Sign in to follow this  
adritill

automotive movement camera in glut

Recommended Posts

adritill    100
hello, i know how to place a camera and look to somewhere with gluLookAt function, but now i have a wheel like this http://www.artesanum.com/upload/postal/9/3/7/noria-46979.jpg coded and i want to place a camera into the one box and travel with it, how could i implement that?
my wheel does a 360º movement and then it returns another -360º and repeat this pattern.

Share this post


Link to post
Share on other sites
FXACE    182
>> "position of box per frame" + "camera's position"...

Note:
1. initialize "position of your camera" at {x:0,y:0,z:0};
2. initialize "position of box" which would be relative to wheel object.
3. each time-line/frame "position of box per frame" = "position of box" * "rotation matrix of wheel".

the end.

Best wishes, FXACE.

Share this post


Link to post
Share on other sites
adritill    100
so this is the wheel code:
void wheel()
{
if(er==1)vr-=1;
else vr+=1;
if(vr>360)er=1;
else if(vr<-360) er=2;

glColor3d(1,1,0);

glPushMatrix();
glTranslatef(-230,-5,250);
glScalef(18,18,18);

glPushMatrix();
glTranslatef(10,4,-8.3);
glRotatef(vr,0,0,1);
glColor3d(sin(luz/9),1,0); c=1;
glutWireTorus(0.3,2.2,6,stacks);

glColor3d(1,0,0);
for(i=0;i<30;i++)
{
glPushMatrix();
glRotatef(90,0,1,0);
glRotatef(12*i,1,0,0);
glutWireCone(0,1.89,2,1);
glPopMatrix();
}

// Creamos los asientos
for(i=0;i<=12;i++)
{
glPushMatrix();
glColor3d(0,1,1);
glRotatef(90,0,1,0);
glRotatef(30*i,1,0,0);
glTranslatef(0,2.4,0);
glTranslatef(-0.2,0,0);
glRotatef(270,1,0,0);
glutSolidCone(0.05,0.5,slices,stacks);
glTranslatef(0.4,0,0);
glutSolidCone(0.05,0.5,slices,stacks);
glTranslatef(-0.2,0,0.5);
glRotatef(vr,1,0,0);
glutSolidCube(0.37);
glTranslatef(0,0.1,0);
glutSolidCube(0.25);
glPopMatrix();
}

glutSolidCone(0.2,0.7,slices,stacks);
glRotatef(180,1,0,0);
glutSolidCone(0.2,0.7,slices,stacks);
glPopMatrix();

glPushMatrix();
glColor3d(1,1,1);
glTranslatef(10,4,-9);
glRotatef(90,0,1,0);
glutSolidSphere(0.1,slices,stacks);
glTranslatef(-1.4,0,0);
glutSolidSphere(0.1,slices,stacks);
glTranslatef(0,-3.4,0);
glRotatef(180,0,1,1);
glutSolidCone(0.2,3.4,slices,stacks);
glColor3d(0,0,1);
glutSolidCube(0.8);
glTranslatef(-1.4,0,0);
glColor3d(1,1,1);
glutSolidCone(0.2,3.4,slices,stacks);
glColor3d(0,0,1);
glutSolidCube(0.8);
glPopMatrix();
glPopMatrix();
}

how would the camera be ?? negative of translation/rotation ?

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this