April 26, 2024, 03:13:17 AM

News:

IonicWind Snippit Manager 2.xx Released!  Install it on a memory stick and take it with you!  With or without IWBasic!


Vectors and Matrices

Started by kryton9, August 20, 2006, 04:21:19 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

kryton9

August 20, 2006, 04:21:19 PM Last Edit: August 20, 2006, 04:23:25 PM by kryton9
Working in 3D, Vectors and Matrices are a must.

I thought I would start this topic and we can all work out and share info here.

There are tons of websites with all the info you could want about 3d math, the problem is they all show the same complicated formulas and give no real examples.

I have been hitting a solid wall in everything I have been trying to do lately, because of the lack of practical info.

I decided today to spend the next few days working on this stuff and sharing what I learn. I hope anyone who knows more about this stuff can help.

I am going to do simple vector math in console apps, once it is confirmed that what I am doing is correct, I will work on doing the same in 3d. This will be a great help for anyone in the future and for me as I need to refer to notes all the time as my memory is really bad.

If we get through that then onto matrices.

I will post the first code soon, got it started. This is the only site that cut it to the core and gives examples, I will start with these: http://forum.thegamecreators.com/?m=forum_view&t=64491&b=1

kryton9

/*
by kryton9 8-20-2006

Using info from this site: http://forum.thegamecreators.com/?m=forum_view&t=64491&b=1

Vectors - Creating a directional Vector from 2 positional vectors.
Consider the following positional vectors:

a = (2,3,4)
b = (10,-3,6)

You first have to think of these as directional vectors from (0,0,0).
To create a directional vector you have to get to the origin and then
to your destination point. This means you have to take the minus of
one vector and add it to your destination point.

so a to b can be thought of as -a+ b. Then all you do is work it out.

so -a + b = (-2+10,-3-3,-4+6) = (8,-6,2)

so your directional vector a to b is (8,-6,2)
*/
global sub main
{

vector3 vObject,VTarget,VAnswer;
   
vObject.x = 2;
vObject.y = 3;
vObject.z = 4;
   
VTarget.x = 10;
VTarget.y = -3;
VTarget.z = 6;
   
print();
print("vObject = ("+NumToStr(vObject.x)+", "+NumToStr(vObject.y)+", "+NumToStr(vObject.z)+")");
print("vTarget = ("+NumToStr(VTarget.x)+", "+NumToStr(VTarget.y)+", "+NumToStr(VTarget.z)+")");
print();
print("-vObject + vTarget = (-2+10,-3-3,-4+6) = (8,-6,2)");
print();
print("To match the formula, we do the following");
print("in assigning the values to the vectors:");
print();
print("vObject.x = -2;");
print("vObject.y = -3;");
print("vObject.z = -4;");
vObject.x = -2;
vObject.y = -3;
vObject.z = -4;
print(); 
print("VTarget.x = 10;");
print("VTarget.y = -3;");
print("VTarget.z = 6;");
print();
VAnswer = Vec3Add(VObject,VTarget);
print("vAnswer = Vec3Add(vObject,vTarget);");
print();
print("vAnswer = ("+NumToStr(VAnswer.x)+", "+NumToStr(VAnswer.y)+", "+NumToStr(VAnswer.z)+")");
print();
print();
print("Reversing the vectors in Vec3Add, has no impact on the result.");
VAnswer = Vec3Add(VTarget,VObject);
print("vAnswer = Vec3Add(VTarget,VObject);");
print();
print("vAnswer = ("+NumToStr(VAnswer.x)+", "+NumToStr(VAnswer.y)+", "+NumToStr(VAnswer.z)+")");
print();
print();
print("If you look at the above, you realize we did a subtraction.");
print("We placed minus in front of all the elements of the vObject.");
print("We need to remove that minus now since we will use the subtract function");
print();
print("vObject.x = 2;");
print("vObject.y = 3;");
print("vObject.z = 4;");
vObject.x = 2;
vObject.y = 3;
vObject.z = 4;
print();
VAnswer = Vec3Sub(vTarget,vObject);
print("vAnswer = Vec3Sub(vTarget,vObject);");
print();
print("vAnswer = ("+NumToStr(VAnswer.x)+", "+NumToStr(VAnswer.y)+", "+NumToStr(VAnswer.z)+")");
print();
print();
print("Reversing the vectors in Vec3Sub, does impact the result.");
VAnswer = Vec3Sub(VObject,VTarget);
print("vAnswer = Vec3Sub(VObject,VTarget);");
print();
print("vAnswer = ("+NumToStr(VAnswer.x)+", "+NumToStr(VAnswer.y)+", "+NumToStr(VAnswer.z)+")  ******* This is wrong");
print();
print();
print("Make sure to scroll to the top of the page.");
while GetKey() == "";
}



