i couldn't notice any proportional speed when using the gamepad.
but it may just be that the carboat is moving quite slow and hard to notice...
but it may just be that the carboat is moving quite slow and hard to notice...
The 3DRad community can be found at classdev.net.
I like the mouse zoom, nice job.Thanks
/// objects script interfaces with
int objTarget= OBJ_308;
int objTurret= OBJ_0;
int objGun= OBJ_22;
int objCar= OBJ_44;
int objCam= OBJ_66;
int objSprite= OBJ_352; // i3DLocationToScreen(Vector3,Vector3,Int Object)
// objects to test with iObjectScan in bool scanFromObject(int obj)
int objTerrain= OBJ_88;
int objBall= OBJ_132;
int objRandomCar= OBJ_264;
int objRandomCar2= OBJ_286;
int[] testObj= {objTerrain, objBall, objRandomCar, objRandomCar2};
int objPrnDist= OBJ_176;
void boom(Vector3 loc) {objPos(OBJ_220, loc);iObjectStart(OBJ_220);} // position and trigger explosion sound
void valPrnDistance(float v){OUT_176= v;};
void spriteToTarget() {
float s=0.5;
Vector3 vScreenCoords;
i3DLocationToScreen(vScreenCoords, contactPoint, objCam);
iObjectLocationSet(objSprite, vScreenCoords);
float dx= iFloatAbs(vScreenCoords.x);
float dy= iFloatAbs(vScreenCoords.y);
s= iFloatSqrt(dx*dx+dy*dy);
s= (s<1)?(1.0-s)/2.0+0.5:0.5;
s= iFloatSqrt(s);
iObjectScaleSet(objSprite, vecLen(Vector3(1,1,1), 1.7*s));
OUT_352= s;
OUT_353= s;
OUT_354= 1.0-s;
OUT_355= 1.0-s;
}
///
Vector3 vecLen(Vector3 v, float l) {iVectorLengthSet(v,v,l);return v;}
Vector3 vNorm(Vector3 v) {iVectorLengthSet(v,v,1);return v;}
Vector3 vecRot(Quaternion q, Vector3 d) {Vector3 r;iVectorRotate(r,d,q);return r;}
Vector3 objPos(int obj) {Vector3 l; iObjectLocation(obj, l); return l;}
Vector3 objPos(int obj, Vector3 v) {iObjectLocationSet(obj, v); return v;}
Quaternion objRot(int obj) {Quaternion q; iObjectOrientation(obj, q); return q;}
Quaternion qMul(Quaternion q1, Quaternion q2) {Quaternion qt;iQuaternionMultiply(qt,q1,q2);return qt;} // q1+q2
Quaternion qDelta(Quaternion q1, Quaternion q2) {return qMul(q1, qInv(q2));} // q1-q2
Quaternion qInv(Quaternion q) {return Quaternion(q.x,q.y,q.z,-q.w);} // -q
float angleWrap(float a) {while (a<-180) a+=360; while (a> 180) a-=360; return a;}
float sign(float n){return n<0?-1:n>0?1:0;}
Quaternion VectorOrientation(Vector3 v){
Vector3 v1,v2;
iVectorLengthSet(v1,v,1);
iVectorLengthSet(v2,v,2);
return QuatGetLookAt(v2-v1);
}
Quaternion QuatGetLookAt(Vector3 direction){
Vector3 up = Vector3(1,0,0);
Quaternion orientation;
iQuaternionLookAt(orientation,direction,up);
return orientation;
}
float asin(float value) { // aka, R_asin
iDLLArraySet(0,value);
iDLLCall(MathDLLHandle,"asin",0);
float f = iDLLArrayGet(0);
return f;
}
float acos(float value) { // aka, R_acos
iDLLArraySet(0,value);
iDLLCall(MathDLLHandle,"acos",0);
float f = iDLLArrayGet(0);
return f;
}
float atan2(float value1, float value2) { // aka, R_atan2
iDLLArraySet(0,value1); iDLLArraySet(1,value2);
iDLLCall(MathDLLHandle,"atan2",0);
return iDLLArrayGet(0);
}
///
/// GForceImposters
int[] gfiObj= {OBJ_242, OBJ_154, OBJ_198}; // particles & G-Force
int gfiObjs;
Quaternion qGFI;
void GForceImposters_init() {
gfiObjs= gfiObj.length();
for(int j=0;j<gfiObjs;j++) {
iObjectImpostersCreate(gfiObj[j],1);
iObjectImposterHide(gfiObj[j],0);
}
iObjectOrientation(gfiObj[1],qGFI);
}
void GForceImposters_deInit() {for(int j=0;j<gfiObjs;j++) iObjectImpostersDestroy(gfiObj[j]);}
void GForceImposters() {
for(int j=0;j<gfiObjs;j++) { // position & show imposters
iObjectImposterSet(gfiObj[j],0,qGFI,contactPoint);
iObjectImposterShow(gfiObj[j],0);
}
boom(contactPoint);
}
bool key, _key, rKey;
bool triggered() {_key= (IN_110 > 0); rKey= _key and not key; key= _key; return rKey;}
/// scanFromObject
///
float scanRange= 2048;
Vector3 contactPoint, contactNormal;
float contactDist;
bool scanFromObject(int obj) {
bool contacts;
Vector3 scanOrigin= objPos(obj);
Quaternion q= objRot(obj);
Vector3 vScan= vecLen(vecRot(q, Vector3(0,0,1)), scanRange);
contacts= false;
contactDist= -1;
contactPoint= scanOrigin+vScan;
Vector3 rContactPoint, rContactNormal;
float dist;
int arrayLen= testObj.length(), i, nContacts;
for(i=0;i<arrayLen;i++)
if (iObjectScan(testObj[i], scanOrigin, vScan, 0, rContactPoint, rContactNormal)) {
bool isCloser= contactDist>(dist= iVectorLength(scanOrigin-rContactPoint));
if ((!contacts) or isCloser ) {
contactDist= dist;
contacts= true;
contactPoint= rContactPoint;
contactNormal= rContactNormal;
nContacts+= 1;
}
}
return contacts;
}
///
/// setTurretRotation
// Actuate hinge motors to rotate the turret and pitch the barrel
void setTurretRotation() {
Vector3 v;
float AngleX, AngleY;
v= vecRot(qDelta(qTarget, objRot(objTurret)), Vector3(0,0,1));
AngleY= 15*angleWrap(57.29578231*atan2(v.x, v.z));
v= vecRot(qDelta(qTarget, objRot(objGun)), Vector3(0,0,1));
AngleX= 15*angleWrap(57.29578231*atan2(v.y, v.z));
if (iFloatAbs(AngleX)>60) AngleX= sign(AngleX)*60;
if (iFloatAbs(AngleY)>60) AngleY= sign(AngleY)*60;
AngleX= iFloatAbs(AngleY)<120?AngleX*((120.0-iFloatAbs(AngleY))/120.0):0;
OUT_310= AngleY;
OUT_332= AngleX;
}
///
/// Turret Control
Quaternion qTarget;
int MathDLLHandle=0; // atan2 needs RadMath2.dll
void Main() { /// Main
if(iInitializing()) {
MathDLLHandle = iDLLLoad(".\\3DRad_res\\objects\\Script\\RadMath2.dll");
if (MathDLLHandle==0)
MathDLLHandle = iDLLLoad(".\\3DRad_res\\objects\\Script\\RadMath.dll");
qTarget= objRot(objCar);
GForceImposters_init();
} else if (iDeinitializing()) {
if (MathDLLHandle != 0) iDLLUnload(MathDLLHandle);
GForceImposters_deInit();
} else if (MathDLLHandle != 0) {
// Determine position and distance of what's at screen center
Vector3 targetContactPoint;
float targetDistance;
if (scanFromObject(objCam)) {
valPrnDistance(targetDistance);
iObjectShow(objPrnDist);
} else
iObjectHide(objPrnDist);
targetContactPoint= contactPoint;
targetDistance= contactDist;
// qTarget= (targetDistance>-1) ? VectorOrientation(vNorm(targetContactPoint-objPos(objTurret))) : objRot(objCam);
qTarget= VectorOrientation(vNorm(targetContactPoint-objPos(objTurret)));
setTurretRotation();
// Determine position and distance of what the cannon is aimed at
scanFromObject(objGun); // get impact point
spriteToTarget();
// if firing a shot, not at nothing, create an explosion where the cannon is aimed
if (triggered()) // and targetDistance>-1)
GForceImposters(); // create explosion at target point
}
}
Side note: At a range of 4096, explosions weren't visible in some parts of the sky. The sky is indeed a box. And we're on a turtle. A really big turtle. Ok not that big.