IonicWind Software

Aurora Compiler => General Discussion => Topic started by: J B Wood (Zumwalt) on August 14, 2006, 06:04:28 PM

Title: Request :)
Post by: J B Wood (Zumwalt) on August 14, 2006, 06:04:28 PM
Include the LookAt method on 3DObject :)
Title: Re: Request :)
Post by: kryton9 on August 14, 2006, 06:15:06 PM
That would be an awesome addition!!
Title: Re: Request :)
Post by: Kale on August 15, 2006, 01:07:10 AM
Good idea, but what axis would be the front of the model? The 'Z' axis?
Title: Re: Request :)
Post by: kryton9 on August 15, 2006, 01:21:13 AM
you would look at a position, like say an object position: x,y,z

so if you had 2 meshes: m1 and m2ÂÃ,  ÂÃ,  ÂÃ, a position vector for m2:ÂÃ,  vm2

vm2= m2.getPosition(1);
m1.LookAt(vm2.x,vm2.y,vm2.z);
Title: Re: Request :)
Post by: Ionic Wind Support Team on August 15, 2006, 01:44:14 AM
Hard to do and have to think about it.  Kale's question is valid.  Models don't have a lookat vector like a camera does.  There is no 'front' of the model.  Although you can use the Orient method to orient a model towards any point if you understand the vector math ;)  You would have to decide what the default is when loading a mesh.  In other words what axis should we impose, -z or +z?

A camera has a frustum that views the scene and that direction is always away from the camera viewport so a LookAt vector is a simple matter to calculate.

Title: Re: Request :)
Post by: Kale on August 15, 2006, 02:22:12 AM
IÂÃ,  guess it depends wether the built-in 3D engine uses a right or left handed coordinate system? For example, if it uses a right handed system then the Z axis is positive (+Z) looking toward you from the screen, so i guess you develop models looking at you, so i guess you could call that the 'front'? ;)

A left handed coord system would have to use (using this theory) -Z

This is all local to the model of course. I guess it will be saved within the mesh object somewhere as an additional vector.
Title: Re: Request :)
Post by: J B Wood (Zumwalt) on August 15, 2006, 07:05:57 AM
Had to toil on this some, here is the solution.
The mesh has a native center, then it would require a child object to be used to determine the front.

X = represents mesh
o = represents dummy anchor object

XXX
XXXo
XXX

Now we wouldnt' even have to create the dummy mesh in the modeler, we can do it dynamically in the engine and give it an offset. This goes back to the trans.

You are right, we have to give the mesh a front, so the dummy is the front, or we give it a location to the front.

Lets say we have 1 x 1 x 1 cube, which sets at 0,0,0 as its center, so we have an offset from center of 0,0,0 by 0.5 in all directions, we all get that.
Now in the method we not only pass the 3dObject in as a parameter, we pass a vector3 in, which is telling the method what is the front, so the method would be:

Target as 3DOBJECT
Front as VECTOR3
3DOBJECT::POINTAT(TARGET,FRONT)

Declare pointat(3DOBJECT obj1, VECTOR3 front);

Make sense?
Title: Re: Request :)
Post by: Kale on August 15, 2006, 07:49:58 AM
Quote from: zumwalt on August 15, 2006, 07:05:57 AM
Make sense?
Nope, because if you use a directional vector relative to the mesh you don't need any hidden dummy objects. Remember a vector can be a method to decribe a direction which isn't necessarily pointing to anything.

When loading a mesh, initialise the 'lookat' vector to (0, 0, 1.0). Then when you perform a rotation on the mesh, transform its 'lookat' vector to match the rotation (and vice versa). You are then free to test the 'lookat' vector to find what it's looking at or set it to make the mesh look at another point (and/or direction).

Get what i mean?
Title: Re: Request :)
Post by: J B Wood (Zumwalt) on August 15, 2006, 09:42:59 AM
Hrm, well ultimately, I need to rotate left and right on the X and Z or the Y for up and down.
Or spindel, where I spin centrel to the Y when I rotate the object, finally I need one that is like a limb on the body, can point in any direction.

See, if I automated the turret and barrel, first I have to spin on the Y for the turret, then I have to angle the barrel to point at what I just turned to.
... More though going into this to figure out a single method to perform the function.