kryton9

August 21, 2006, 12:27:19 AM #2 Last Edit: August 21, 2006, 12:10:34 PM by kryton9
Made a 3D version to use the info from the first post.

I get the answer vector, but can't seem to apply it properly. Paul, or some other 3d programming guru is going to have to show how to make this work.
Look for this in the code to see where to do the magic. // <<<<<<<<<<<< How do we get it to work correctly :)

Commands:
Escape Key exit program
WSAD control camera forward/backwardÂÃ,  Left/Right
RF control camera up/down
SpaceBar reset camera
M move vector to object position
C calc answer and try applying the direction vector
B move vector back to start location
N set vector to start direction

Screenshot of what you might see.

kryton9

August 21, 2006, 12:29:31 AM #3 Last Edit: August 21, 2006, 12:31:26 AM by kryton9
Paul feel free to take this program and maybe make a tutorial for all those 3d math functions you have in Aurora and we can then visually see its impact and maybe be able to use them in practical applications. Thanks.

If you need any more models to help illustrate, let me know will be glad to make them.

J B Wood (Zumwalt)

Kryikey Kryton!
I was impressed with the hover mech (trust me very impressed), and now this beautiful thing you have started!
Man your making me feel like I am falling behind!

sapero

I'm wondering why all windowed dx examples are closed only by keyboard ???
If we have a window, it should allow close from systemmenu:

class C3DScreen2:C3DScreen{declare virtual OnClose() {Destroy();}}

