3D Rad - Free 3D game maker - Forum

This forum is now archived!

This forum is locked, and is a read-only version. A new community-ran forum can be found at classdev.net

News:

The 3DRad community can be found at classdev.net.

Pages: [1]

Author Topic: Script - iObjectAccelerationApply Direction (Help)  (Read 385 times)

« on: December 07, 2013, 01:03:43 PM »
Hello,

I'm wondering how i would get the vector3 for the iObjectAccelerationApply to accelerate an object towards another object.
So, if I got the location and orientation of the target object, how would i use them to calculate the Vector3 parameter in the iObjectAccelerationApply function to accelerate it towards it.
Thanks

-PlayDasher-
New 3DFoundry:3DFoundry.tk
« Reply #1 on: December 07, 2013, 02:10:50 PM »
First you could get the base vector simply by subtracting the target location with the object location and then use iVectorLengthSet() to set the length.
Then I think you would need to rotate this vector with the inverse rotation of the object, but I don't know how to do this in 3D Rad.
Rocket Rumble, a 3D Rad puzzle game:
http://www.3drad.com/forum/index.php?topic=9896.0
« Reply #2 on: December 07, 2013, 02:25:29 PM »
First you could get the base vector simply by subtracting the target location with the object location and then use iVectorLengthSet() to set the length.
Then I think you would need to rotate this vector with the inverse rotation of the object, but I don't know how to do this in 3D Rad.
Ok thanks Robert. Does anyone know how to do it?
New 3DFoundry:3DFoundry.tk
« Reply #3 on: December 11, 2013, 04:44:54 PM »
First you could get the base vector simply by subtracting the target location with the object location and then use iVectorLengthSet() to set the length.
Then I think you would need to rotate this vector with the inverse rotation of the object, but I don't know how to do this in 3D Rad.
How would I subtract the 2 Vectors?
Also what did you mean rotate the vector WITH the inverse rotation of the object?
Thanks
« Last Edit: December 11, 2013, 04:50:55 PM by PlayDasher »
New 3DFoundry:3DFoundry.tk
« Reply #4 on: December 12, 2013, 04:44:25 AM »
you could use iQuaternionLookAt() and then use iVectorRotate().

it's been so long since I even looked at rad functions but that should do it. iQuaternionlookAt creates an orientation facing a target vector location from an origin. and you use that orientation to rotate the acceleration vector with iVectorRotate().
using 3Drad 7.22

system specs:
Windows 7 Home Premium 64-bit
Intel(R) Core(TM) i5-3470 CPU @ 3.20GHz (4 CPUs), ~3.2Ghz
8 gig ram
Geforce GTX 650 1024 MB GDDR5
DirectX 11
« Reply #5 on: December 12, 2013, 10:08:12 AM »
you could use iQuaternionLookAt() and then use iVectorRotate().

it's been so long since I even looked at rad functions but that should do it. iQuaternionlookAt creates an orientation facing a target vector location from an origin. and you use that orientation to rotate the acceleration vector with iVectorRotate().

Thanks Genetransfer.

However, I don't understand one of the parameters of iQuaternionlookAt:
Quote
iQuaternionLookAt(Quaternion,Vector3,Vector3)
   Quaternion = resulting quaternion. Return data.
                     It is the rotation required to orientate the Z+ vector
                     D3DXVECTOR3(0.0f,0.0f,1.0f) to the specified direction.
   Vector3 = direction
   Vector3 = up direction. For example Vector3(0,1,0)
   NOTE: this function will not work properly if 'direction' and 'up'
   vectors are parallel.
What is the Vector3 = direction?Would it be the vector after I subtract the 2 location vectors and set it using iVectorLengthSet()?

I'm not very familiar with quaternions and vectors so...

Thanks

--PlayDasher--
« Last Edit: December 12, 2013, 10:09:44 AM by PlayDasher »
New 3DFoundry:3DFoundry.tk
« Reply #6 on: December 12, 2013, 10:52:18 AM »
How would I subtract the 2 Vectors?

VecA - VecB;  ;D

Also what did you mean rotate the vector WITH the inverse rotation of the object?

