This topic is now archived and is closed to further replies.


steering objects

Recommended Posts

Learn it, the most complicated thing in maths I have done in maths so far is algebra! I don`t even know what sine is! and you are suggesting I learn NORMALS? what are you _on_?

sorry about that, but seriously, laerning normals isn`t really an option.

any other help?

Share this post

Link to post
Share on other sites
Guest Anonymous Poster
im 14 and im writing a 3d internet game with directx
i understand sine cosines tangents trignometry etc. etc. etc.
but i just dont get these "normal" thingys
ive heard that they are useful in hidden-surface-removal, but how?

Share this post

Link to post
Share on other sites
Guest Anonymous Poster
The tutorials tell you what normals are. If I remember correctly, they specify which direction the polygon''s facing so that light can reflect off it accordingly.
Also age is no excuse for anything. You just have to put more effort into it, you don''t have to wait for school to teach you, just figure it out. I would brag about how early I learned how to program but it doesn''t matter.
I made a tank game a really long time ago and this was the code for moving an object in the direction it''s facing. I kept track of it''s angle which would be a good idea if you want to do anything. xPos is the position on the x axis, zPos is the position on the z axis, Angle is the angle of the object in degrees, because im not used to radians. There are 360° in the system I like and 6.28 ° in radians. For some reason sin and cos always use radians so I had to convert them. The *speed at the end is to control how fast it moves, the higher the speed the faster it moves.
zPos -= (1 * cos(Angle/360*6.28))*speed;
xPos -= (1 * sin(Angle/360*6.28))*speed;

I''m not sure if this is what you want, but I hope it helps.

Share this post

Link to post
Share on other sites
ok kiddo, I gotta give you respect for being 13 and programming. Mind you you must learn what normals are. At very least you can impress the girls in high-school with your uncanny mathmatical prowess.

Imagine your triangle or polygon is made of card. If you were to stick the eraser end of a pencil with crazy glue so that it stuck straight up off the card ( perpendicular ), pointing away from it, that would be a "normal" to the triangle. You''ve probably heard people describe this as a normal to the plane, all that means is the pencil is the normal and the card is the plane.

If you need some code I suggest you checkout my racing game for the code to calculate normals, use them and also "reduce them to units". I''m not going to go into the reduction as it''d just confuse things.

//-- Modelling and animation in every dimension --//

Share this post

Link to post
Share on other sites
Hi baldurk!

So you''re wanting to move the object around like, let''s say quake or a racing game?

What you want to do is when you hit a key it''ll increase the y rotation (turn it) or make it go forward.

So let''s say you hit the right key

To make it spin right you''d do something like this

or left


Now to make it go forward you''d do something like this when you hit the up key.

x += (float)sin(yrot * (pi/180) ) * 1;
z -= (float)cos(yrot * (pi/180) ) * 1;

To make it go backward you''d simply change the +''s to -''s and the -''s to +''s.

Now that you have the x, z, and y rotation values you can now use these to rotate and move your object.

If you read tutorial 10 or 23, it''ll show you how to do this
Probably in better explanation than I can give you right now :p

Don''t pay attention to these guys right now, they''re being way too complicated for you right now, but sooner or later you''ll have to do it like that. This is the easy way

Hope that helps!

Don''t give up, I''m only 14...when I was first learning this stuff it was kinda hard. Now it''s a peice of cake!

Good luck to you and your project!

~Justin Eslinger~

Share this post

Link to post
Share on other sites
You can learn anything if you put your mind to it. I''m 14. When I was 12 I programmed a wireframe 3D engine in DJGPP with no libraries with correct matrix transformations. Only now I''m starting OpenGL, and working on a game:
Tank Wars 3D

Oh, and fshana: your right about the chicks going for the math kids

Share this post

Link to post
Share on other sites
btw, fshana, how do you know I am a boy?

anyway I now have a simple tank moving around, I fixed the bug without normals.

My next question is: how do I use normals in OpenGL?

don`t worry about feeling old, I hardly know anything about 3d programming.

btw I am going to upload (in the next few minutes) my simple tank program to:

and don`t worry, its less than 200kb

Share this post

Link to post
Share on other sites
Normals are only good for lighting. I think if it''s driving you want you should check out my code see the link below. Anyway here''s the low-down on normals...

For each face or triangle you do something like this:

// Make a silly struct
Struct Point3D {
float x,y,z ;
} Point3D

// Declare some stuff....
Point3D Pointa, Pointb, Pointc, out;


glNormal( out.x , out.y, out.z );

glVertex( Pointa.x ,Pointa.y, Pointa.z );
glVertex( Pointb.x,Pointb.y, Pointb.z );
glVertex( Pointc.x,Pointc.y, Pointc.z );

You''re problem is what''s out.x, out.y, out.z. Easy,

Use these simple functions, calling CalcNormal passing in a, b and c and getting back out filled with the normal coordinates of the plane a,b,c

void GLCalcNormal(Point3D a, Point3D b, Point3D c, Point3D *out)
Point3D v1,v2;

// Calculate two vectors from the three points
v1.x = a.x - b.x;
v1.y = a.y - b.y;
v1.z = a.z - b.z;

v2.x = b.x - c.x;
v2.y = b.y - c.y;
v2.z = b.z - c.z;

// Take the cross product of the two vectors to get
// the normal vector which will be stored in out
out->x = v1.y * v2.z - v1.z * v2.y;
out->y = v1.z * v2.x - v1.x * v2.z;
out->z = v1.x * v2.y - v1.y * v2.x;

// Normalize the vector (shorten length to one)

void GLElement::GLReduceToUnit(Point3D *vector)
float length;

// Calculate the length of the vector
length = (float)sqrt( (vector->x * vector->x ) +
(vector->y * vector->y ) +
(vector->z * vector->z ) );

// Keep the program from blowing up by providing an exceptable
// value for vectors that may calculated too close to zero.
if (length == 0.0f) length = 1.0f;

// Dividing each element by the length will result in a
// unit normal vector.
vector->x /= length;
vector->y /= length;
vector->z /= length;

I''ll say it one more time though, if it''s DRIVING code you want, get this code , it''ll show give you a framework to build on and you don''t need normals.
//-- Modelling and animation in every dimension --//

Share this post

Link to post
Share on other sites
You don''t need to use normals, but you should learn what they are anyway.

Anyway, to drive something around you need to keep track of a couple of things: It''s position and orientation. Let''s start simple, and say your working in 2D. You can still render in 3D but the tank will drive around on a plane.

Now, The position you store with two values:
float posx;
float posy;

The rotation you can store with an angle between 0 and 360:
float rotation;

Now when the program starts, initialize the variables. Then you check keypresses. If the player presses LEFT or RIGHT then you either add or subract from the rotation variable. When the player presses UP you need to move the tank forward. How do you do that? I''ll just give you the equations:

posx = posx + cos(rotation*PI/180)*speed;
posy = posy + sin(rotation*PI/180)*speed;

If you need more help post

Share this post

Link to post
Share on other sites