global sub main()
{
C3DScreen2 screen;
CDirectInput keyboard;
screen.CreateWindowed(0,0,1024,768,AWS_VISIBLE|AWS_OVERLAPPEDWINDOW|AWS_CENTERED,0,"example",NULL,false);

do (
// render here
}until (keyboard.KeyDown(DIK_ESCAPE) || !screen.IsValid());

J B Wood (Zumwalt)

Good question, generally speaking all 3d games are written for full screen and the window has no menu.

kryton9

Thanks Zumwalt, well you got me inspired with your great demo and now I want to get over this hump or wall that keeps cropping up all the time in working with 3D.

Sapero, I will add the system menu in the next version. You are right, if it is a window it should really have that.

Ionic Wind Support Team

August 21, 2006, 10:47:18 AM #8 Last Edit: August 21, 2006, 11:35:16 AM by Paul Turley
Quote from: sapero on August 21, 2006, 08:46:23 AM
I'm wondering why all windowed dx examples are closed only by keyboard ???
If we have a window, it should allow close from systemmenu:

Some of them are closed by the button.  Oh wait, you don't have those examples yet ;)

Just create a derived class as you did an you can handle any Windows message in the 3D screen.
Ionic Wind Support Team

kryton9

August 21, 2006, 11:25:11 AM #9 Last Edit: August 21, 2006, 11:26:56 AM by kryton9
Updated the code as Sapero suggested. I also cleaned up the code a bit, but didn't solve the main problem. The new version can be downloaded at the second post, reply #2.

kryton9

I tried all of these today and still no luck :(

Code Snippet:
if (input.KeyDown(DIK_C))
{
ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  //vAnswer = Vec3Sub(vTarget,vObject);
ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  //vSet = Vec3Normalize(vAnswer);
//svAnswer="Answer Vector: "+NumToStr(vAnswer.x,4)+" "+NumToStr(vAnswer.y,4)+" "+NumToStr(vAnswer.z,4);
//sVectorThruTarget="The Vector is not going through the Target :(";
//vector.Orient(vAnswer.x,vAnswer.y,vAnswer.z,vUpVector.x,vUpVector.y,vUpVector.z);// <<<<<<<<<<<< How do we get it to work correctly :)
//vector.Orient(vSet.x,vSet.y,vSet.z,vUpVector.x,vUpVector.y,vUpVector.z);// <<<<<<<<<<<< How do we get it to work correctly :)
//vector.rotate(vAnswer.x,vAnswer.y,vAnswer.z);
//vector.rotate(vSet.x,vSet.y,-vSet.z);
//sVectorThruTarget = NumToStr(ACOS(Vec3Dot(Vec3Normalize(vObject),Vec3Normalize(vTarget))),4);
//vector.rotate(vSet.x,ACOS(Vec3Dot(Vec3Normalize(vObject),Vec3Normalize(vTarget))),vSet.z);
//vector.Orient(vSet.x,ACOS(Vec3Dot(Vec3Normalize(vObject),Vec3Normalize(vTarget))),vSet.z,vUpVector.x,vUpVector.y,vUpVector.z);
}

Ionic Wind Support Team

Keep working on it.  I can't look at it for you for at least a few days.
Ionic Wind Support Team

kryton9

Added arrow keys and numpad 4 and 6 to control the vector object and some more stats, at least something to maybe help figure this out.
Escape Key exit program
WSAD control camera forward/backward  Left/Right
RF control camera up/down
SpaceBar reset camera
M move vector to object position
C calc answer and try applying the direction vector
B move vector back to start location
N set vector to start direction

/* 3d vector example 01
8-20-2006
by kryton9 */

class MyC3DScreen:C3DScreen{declare virtual OnClose() {Destroy();}}
declare import,timeGetTime(),int;

global sub main()
{
vector3 vObject,vObjectDir,vTarget,vAnswer,vOriginal,vUpVector,vNow,vCamera,vSet,vAnswerNormalized;
ÂÃ,  ÂÃ, 
vAnswer.x = 0;
vAnswer.y = 0;
vAnswer.z = 0;

vObject.x = 2;
vObject.y = 3;
vObject.z = 4;
ÂÃ,  ÂÃ, 
vTarget.x = 10;
vTarget.y = -3;
vTarget.z = 6;

MyC3DScreen screen;
C3DCamera camera;
C3DObject scene;
C3DLight light;
CDirectInput input;

C3DMesh axis,object,target,vector;

int TextColor = RGBA(255,100,0,200);
float fRate=1;


float fadjust,fTarget,fCamLR,fCamUD,fCamFB,vectorPitch,vectorYaw;
fCamLR=17.0f;fCamUD=5.0f;fCamFB=-35.0f;
fTarget = 1.0f / /*FPS*/60.0f * 1000.0f;
fAdjust = 1.0f;vectorPitch = 0.0f;vectorYaw = 0.0f;vectorRoll=0.0f;

string sWinTitle = "Vectors Example 01";string svAnswer="";string sVectorThruTarget="";string svAnswerNormalized ="";
screen.CreateWindowed(0,0,1024,768,AWS_CAPTION|AWS_VISIBLE|AWS_OVERLAPPEDWINDOW|AWS_SIZE|AWS_CENTERED,0,sWinTitle,NULL,false);

input.Init(screen);
camera.Create(screen);
camera.Position(5,5,-50);
camera.SetBackPlane(10000);


screen.Clear(RGBA(0,0,0,255));
screen.BeginScene(camera);
screen.RenderText(0,10,"Loading objects...",TextColor);
screen.RenderScene();

ÂÃ,  ÂÃ,  light.Create(screen,LIGHT_POINT,1);
light.SetAttenuation(0,1/200.0,0);
light.SetSpecular(.5,.5,.5,1);
light.SetAmbient (.7,.7,.7,1);
light.Position(0,150,-300);

//axis,object,target,vector
axis.LoadSkinnedX(screen,GetStartPath()ÂÃ,  ÂÃ, +ÂÃ,  "k9 3d axis.X");
object.LoadSkinnedX(screen,GetStartPath() +"k9 3d object.X");
target.LoadSkinnedX(screen,GetStartPath() +"k9 3d target.X");
vector.LoadSkinnedX(screen,GetStartPath() +"k9 3d vector.X");

scene.CreateScene(screen);vUpVector = camera.GetUpVector();
scene.AddChild(light);
scene.AddChild(axis); axis.position(0,0,0);
scene.AddChild(object); object.Position(2,3,4);
scene.AddChild(target); target.Position(10,-3,5);
scene.AddChild(vector); vector.Position(-5,-10,5);vOriginal = vector.getDirection();


int fps = 0;
int startTime;
do
{
// Camera Controls
if input.KeyDown(DIK_W){fCamFB += 0.5*fRate;} // move camera forwards
if input.KeyDown(DIK_S){fCamFB -= 0.5*fRate;} // move camera backwards
if input.KeyDown(DIK_D){fCamLR += 0.5*fRate;} // move camera right
if input.KeyDown(DIK_A){fCamLR -= 0.5*fRate;} // move camera left
if input.KeyDown(DIK_R){fCamUD += 0.5*fRate;} // move camera up
if input.KeyDown(DIK_F){fCamUD -= 0.5*fRate;} //move camera down

if input.KeyDown(DIK_SPACE){fCamLR=17.0f;fCamUD=5.0f;fCamFB=-35.0f;} //reset camera

if input.KeyDown(DIK_M)//move vector to object location
{
vector.Position(2,3,4);vObjectDir = object.GetDirection();
fCamLR=23.0f;fCamUD=7.5f;fCamFB=-58.0f;// adjust camera to see better
}
if (input.KeyDown(DIK_B)){ vector.position(-5,-10,5);} //move vector to start location
if (input.KeyDown(DIK_N)){ vector.orient(vOriginal.x,vOriginal.y,vOriginal.z,vUpVector.x,vUpVector.y,vUpVector.z);} //restore back original vector direction

if (input.KeyDown(DIK_C))
{
vAnswer = Vec3Sub(vTarget,vObject);
vAnswerNormalized = Vec3Normalize(vAnswer);
svAnswerNormalized = "Answer Vector Normalized: "+NumToStr(vAnswerNormalized.x,4)+" "+NumToStr(vAnswerNormalized.y,4)+" "+NumToStr(vAnswerNormalized.z,4);
//vSet = Vec3Normalize(vAnswer);
svAnswer="Answer Vector: "+NumToStr(vAnswer.x,4)+" "+NumToStr(vAnswer.y,4)+" "+NumToStr(vAnswer.z,4);
sVectorThruTarget="The Vector is not going through the Target :(";
vectorPitch = 0.0f;vectorYaw =0.0f;vectorRoll = 0.0f;
//vector.Orient(vAnswer.x,vAnswer.y,vAnswer.z,vUpVector.x,vUpVector.y,vUpVector.z);// <<<<<<<<<<<< How do we get it to work correctly :)
//vector.Orient(vSet.x,vSet.y,vSet.z,vUpVector.x,vUpVector.y,vUpVector.z);// <<<<<<<<<<<< How do we get it to work correctly :)
vector.rotate(vAnswer.x,vAnswer.y,vAnswer.z);
//vector.rotate(vAnswerNormalized.x+(vNow.x+vAnswerNormalized.x),vAnswerNormalized.y+(vNow.y+vAnswerNormalized.y),vAnswerNormalized.z+(vNow.z+vAnswerNormalized.z));
//sVectorThruTarget = NumToStr(ACOS(Vec3Dot(Vec3Normalize(vObject),Vec3Normalize(vTarget))),4);
//vector.rotate(vSet.x,ACOS(Vec3Dot(Vec3Normalize(vObject),Vec3Normalize(vTarget))),vSet.z);
//vector.Orient(vSet.x,ACOS(Vec3Dot(Vec3Normalize(vObject),Vec3Normalize(vTarget))),vSet.z,vUpVector.x,vUpVector.y,vUpVector.z);
}
// Vector Object Controls
IF input.KeyDown(DIK_NUMPAD4)
{ vectorRoll += 0.01*fRate;vector.Rotate(vAnswer.x+vectorPitch,vAnswer.y+vectorYaw,vAnswer.z+vectorRoll);}
IF input.KeyDown(DIK_NUMPAD6)
{ vectorRoll -= 0.01*fRate;vector.Rotate(vAnswer.x+vectorPitch,vAnswer.y+vectorYaw,vAnswer.z+vectorRoll);}
IF input.KeyDown(DIK_RIGHT)
{ vectorYaw -= 0.01*fRate;vector.Rotate(vAnswer.x+vectorPitch,vAnswer.y+vectorYaw,vAnswer.z+vectorRoll);}
IF input.KeyDown(DIK_LEFT)
{ vectorYaw += 0.01*fRate;vector.Rotate(vAnswer.x+vectorPitch,vAnswer.y+vectorYaw,vAnswer.z+vectorRoll);}
IF (input.KeyDown(DIK_UP))
{ÂÃ,  ÂÃ, vectorPitch += 0.01*fRate;vector.Rotate(vAnswer.x+vectorPitch,vAnswer.y+vectorYaw,vAnswer.z+vectorRoll);}
IF (input.KeyDown(DIK_DOWN))
{ vectorPitch -= 0.01*fRate;vector.Rotate(vAnswer.x+vectorPitch,vAnswer.y+vectorYaw,vAnswer.z+vectorRoll);}

camera.Position (fCamLR,fCamUD,fCamFB);
vCamera= camera.GetPosition();vNow = vector.getDirection();

startTime = timeGetTime();
screen.Clear(RGBA(0,0,0,255));
screen.BeginScene(camera);

scene.Draw();
y=0;s=14;
screen.RenderText(5,y,"FPS: "+NumToStr(fps),TextColor);y+=s;
screen.RenderText(5,y,"",TextColor);y+=s;

screen.RenderText(5,y,"CameraX: "+NumToStr(vCamera.x,1),TextColor);y+=s;
screen.RenderText(5,y,"CameraY: "+NumToStr(vCamera.y,1),TextColor);y+=s;
screen.RenderText(5,y,"CameraZ: "+NumToStr(vCamera.z,1),TextColor);y+=s;
screen.RenderText(5,y,"",TextColor);y+=s;

screen.RenderText(5,y,"vectorPitch: "+NumToStr(vectorPitch,4),TextColor);y+=s;
screen.RenderText(5,y,"vectorYaw: "+NumToStr(vectorYaw,4),TextColor);y+=s;
screen.RenderText(5,y,"vectorRoll: "+NumToStr(vectorRoll,4),TextColor);y+=s;
screen.RenderText(5,y,"",TextColor);y+=s;

screen.RenderText(5,y,"Object Direction Vector: "+NumToStr(vObjectDir.x,4)+" "+NumToStr(vObjectDir.y,4)+" "+NumToStr(vObjectDir.z,4),TextColor);y+=s;
screen.RenderText(5,y,"",TextColor);y+=s;

screen.RenderText(5,y,"Vector Original Direction: "+NumToStr(vOriginal.x,4)+" "+NumToStr(vOriginal.y,4)+" "+NumToStr(vOriginal.z,4),TextColor);y+=s;
screen.RenderText(5,y,"",TextColor);y+=s;

screen.RenderText(5,y,svAnswer,TextColor);y+=s;
screen.RenderText(5,y,"",TextColor);y+=s;

screen.RenderText(5,y,svAnswerNormalized,TextColor);y+=s;
screen.RenderText(5,y,"",TextColor);y+=s;

screen.RenderText(5,y,"Vector Now Direction: "+NumToStr(vNow.x,4)+" "+NumToStr(vNow.y,4)+" "+NumToStr(vNow.z,4),TextColor);y+=s;
screen.RenderText(5,y,"",TextColor);y+=s;

screen.RenderText(5,y,sVectorThruTarget,TextColor);y+=s;
screen.RenderText(5,y,"",TextColor);y+=s;
screen.RenderText(5,y,"vNow-vAnswerNormalized: "+NumToStr(vNow.x-vAnswerNormalized.x,4)+" "+NumToStr(vNow.y-vAnswerNormalized.y,4)+" "+NumToStr(vNow.z-vAnswerNormalized.z,4),TextColor);y+=s;
screen.RenderText(5,y,"",TextColor);y+=s;


fps = screen.RenderScene();
fAdjust = (timeGetTime() - startTime) / fTarget;
}
until (input.KeyDown(DIK_ESCAPE) || !screen.IsValid());
scene.Free();screen.CloseScreen();
}


John S

John Siino, Advanced Engineering Services and Software

kryton9

Thanks hopefully will get it working sometime.
If anyone has ideas for using this setup and needs extra models let me know. I can make what you need if it will help us figure this stuff out!!

kryton9

I modified my previous program to try out the new lookat command. Strange things happen, not only in where it points, but also the arrow at times disappears and other times is all distorted.

Commands:
WSADRF move the camera, the camera always looks at 0,0,0
The arrow keys as well as NumPad 4 and 6 let you spin the arrow around
0-8 move the location of the arrow to one of the points in 3d space
F1-F9 select the coordinates to look at
SpaceBar resets the camera

When the arrow dissapears or becomes really distorted. Just hit 0 to move it back to 0,0,0 and then try the different F keys till it becomes normal again. Sometimes hitting the arrow keys
brings it back too.

Still fun to play with and you can use it to do your tests with other 3d commands and use this as  a foundation. As you can see by all the commented lines, I have been trying to figure stuff out like crazy and not getting much luck :)


Ionic Wind Support Team

When your playing with the LookAt method remember that it is just a point in 3D space.  If that point is very close, or inside your mesh, then you'll have strange results.

For example if you have a cube that is 100x100x100 postioned at 0,0,0 and you tell it to look at 0,0,50 then the look at point is in the middle of your mesh, in which case it may flip in the wrong direction.  Draw some lines on paper to help visualize it.

The LookAt method rotates the mesh so that an imaginary vector pointing straight out from the face lines up with the point, it uses the same code for the C2DCamera::LookAt method. 

When you want to look at another mesh, and that mesh is very close, look at a point beyond that mesh as if the vector penetrates the target to reach that point.  In other words scale the point to a larger value.
Ionic Wind Support Team

Kale

To learn about Vectors and Matrices try this book:

3D Math Primer for Graphics and Game Development

Very easy to follow and lots of good examples.

Barney

This is a good place to visit regarding game programming. It's in German, but there's some good info in English for those who don't understand German. Look at the left part of the screen and click on Mathlib link.

http://www.zfx.info/

Barney

kryton9

Thanks for the links guys.

The LookAt is not looking where it should it seems, it works fine for the camera, but for one object to look at another something is not right?
Try the program out to see.

J B Wood (Zumwalt)

Its not that simple.
It doesn't reset.

I am standing in a room looking out a window, I don't move, the mailbox doesn't move, so therefor the lookat just worked.
I move, go downstairs, open the front door, and I look out at the same mailbox.
My initial view hasn't changed, its as if I am still up in the room, looking out the window, at the mailbox, but my orientation to the mailbox is different, my position is different, everything but the mailbox location is different.

Download my tank game for an example of the problem.

Ionic Wind Support Team

Works fine here ;).  I'll write a demo for you this weekend, I've tried to give you clues in the posts I've made but you need more it seems.  The mesh itself has to be designed to face in the correct location when it is initially loaded, otherwise the LookAt command is meaningless.