I mean that after subtracting the two vectors you would get the world relative vector for the acceleration, while iObjectAccelerationApply() is object relative. So, to compensate this, you would need to rotate the subtraction of the two vectors by the reversed object orientation.

...I don't understand one of the parameters of iQuaternionlookAt...

What is the Vector3 = direction?

The 'direction' parameter is the vector that you want get the orientation of.
Rocket Rumble, a 3D Rad puzzle game:
http://www.3drad.com/forum/index.php?topic=9896.0
« Reply #7 on: December 12, 2013, 01:02:10 PM »
How would I subtract the 2 Vectors?

VecA - VecB;  ;D

Also what did you mean rotate the vector WITH the inverse rotation of the object?

I mean that after subtracting the two vectors you would get the world relative vector for the acceleration, while iObjectAccelerationApply() is object relative. So, to compensate this, you would need to rotate the subtraction of the two vectors by the reversed object orientation.

...I don't understand one of the parameters of iQuaternionlookAt...

What is the Vector3 = direction?

The 'direction' parameter is the vector that you want get the orientation of.

Sorry i'm being really noob here and I still do not understand.

The direction parameter.
So here are my vectors:
originLoc = Vector3(0,0,0)
acceltargetLoc = Vector3(0,0,-20)
diferencevect = originLoc-acceltargetLoc

For me to use the iObjectAccelerationApply to move the object from the originLoc to the acceltargetLoc, which Vector would i use for the direction?
New 3DFoundry:3DFoundry.tk
« Reply #8 on: December 12, 2013, 02:23:19 PM »
If you have a targetLoc and a objectLoc, assuming the objects rotation doesn't matter, this would be the way:

Vector3 forceVec;
iVectorLengthSet(forceVec,targetLoc-objectLoc,1.0); //Last value in the acceleration in m/s^2
iObjectAccelerationApply(OBJ_X,forceVec);

That's it.
Rocket Rumble, a 3D Rad puzzle game:
http://www.3drad.com/forum/index.php?topic=9896.0
« Reply #9 on: December 12, 2013, 07:01:31 PM »
Thanks Genetransfer.

However, I don't understand one of the parameters of iQuaternionlookAt:
Quote
iQuaternionLookAt(Quaternion,Vector3,Vector3)
   Quaternion = resulting quaternion. Return data.
                     It is the rotation required to orientate the Z+ vector
                     D3DXVECTOR3(0.0f,0.0f,1.0f) to the specified direction.
   Vector3 = direction
   Vector3 = up direction. For example Vector3(0,1,0)
   NOTE: this function will not work properly if 'direction' and 'up'
   vectors are parallel.
What is the Vector3 = direction?Would it be the vector after I subtract the 2 location vectors and set it using iVectorLengthSet()?

I'm not very familiar with quaternions and vectors so...

Thanks

--PlayDasher--

the direction is (origin-target), yeah without a code showing it in action it's not obvious what should go there.

so...(below is untested but shows the use of iQuaternionLookAt() in this context)

Vector3 accelerationDir = Vector3(0.0f,0.0f,1.0f);//set to 1.0 on z every loop (also can't remember if you can set Vector3's like this)
float acceleration = 1.0f;//or whatever force you want to apply.
iVectorLengthSet(accelerationDir ,accelerationDir ,acceleration);

Quaternion qLookAt;
Vector3 vUp = Vector3(0.0f,1.0f,0.0f);
Vector3 Origin = The location of object that will accelerate toward target
Vector3 Target = the location of the target

iQuaternionLookAt(qLookAt,(Origin-Target ),vUp );//if accelerates away from target swap it (Target-Origin) can't remember which is first)
iVectorRotate(accelerationDir,accelerationDir ,qLookAt);//orientate the acceleration vector to look at the target

iObjectAccelerationApply(OBJ_X,accelerationDir);//apply acceleration
using 3Drad 7.22

system specs:
Windows 7 Home Premium 64-bit
Intel(R) Core(TM) i5-3470 CPU @ 3.20GHz (4 CPUs), ~3.2Ghz
8 gig ram
Geforce GTX 650 1024 MB GDDR5
DirectX 11
Pages: [1]