• Announcements

Archived

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

steering objects

Recommended Posts

I have made a object out of quads and I have made it spin like nehes tutorial 7. What I want to know is how to create a variable (e.g. direction) to record which way it is facing and move it apporpriately, as if you can drive it around. Do you see what I mean.

Share on other sites
Use the normal of the face you want to be forward... Find the unit vector in that direction and move it along that in increments of one (because it''s a unit vector)... That should do it.

S.

Share on other sites
If it''s driving you want, check out my very simple and easy to follow driving thing in the Projects section of the CornflakeZone.com

-fs

http://www.CornflakeZone.com
//-- Modelling and animation in every dimension --//

Share on other sites
Help.

I am only 13 years old and I havent the foggiest as to what normals are

seriously

Share on other sites
Learn it, the most complicated thing in maths I have done in maths so far is algebra! I dont even know what sine is! and you are suggesting I learn NORMALS? what are you _on_?

sorry about that, but seriously, laerning normals isnt really an option.

any other help?

Share on other sites
I''m very sorry, but you''ll need to learn what normals are because they''re used very much in 3D.

Do a search here at the GDnet forums for "normals", they''re easy!

Share on other sites
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 on other sites
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 on other sites
Wait why am I registered as anonymous poster? I wrote that post above and can't edit it to make it not anonymous. Oh well

Edited by - David20321 on October 29, 2000 1:05:52 PM

Share on other sites
normals tell you which way the polygon is facing. they are used a lot in bsp based engines. also, you better learn the math before you try to understand 3d programming. it''ll just get more confusing.

JoeMont001@aol.com www.polarisoft.n3.net

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.

Later,
fs

http://www.CornflakeZone.com
//-- Modelling and animation in every dimension --//

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
yrot--;

or left

yrot++;

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~
~.."BlackScar"..~
~-=-=-=-=-=-=~

Share on other sites
thanks for all the replies to my question!

I now understand (vaguely) what normals are.

wait a minute, Ill be back later the school bell just rung

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 on other sites
You go Wolfman!!! Wow I''m pretty impressed by you guys being so young and all. I feel so ancient. Keep up the great work !
fs

http://www.CornflakeZone.com
//-- Modelling and animation in every dimension --//

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?

dont 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:
http://members.xoom.com/baldurk/3d/tank.exe

and dont worry, its less than 200kb

Share on other sites
the keys are forward,back,left and right to steer then f1 to change to window mode (or of course alt+enter) and r to reset if you drive off the screen, although that is beta quality

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;

glBegin(GL_TRIANGLES);

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)
GLReduceToUnit(out);
}

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.

http://www.CornflakeZone.com
//-- Modelling and animation in every dimension --//

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;[/source]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:[source]posx = posx + cos(rotation*PI/180)*speed;posy = posy + sin(rotation*PI/180)*speed; `

If you need more help post

Share on other sites
Stupid forum! You can''t post more than one piece of code!

Share on other sites
check out the fixed version at members.xoom.com/baldurk/3d/tank.exe

PLEASE tell me what you think of it

• Forum Statistics

• Total Topics
628282
• Total Posts
2981805

• 9
• 10
• 11
• 17
• 14