LookAt with a mesh will have limited use if your using them with characters that are meant to walk or roll like a tank.  Only because the lookat vector will cause the mesh to rotate on all three axis from the center point.  Which for a camera is normal.  But a person walking on a game board would look kind of strange looking at a point on the ground, since it would rotate the mesh on the X axis.
Ionic Wind Support Team

kryton9

September 02, 2006, 12:13:03 PM #22 Last Edit: September 02, 2006, 12:24:56 PM by kryton9
Paul can you use the models and program I made to show where I am going wrong. Thanks Will save you time instead of writing something from scratch.

Just to show how what I am trying to do to make it work. Thanks will help immensly. Paul, I made all my models to face correctly from my modeler. That is if you see, I use no rotations or transforms. I write this because I know you wrote to me about the mesh in creation and facing direction.

The version to use is in reply # 15.

kryton9

Quote from: zumwalt on September 02, 2006, 12:00:21 PM
Its not that simple.
It doesn't reset.

I am standing in a room looking out a window, I don't move, the mailbox doesn't move, so therefor the lookat just worked.
I move, go downstairs, open the front door, and I look out at the same mailbox.
My initial view hasn't changed, its as if I am still up in the room, looking out the window, at the mailbox, but my orientation to the mailbox is different, my position is different, everything but the mailbox location is different.

