Advertisement

Help!..Why doesnt my objects move

Started by October 18, 2000 03:31 PM
1 comment, last by pauljg 24 years, 1 month ago
Hi Guys, need a little push in the right direction - my 3d engine is come to a full stop. What i`m trying to do is allow my object to be spun to any angle (x,y or z) - then move forwards in whatever direction the shape is facing. My camera code works fine based on the equations: cam.tranx+= (float)sin(cam.roty*piover180) * dist; cam.tranz+= (float)cos(cam.roty*piover180) * dist; cam.trany+= (float)sin(cam.rotx*piover180) * dist; Of course I`m doing all the inverse calcs and bits & bobs.. Like I`ve already said though, the camera works fine. So I was trying to get my object moving using the same formula - but for some reason it just doesnt go in the directions its facing. Here`s some code snippets that may give you a clue: struct { float rotx,roty,rotz; float tranx,trany,tranz; float offsetx,offsety,offsetz; float scalex,scaley,scalez; int shape_id; } object[num_of_objects+1]; ..... if (keys[188]){object[1].roty+=1.5f; } if (keys[190]){object[1].roty-=1.5f; } ..... void object_move(int objnum,float objdist) { object[objnum].tranx+=(float)sin(object[objnum].roty*piover180)*objdist; object[objnum].tranz+=(float)cos(object[objnum].roty*piover180)*objdist; object[objnum].trany+=(float)sin(object[objnum].rotx*piover180)*objdist; } ..... glTranslatef(object[num].tranx,object[num].trany,object[num].tranz); glRotatef(object[num].rotx,1.0f,0.0f,0.0f); glRotatef(object[num].roty,0.0f,1.0f,0.0f); glRotatef(object[num].rotz,0.0f,0.0f,1.0f); glBegin(GL_TRIANGLES); glColor3ub( shape[num3].colour_of_side_r[num2], shape[num3].colour_of_side_g[num2], shape[num3].colour_of_side_b[num2]); glVertex3f(tri[shape[num3].side[num2]].vx[1], tri[shape[num3].side[num2]].vy[1], tri[shape[num3].side[num2]].vz[1]); glEnd(); .... Please help an old guy out !!! Thanks Paul
position camera
glPushMatrix()
position object
glPopMatrix()
glPushMatrix()
position object
glPopMatrix()


http://members.xoom.com/myBollux
Advertisement
I already do that in the sections of code missing from the above.

Paul.

This topic is closed to new replies.

Advertisement