Download my tank game for an example of the problem.

Even if I don't move the arrow at all and tell it took at a direction it doesn't seem to point in the right direction.

I can understand about what you are saying, but like I said, even the default first lookat from the location o,o,o doesn't seem to work the way I though it would.

J B Wood (Zumwalt)

Paul, I Ignore the Y value on my LookAt call.
As I stated, it does look at the correct target in the DO look on first pass.
This is shown on ÂÃ, my tank.

Now, here is the hierarchy:
Tank body, has tank turret as a child, tank turret has a trans as a child, of that trans, I have a machine gun as a child.
When the gun loads, it loads facing the same direction the barrel faces, it faces the same direction the body faces.
Everything is facing the same direction when it loads.

Now comes the loop with positioning:

tX=midTarget.x;
tY=midTarget.y;
tZ=midTarget.z;

trans.lookat(tX,0.0f,tZ);



midTarget is NEW on every do loop cycle.
Please, download my tank game and look at the red sphere between the tank and the mech.
At all times, the gun should face the red ball.
tX has a new value, tZ has a new value coordinates

Add this to the code to see...


s.RenderText(8,178,"tX: "+NumToStr(tX),RGBA(255,255,0,255));
s.RenderText(8,188,"tY: "+NumToStr(tY),RGBA(255,255,0,255));
s.RenderText(8,198,"tZ: "+NumToStr(tZ),RGBA(255,255,0,255));


So that all said, the lookat is not taking any NEW coordinates once it is called the first time for me.
Anxiously waiting the code to see what on earth I am doing wrong.
Thanks Paul :)