Jump to content
  • Advertisement
Sign in to follow this  
barantamer

OpenGL 3rd person view problem (gluLookAt)--HEEEEEEEELLLLLLLPP

This topic is 3972 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

hello i am new to opengl and i am stucked for hours , but i think my problem is really easy for most of u. I made a 3d robot ,and with `a` `s` `d` `w` keys it can move (forward and backwards)and rotate. However i couldnt make the camera follow (which i thought would be so simple). My code is below if any of you could figure out what is wrong i would be very happy.
#include<stdio.h>
#include<stdlib.h>
#include<gl/glut.h>
#include<gl/gl.h>
#include<time.h>
#include<math.h>



#define KEY_UP 101
#define KEY_DOWN 103


void display(void);
void init(void);
void drawstack(void);
void DrawRectangles(void);
void BaranKeyboardFunc(unsigned char ,int , int );
void BaranKeyboardUpFunc(unsigned char ,int , int );
void Special(int , int ,int );
void readfile(void);
void RandomColor(void);
void ChangeSize(GLsizei w, GLsizei h);
void DrawArmOneJointOne(void);
void DrawArmTwoJointOne(void);
void DrawArmOneJointTwo(void);
void DrawArmTwoJointTwo(void);
void DrawArmOneJointThree(void);
void DrawArmTwoJointThree(void);
void body(void);
void leg(void);
void pole(void);


int stackwidth,RecNum,unit,i,DrawCounter;
int g_window,random,random2,random3;
float posx=0.0f;
float posy=0.0f;
float posz=-20.0f;
int bayrak;
FILE *BaranPtr;
float a=0;
float arm1joint1=0,arm1joint2=0,arm1joint3=0;
int flags[6] = {0,0,0,0,0,0};
int arms[2]={0,0};
int up,down;
float rotation[6]={0,0,0,0,0,0};
float horotation[6]={0,0,0,0,0,0};
int counter=0;
float cevir=0;
float rotate=0,movez=0,mz=0,mx=0;
float conversion=0.01745;

struct rectangle
{
	float x;
	float y;
	float wit;
	float hayt;
	float x2;
	float y2;
	int color1;
	int color2;
	int color3;
	int cakisma;

}rec[100];

int main(int argc,char **argv)
{

	// srand(time(NULL));

	RandomColor();
	glutInit(&argc,argv);
	init();

	glutMainLoop();
	return 0;
}

void idle()
{

/*

	for(counter=0;counter<6;counter++){
					
				
		if(counter!=0){
						
		flags[counter]=0;
		}

			
	}
	
/*
	if(flags[0]==1)
	{
		arm1joint1+=0.1f;
	}
	if(flags[1]==1)
	{
		arm1joint2+=0.1f;
	}
	if(flags[2]==1)
	{
		arm1joint3+=0.1f;
	}






	if(flags[0]==2)
	{
		arm1joint1-=0.1f;
	}
	if(flags[1]==2)
	{
		arm1joint2-=0.1f;
	}
	if(flags[2]==2)
	{
		arm1joint3-=0.1f;
	}

*/


	glutPostRedisplay();
}

void init(void)
{
	glutInitDisplayMode(GLUT_RGBA|GLUT_DOUBLE);
	glutInitWindowSize(800,600);
	g_window=glutCreateWindow("Baran Tamer");

	glutDisplayFunc(display);
	glutKeyboardFunc(BaranKeyboardFunc);
	glutSpecialFunc(Special);
	glutKeyboardUpFunc(BaranKeyboardUpFunc);
	glutIdleFunc(idle);

	
	//glShadeModel(GL_SOLID);
	glClearColor(0.0f,0.0f,0.0f,1.0f);
	
	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
	gluPerspective(45.0f,800.0f/600.0f,0.1f,100.0f);
	glEnable(GL_DEPTH_TEST);
//	glDepthFunc(GL_LEQUAL);

}

void display()
{

int i=0;
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();

	
	
	mz=sin(90-rotate)*movez;
	mx=cos(90-rotate)*movez;
	



//	gluLookAt(0, 0,mz,  0, 0, mz-5,  0, 1, 0);

	gluLookAt(mx, 0,mz,  0, 0, movez-10,  0, 1, 0);
	
	

/*
	glPushMatrix();	
	glTranslatef(4,-2,-30.0f);

	pole();

	glTranslatef(-10,-2,2.0f);

	pole();

    glPopMatrix();
	
*/

	glPushMatrix();	
	glTranslatef(4,-2,-30.0f);

	pole();

	glTranslatef(-10,-2,2.0f);

	pole();

    glPopMatrix();
	


	glTranslatef(0,0,-30.0f);
	glTranslatef(0.0f,0.0f,movez);	
	glRotatef(rotate,0.0, 1.0, 0.0);

	//body begin
	glPushMatrix();	
	glTranslatef(0,1.5,0.0f);
	glRotatef(90,1, 0.0,0);
	body();
	glPopMatrix();
	//body end


	//leg begin
	glPushMatrix();
	glTranslatef(-1.5,-5.0f,0.5f);
	leg();
	glTranslatef(2.0,0.0f,0.0f);
	leg();
	glPopMatrix();
	//leg end
 
	


	


	glPushMatrix();

	//arm2 joint1
	glTranslatef(-2,0.0f,0.0f);
	glRotatef(rotation[0],0, 0.0,1);
	glRotatef(horotation[0],0, 1.0,0);
	DrawArmTwoJointOne();

  //DrawArmOneJointTwo();
	//end of arm joint one


	//arm2 joint2
	glTranslatef(-4,0,0);
	glRotatef(rotation[1],0, 0.0, 1);
	glRotatef(horotation[1],0, 1.0,0);
	DrawArmTwoJointTwo();
	//end of arm joint two


	//arm2 joint3
	glTranslatef(-4,0,0);
	glRotatef(rotation[2],0.0, 0.0, 1);
	glRotatef(horotation[2],0, 1.0,0);
	DrawArmTwoJointThree();
	//end of arm joint three
	
	glPopMatrix();
	





	//arm1 joint1
	glTranslatef(2,0,0);
	glRotatef(rotation[3],0.0, 0.0, -20);
	glRotatef(horotation[3],0, 1.0,0);
	DrawArmOneJointOne();
	//end of arm joint three
	
	
	//arm1 joint1
	glTranslatef(4,0,0);
	glRotatef(rotation[4],0.0, 0.0, -20);
	glRotatef(horotation[4],0, 1.0,0);
	DrawArmOneJointTwo();
	//end of arm joint three

	//arm1 joint1
	glTranslatef(4,0,0);
	glRotatef(rotation[5],0.0, 0.0, -20);
	glRotatef(horotation[5],0, 1.0,0);
	DrawArmOneJointThree();
	//end of arm joint three




	

	
	


	

	


	glutSwapBuffers();


}

void leg()
{
	glBegin(GL_QUADS);									// Draw A Quad
		//ön
		glColor3f(0.0f,0.0f,1.0f);						// Set The Color To Green
		glVertex3f( 0.0f, 0.0f, 0.0f);					// Top Right Of The Quad (Top)
		glVertex3f( 1.0f, 0.0f, 0.0f);					// Top Left Of The Quad (Top)
		glVertex3f( 1.0f, -7.0f, 0.0f);					// Bottom Left Of The Quad (Top)
		glVertex3f( 0.0f, -7.0f, 0.0f);					// Bottom Right Of The Quad (Top)
		//arka
		glColor3f(0.0f,0.0f,1.0f);						// Set The Color To Red
		glVertex3f( 0.0f, 0.0f, -1.0f);					// Top Right Of The Quad (Top)
		glVertex3f( 1.0f, 0.0f, -1.0f);					// Top Left Of The Quad (Top)
		glVertex3f( 1.0f, -7.0f, -1.0f);					// Bottom Left Of The Quad (Top)
		glVertex3f( 0.0f, -7.0f, -1.0f);					// Bottom Right Of The Quad (Top)
		//sol
		glColor3f(0.0f,0.0f,1.0f);						// Set The Color To Orange
		glVertex3f( 0.0f, 0.0f, 0.0f);					// Top Right Of The Quad (Bottom)
		glVertex3f( 0.0f, 0.0f, -1.0f);					// Top Left Of The Quad (Bottom)
		glVertex3f( 0.0f, -7.0f, -1.0f);					// Bottom Left Of The Quad (Bottom)
		glVertex3f( 0.0f, -7.0f, 0.0f);					// Bottom Right Of The Quad (Bottom)
		
		//sag
		glColor3f(0.0f,0.0f,1.0f);						// Set The Color To Orange
		glVertex3f( 1.0f, 0.0f, 0.0f);					// Top Right Of The Quad (Bottom)
		glVertex3f( 1.0f, 0.0f, -1.0f);					// Top Left Of The Quad (Bottom)
		glVertex3f( 1.0f, -7.0f, -1.0f);					// Bottom Left Of The Quad (Bottom)
		glVertex3f( 1.0f, -7.0f, 0.0f);					// Bottom Right Of The Quad (Bottom)
		//alt
		glColor3f(0.0f,0.0f,1.0f);						// Set The Color To Blue
		glVertex3f( 0.0f, 0.0f, 0.0f);					// Top Right Of The Quad (Left)
		glVertex3f( 0.0f, 0.0f, -1.0f);					// Top Left Of The Quad (Left)
		glVertex3f( 1.0f, 0.0f, -1.0f);					// Bottom Left Of The Quad (Left)
		glVertex3f( 1.0f, 0.0f, 0.0f);					// Bottom Right Of The Quad (Left)
		//üst
		glColor3f(0.0f,0.0f,1.0f);						// Set The Color To Blue
		glVertex3f( 0.0f, -7.0f, 0.0f);					// Top Right Of The Quad (Left)
		glVertex3f( 0.0f, -7.0f, -1.0f);					// Top Left Of The Quad (Left)
		glVertex3f( 1.0f, -7.0f, -1.0f);					// Bottom Left Of The Quad (Left)
		glVertex3f( 1.0f, -7.0f, 0.0f);					// Bottom Right Of The Quad (Left)
	glEnd();
}


void pole()
{
	glBegin(GL_QUADS);									// Draw A Quad
		//ön
		glColor3f(0.0f,0.0f,1.0f);						// Set The Color To Green
		glVertex3f( 0.0f, 0.0f, 0.0f);					// Top Right Of The Quad (Top)
		glVertex3f( 1.0f, 0.0f, 0.0f);					// Top Left Of The Quad (Top)
		glVertex3f( 1.0f, -7.0f, 0.0f);					// Bottom Left Of The Quad (Top)
		glVertex3f( 0.0f, -7.0f, 0.0f);					// Bottom Right Of The Quad (Top)
		//arka
		glColor3f(0.0f,0.0f,1.0f);						// Set The Color To Red
		glVertex3f( 0.0f, 0.0f, -1.0f);					// Top Right Of The Quad (Top)
		glVertex3f( 1.0f, 0.0f, -1.0f);					// Top Left Of The Quad (Top)
		glVertex3f( 1.0f, -7.0f, -1.0f);					// Bottom Left Of The Quad (Top)
		glVertex3f( 0.0f, -7.0f, -1.0f);					// Bottom Right Of The Quad (Top)
		//sol
		glColor3f(0.0f,0.0f,1.0f);						// Set The Color To Orange
		glVertex3f( 0.0f, 0.0f, 0.0f);					// Top Right Of The Quad (Bottom)
		glVertex3f( 0.0f, 0.0f, -1.0f);					// Top Left Of The Quad (Bottom)
		glVertex3f( 0.0f, -7.0f, -1.0f);					// Bottom Left Of The Quad (Bottom)
		glVertex3f( 0.0f, -7.0f, 0.0f);					// Bottom Right Of The Quad (Bottom)
		
		//sag
		glColor3f(0.0f,0.0f,1.0f);						// Set The Color To Orange
		glVertex3f( 1.0f, 0.0f, 0.0f);					// Top Right Of The Quad (Bottom)
		glVertex3f( 1.0f, 0.0f, -1.0f);					// Top Left Of The Quad (Bottom)
		glVertex3f( 1.0f, -7.0f, -1.0f);					// Bottom Left Of The Quad (Bottom)
		glVertex3f( 1.0f, -7.0f, 0.0f);					// Bottom Right Of The Quad (Bottom)
		//alt
		glColor3f(0.0f,0.0f,1.0f);						// Set The Color To Blue
		glVertex3f( 0.0f, 0.0f, 0.0f);					// Top Right Of The Quad (Left)
		glVertex3f( 0.0f, 0.0f, -1.0f);					// Top Left Of The Quad (Left)
		glVertex3f( 1.0f, 0.0f, -1.0f);					// Bottom Left Of The Quad (Left)
		glVertex3f( 1.0f, 0.0f, 0.0f);					// Bottom Right Of The Quad (Left)
		//üst
		glColor3f(0.0f,0.0f,1.0f);						// Set The Color To Blue
		glVertex3f( 0.0f, -7.0f, 0.0f);					// Top Right Of The Quad (Left)
		glVertex3f( 0.0f, -7.0f, -1.0f);					// Top Left Of The Quad (Left)
		glVertex3f( 1.0f, -7.0f, -1.0f);					// Bottom Left Of The Quad (Left)
		glVertex3f( 1.0f, -7.0f, 0.0f);					// Bottom Right Of The Quad (Left)
	glEnd();
}

void body()
{

	glColor3f(1.0f,0.0f,0.0f);
	gluCylinder(gluNewQuadric(), 2, 2,7, 50, 50);



}

void DrawArmOneJointOne()
{
	glBegin(GL_QUADS);									// Draw A Quad
		//ön
		glColor3f(0.0f,1.0f,0.0f);						// Set The Color To Green
		glVertex3f( 0.0f, 0.0f, 0.0f);					// Top Right Of The Quad (Top)
		glVertex3f( 4.0f, 0.0f, 0.0f);					// Top Left Of The Quad (Top)
		glVertex3f( 4.0f, 1.0f, 0.0f);					// Bottom Left Of The Quad (Top)
		glVertex3f( 0.0f, 1.0f, 0.0f);					// Bottom Right Of The Quad (Top)
		//arka
		glColor3f(1.0f,1.0f,0.0f);						// Set The Color To Red
		glVertex3f( 0.0f, 0.0f, -1.0f);					// Top Right Of The Quad (Top)
		glVertex3f( 4.0f, 0.0f, -1.0f);					// Top Left Of The Quad (Top)
		glVertex3f( 4.0f, 1.0f, -1.0f);					// Bottom Left Of The Quad (Top)
		glVertex3f( 0.0f, 1.0f, -1.0f);					// Bottom Right Of The Quad (Top)
		//sol
		glColor3f(1.0f,0.0f,0.0f);						// Set The Color To Orange
		glVertex3f( 0.0f, 0.0f, 0.0f);					// Top Right Of The Quad (Bottom)
		glVertex3f( 0.0f, 0.0f, -1.0f);					// Top Left Of The Quad (Bottom)
		glVertex3f( 0.0f, 1.0f, -1.0f);					// Bottom Left Of The Quad (Bottom)
		glVertex3f( 0.0f, 1.0f, 0.0f);					// Bottom Right Of The Quad (Bottom)
		
		//sag
		glColor3f(1.0f,0.0f,0.0f);						// Set The Color To Orange
		glVertex3f( 4.0f, 0.0f, 0.0f);					// Top Right Of The Quad (Bottom)
		glVertex3f( 4.0f, 0.0f, -1.0f);					// Top Left Of The Quad (Bottom)
		glVertex3f( 4.0f, 1.0f, -1.0f);					// Bottom Left Of The Quad (Bottom)
		glVertex3f( 4.0f, 1.0f, 0.0f);					// Bottom Right Of The Quad (Bottom)
		//alt
		glColor3f(0.0f,0.0f,1.0f);						// Set The Color To Blue
		glVertex3f( 0.0f, 0.0f, 0.0f);					// Top Right Of The Quad (Left)
		glVertex3f( 0.0f, 0.0f, -1.0f);					// Top Left Of The Quad (Left)
		glVertex3f( 4.0f, 0.0f, -1.0f);					// Bottom Left Of The Quad (Left)
		glVertex3f( 4.0f, 0.0f, 0.0f);					// Bottom Right Of The Quad (Left)
		//üst
		glColor3f(0.0f,0.0f,1.0f);						// Set The Color To Blue
		glVertex3f( 0.0f, 1.0f, 0.0f);					// Top Right Of The Quad (Left)
		glVertex3f( 0.0f, 1.0f, -1.0f);					// Top Left Of The Quad (Left)
		glVertex3f( 4.0f, 1.0f, -1.0f);					// Bottom Left Of The Quad (Left)
		glVertex3f( 4.0f, 1.0f, 0.0f);					// Bottom Right Of The Quad (Left)
	glEnd();
  }

void DrawArmOneJointTwo()
{
glBegin(GL_QUADS);									// Draw A Quad
		//ön
		glColor3f(1.0f,1.0f,0.0f);						// Set The Color To Green
		glVertex3f( 0.0f, 0.0f, 0.0f);					// Top Right Of The Quad (Top)
		glVertex3f( 4.0f, 0.0f, 0.0f);					// Top Left Of The Quad (Top)
		glVertex3f( 4.0f, 1.0f, 0.0f);					// Bottom Left Of The Quad (Top)
		glVertex3f( 0.0f, 1.0f, 0.0f);					// Bottom Right Of The Quad (Top)
		//arka
		glColor3f(1.0f,1.0f,0.0f);						// Set The Color To Red
		glVertex3f( 0.0f, 0.0f, -1.0f);					// Top Right Of The Quad (Top)
		glVertex3f( 4.0f, 0.0f, -1.0f);					// Top Left Of The Quad (Top)
		glVertex3f( 4.0f, 1.0f, -1.0f);					// Bottom Left Of The Quad (Top)
		glVertex3f( 0.0f, 1.0f, -1.0f);					// Bottom Right Of The Quad (Top)
		//sol
		glColor3f(1.0f,0.0f,0.0f);						// Set The Color To Orange
		glVertex3f( 0.0f, 0.0f, 0.0f);					// Top Right Of The Quad (Bottom)
		glVertex3f( 0.0f, 0.0f, -1.0f);					// Top Left Of The Quad (Bottom)
		glVertex3f( 0.0f, 1.0f, -1.0f);					// Bottom Left Of The Quad (Bottom)
		glVertex3f( 0.0f, 1.0f, 0.0f);					// Bottom Right Of The Quad (Bottom)
		
		//sag
		glColor3f(1.0f,0.0f,0.0f);						// Set The Color To Orange
		glVertex3f( 4.0f, 0.0f, 0.0f);					// Top Right Of The Quad (Bottom)
		glVertex3f( 4.0f, 0.0f, -1.0f);					// Top Left Of The Quad (Bottom)
		glVertex3f( 4.0f, 1.0f, -1.0f);					// Bottom Left Of The Quad (Bottom)
		glVertex3f( 4.0f, 1.0f, 0.0f);					// Bottom Right Of The Quad (Bottom)
		//alt
		glColor3f(0.0f,0.0f,1.0f);						// Set The Color To Blue
		glVertex3f( 0.0f, 0.0f, 0.0f);					// Top Right Of The Quad (Left)
		glVertex3f( 0.0f, 0.0f, -1.0f);					// Top Left Of The Quad (Left)
		glVertex3f( 4.0f, 0.0f, -1.0f);					// Bottom Left Of The Quad (Left)
		glVertex3f( 4.0f, 0.0f, 0.0f);					// Bottom Right Of The Quad (Left)
		//üst
		glColor3f(0.0f,0.0f,1.0f);						// Set The Color To Blue
		glVertex3f( 0.0f, 1.0f, 0.0f);					// Top Right Of The Quad (Left)
		glVertex3f( 0.0f, 1.0f, -1.0f);					// Top Left Of The Quad (Left)
		glVertex3f( 4.0f, 1.0f, -1.0f);					// Bottom Left Of The Quad (Left)
		glVertex3f( 4.0f, 1.0f, 0.0f);					// Bottom Right Of The Quad (Left)
	glEnd();
}


void DrawArmOneJointThree()
{
	glBegin(GL_QUADS);									// Draw A Quad
		//ön
		glColor3f(1.0f,0.0f,0.0f);						// Set The Color To Green
		glVertex3f( 0.0f, 0.0f, 0.0f);					// Top Right Of The Quad (Top)
		glVertex3f( 1.0f, 0.0f, 0.0f);					// Top Left Of The Quad (Top)
		glVertex3f( 1.0f, 1.0f, 0.0f);					// Bottom Left Of The Quad (Top)
		glVertex3f( 0.0f, 1.0f, 0.0f);					// Bottom Right Of The Quad (Top)
		//arka
		glColor3f(1.0f,0.0f,0.0f);						// Set The Color To Red
		glVertex3f( 0.0f, 0.0f, -1.0f);					// Top Right Of The Quad (Top)
		glVertex3f( 1.0f, 0.0f, -1.0f);					// Top Left Of The Quad (Top)
		glVertex3f( 1.0f, 1.0f, -1.0f);					// Bottom Left Of The Quad (Top)
		glVertex3f( 0.0f, 1.0f, -1.0f);					// Bottom Right Of The Quad (Top)
		//sol
		glColor3f(1.0f,0.0f,0.0f);						// Set The Color To Orange
		glVertex3f( 0.0f, 0.0f, 0.0f);					// Top Right Of The Quad (Bottom)
		glVertex3f( 0.0f, 0.0f, -1.0f);					// Top Left Of The Quad (Bottom)
		glVertex3f( 0.0f, 1.0f, -1.0f);					// Bottom Left Of The Quad (Bottom)
		glVertex3f( 0.0f, 1.0f, 0.0f);					// Bottom Right Of The Quad (Bottom)
		
		//sag
		glColor3f(1.0f,0.0f,0.0f);						// Set The Color To Orange
		glVertex3f( 1.0f, 0.0f, 0.0f);					// Top Right Of The Quad (Bottom)
		glVertex3f( 1.0f, 0.0f, -1.0f);					// Top Left Of The Quad (Bottom)
		glVertex3f( 1.0f, 1.0f, -1.0f);					// Bottom Left Of The Quad (Bottom)
		glVertex3f( 1.0f, 1.0f, 0.0f);					// Bottom Right Of The Quad (Bottom)
		//alt
		glColor3f(1.0f,0.0f,0.0f);						// Set The Color To Blue
		glVertex3f( 0.0f, 0.0f, 0.0f);					// Top Right Of The Quad (Left)
		glVertex3f( 0.0f, 0.0f, -1.0f);					// Top Left Of The Quad (Left)
		glVertex3f( 1.0f, 0.0f, -1.0f);					// Bottom Left Of The Quad (Left)
		glVertex3f( 1.0f, 0.0f, 0.0f);					// Bottom Right Of The Quad (Left)
		//üst
		glColor3f(1.0f,0.0f,0.0f);						// Set The Color To Blue
		glVertex3f( 0.0f, 1.0f, 0.0f);					// Top Right Of The Quad (Left)
		glVertex3f( 0.0f, 1.0f, -1.0f);					// Top Left Of The Quad (Left)
		glVertex3f( 1.0f, 1.0f, -1.0f);					// Bottom Left Of The Quad (Left)
		glVertex3f( 1.0f, 1.0f, 0.0f);					// Bottom Right Of The Quad (Left)
	glEnd();	

}

void DrawArmTwoJointOne()
{
	glBegin(GL_QUADS);									// Draw A Quad
		//ön
		glColor3f(0.0f,1.0f,0.0f);						// Set The Color To Green
		glVertex3f( 0.0f, 0.0f, 0.0f);					// Top Right Of The Quad (Top)
		glVertex3f( -4.0f, 0.0f, 0.0f);					// Top Left Of The Quad (Top)
		glVertex3f( -4.0f, 1.0f, 0.0f);					// Bottom Left Of The Quad (Top)
		glVertex3f( 0.0f, 1.0f, 0.0f);					// Bottom Right Of The Quad (Top)
		//arka
		glColor3f(0.0f,1.0f,0.0f);						// Set The Color To Red
		glVertex3f( 0.0f, 0.0f, -1.0f);					// Top Right Of The Quad (Top)
		glVertex3f( -4.0f, 0.0f, -1.0f);					// Top Left Of The Quad (Top)
		glVertex3f( -4.0f, 1.0f, -1.0f);					// Bottom Left Of The Quad (Top)
		glVertex3f( 0.0f, 1.0f, -1.0f);					// Bottom Right Of The Quad (Top)
		//sol
		glColor3f(0.0f,1.0f,0.0f);						// Set The Color To Orange
		glVertex3f( 0.0f, 0.0f, 0.0f);					// Top Right Of The Quad (Bottom)
		glVertex3f( 0.0f, 0.0f, -1.0f);					// Top Left Of The Quad (Bottom)
		glVertex3f( 0.0f, 1.0f, -1.0f);					// Bottom Left Of The Quad (Bottom)
		glVertex3f( 0.0f, 1.0f, 0.0f);					// Bottom Right Of The Quad (Bottom)
		
		//sag
		glColor3f(0.0f,1.0f,0.0f);						// Set The Color To Orange
		glVertex3f( -4.0f, 0.0f, 0.0f);					// Top Right Of The Quad (Bottom)
		glVertex3f( -4.0f, 0.0f, -1.0f);					// Top Left Of The Quad (Bottom)
		glVertex3f( -4.0f, 1.0f, -1.0f);					// Bottom Left Of The Quad (Bottom)
		glVertex3f( -4.0f, 1.0f, 0.0f);					// Bottom Right Of The Quad (Bottom)
		//alt
		glColor3f(0.0f,1.0f,0.0f);						// Set The Color To Blue
		glVertex3f( 0.0f, 0.0f, 0.0f);					// Top Right Of The Quad (Left)
		glVertex3f( 0.0f, 0.0f, -1.0f);					// Top Left Of The Quad (Left)
		glVertex3f( -4.0f, 0.0f, -1.0f);					// Bottom Left Of The Quad (Left)
		glVertex3f( -4.0f, 0.0f, 0.0f);					// Bottom Right Of The Quad (Left)
		//üst
		glColor3f(0.0f,1.0f,0.0f);						// Set The Color To Blue
		glVertex3f( 0.0f, 1.0f, 0.0f);					// Top Right Of The Quad (Left)
		glVertex3f( 0.0f, 1.0f, -1.0f);					// Top Left Of The Quad (Left)
		glVertex3f( -4.0f, 1.0f, -1.0f);					// Bottom Left Of The Quad (Left)
		glVertex3f( -4.0f, 1.0f, 0.0f);					// Bottom Right Of The Quad (Left)
	glEnd();	
}


void DrawArmTwoJointTwo()
{
	glBegin(GL_QUADS);									// Draw A Quad
		//ön
		glColor3f(1.0f,1.0f,0.0f);						// Set The Color To Green
		glVertex3f( 0.0f, 0.0f, 0.0f);					// Top Right Of The Quad (Top)
		glVertex3f( -4.0f, 0.0f, 0.0f);					// Top Left Of The Quad (Top)
		glVertex3f( -4.0f, 1.0f, 0.0f);					// Bottom Left Of The Quad (Top)
		glVertex3f( 0.0f, 1.0f, 0.0f);					// Bottom Right Of The Quad (Top)
		//arka
		glColor3f(1.0f,1.0f,0.0f);						// Set The Color To Red
		glVertex3f( 0.0f, 0.0f, -1.0f);					// Top Right Of The Quad (Top)
		glVertex3f( -4.0f, 0.0f, -1.0f);					// Top Left Of The Quad (Top)
		glVertex3f( -4.0f, 1.0f, -1.0f);					// Bottom Left Of The Quad (Top)
		glVertex3f( 0.0f, 1.0f, -1.0f);					// Bottom Right Of The Quad (Top)
		//sol
		glColor3f(1.0f,0.0f,0.0f);						// Set The Color To Orange
		glVertex3f( 0.0f, 0.0f, 0.0f);					// Top Right Of The Quad (Bottom)
		glVertex3f( 0.0f, 0.0f, -1.0f);					// Top Left Of The Quad (Bottom)
		glVertex3f( 0.0f, 1.0f, -1.0f);					// Bottom Left Of The Quad (Bottom)
		glVertex3f( 0.0f, 1.0f, 0.0f);					// Bottom Right Of The Quad (Bottom)
		
		//sag
		glColor3f(1.0f,0.0f,0.0f);						// Set The Color To Orange
		glVertex3f( -4.0f, 0.0f, 0.0f);					// Top Right Of The Quad (Bottom)
		glVertex3f( -4.0f, 0.0f, -1.0f);					// Top Left Of The Quad (Bottom)
		glVertex3f( -4.0f, 1.0f, -1.0f);					// Bottom Left Of The Quad (Bottom)
		glVertex3f( -4.0f, 1.0f, 0.0f);					// Bottom Right Of The Quad (Bottom)
		//alt
		glColor3f(0.0f,0.0f,1.0f);						// Set The Color To Blue
		glVertex3f( 0.0f, 0.0f, 0.0f);					// Top Right Of The Quad (Left)
		glVertex3f( 0.0f, 0.0f, -1.0f);					// Top Left Of The Quad (Left)
		glVertex3f( -4.0f, 0.0f, -1.0f);					// Bottom Left Of The Quad (Left)
		glVertex3f( -4.0f, 0.0f, 0.0f);					// Bottom Right Of The Quad (Left)
		//üst
		glColor3f(0.0f,0.0f,1.0f);						// Set The Color To Blue
		glVertex3f( 0.0f, 1.0f, 0.0f);					// Top Right Of The Quad (Left)
		glVertex3f( 0.0f, 1.0f, -1.0f);					// Top Left Of The Quad (Left)
		glVertex3f( -4.0f, 1.0f, -1.0f);					// Bottom Left Of The Quad (Left)
		glVertex3f( -4.0f, 1.0f, 0.0f);					// Bottom Right Of The Quad (Left)
	glEnd();	
}

void DrawArmTwoJointThree()
{
	glBegin(GL_QUADS);									// Draw A Quad
		//ön
		glColor3f(1.0f,0.0f,0.0f);						// Set The Color To Green
		glVertex3f( 0.0f, 0.0f, 0.0f);					// Top Right Of The Quad (Top)
		glVertex3f( -1.0f, 0.0f, 0.0f);					// Top Left Of The Quad (Top)
		glVertex3f( -1.0f, 1.0f, 0.0f);					// Bottom Left Of The Quad (Top)
		glVertex3f( 0.0f, 1.0f, 0.0f);					// Bottom Right Of The Quad (Top)
		//arka
		glColor3f(1.0f,0.0f,0.0f);						// Set The Color To Red
		glVertex3f( 0.0f, 0.0f, -1.0f);					// Top Right Of The Quad (Top)
		glVertex3f( -1.0f, 0.0f, -1.0f);					// Top Left Of The Quad (Top)
		glVertex3f( -1.0f, 1.0f, -1.0f);					// Bottom Left Of The Quad (Top)
		glVertex3f( 0.0f, 1.0f, -1.0f);					// Bottom Right Of The Quad (Top)
		//sol
		glColor3f(1.0f,0.0f,0.0f);						// Set The Color To Orange
		glVertex3f( 0.0f, 0.0f, 0.0f);					// Top Right Of The Quad (Bottom)
		glVertex3f( 0.0f, 0.0f, -1.0f);					// Top Left Of The Quad (Bottom)
		glVertex3f( 0.0f, 1.0f, -1.0f);					// Bottom Left Of The Quad (Bottom)
		glVertex3f( 0.0f, 1.0f, 0.0f);					// Bottom Right Of The Quad (Bottom)
		
		//sag
		glColor3f(1.0f,0.0f,0.0f);						// Set The Color To Orange
		glVertex3f( -1.0f, 0.0f, 0.0f);					// Top Right Of The Quad (Bottom)
		glVertex3f( -1.0f, 0.0f, -1.0f);					// Top Left Of The Quad (Bottom)
		glVertex3f( -1.0f, 1.0f, -1.0f);					// Bottom Left Of The Quad (Bottom)
		glVertex3f( -1.0f, 1.0f, 0.0f);					// Bottom Right Of The Quad (Bottom)
		//alt
		glColor3f(0.0f,0.0f,1.0f);						// Set The Color To Blue
		glVertex3f( 0.0f, 0.0f, 0.0f);					// Top Right Of The Quad (Left)
		glVertex3f( 0.0f, 0.0f, -1.0f);					// Top Left Of The Quad (Left)
		glVertex3f( -1.0f, 0.0f, -1.0f);					// Bottom Left Of The Quad (Left)
		glVertex3f( -1.0f, 0.0f, 0.0f);					// Bottom Right Of The Quad (Left)
		//üst
		glColor3f(0.0f,0.0f,1.0f);						// Set The Color To Blue
		glVertex3f( 0.0f, 1.0f, 0.0f);					// Top Right Of The Quad (Left)
		glVertex3f( 0.0f, 1.0f, -1.0f);					// Top Left Of The Quad (Left)
		glVertex3f( -1.0f, 1.0f, -1.0f);					// Bottom Left Of The Quad (Left)
		glVertex3f( -1.0f, 1.0f, 0.0f);					// Bottom Right Of The Quad (Left)
	glEnd();	
}


void BaranKeyboardFunc(unsigned char key,int x , int y)
{
	switch(key){
	case 'l':
		arms[0]=1;
		arms[1]=0;
		break;
	case 'r':
		arms[0]=0;
		arms[1]=1;
		break;

	case 'd':
		rotate-=0.1;
		break;
	case 'a':
		rotate+=0.1;
		break;

	case 'w':
		movez-=0.1;
		break;

	case 's':
		movez+=0.1;
		break;

	
	
	
		default:
		break;
		


	return;

	}
	


	
	
	if(arms[0])
	{
		
			switch(key){
			
			
			case '1':
				flags[0]=1;
			
				for(counter=0;counter<6;counter++){
					
				
					if(counter!=0){
						
					flags[counter]=0;
					}

			
				}
				printf("left arm joint1\n");
				
			
				
			
					

				break;
			case '2':
				flags[1]=1;
				for(counter=0;counter<6;counter++){
					
				
						if(counter!=1){
						
						flags[counter]=0;
					}

			
				}
			
			
				printf("left arm joint2\n");
				break;
			
			case '3':
			
				flags[2]=1;
				for(counter=0;counter<6;counter++){
					
						
						if(counter!=2){
									
						flags[counter]=0;
					}

			
				}
				printf("left arm joint3\n");
				break;
				
	
			default:
				break;

			return;
			}


	}

	
	
	if(arms[1])
	{
		
			switch(key){
			case '1':
				flags[3]=1;	
				
				for(counter=0;counter<6;counter++){
					
				
					if(counter!=3){
						
					flags[counter]=0;
					}

			
				}

				printf("right arm joint1\n");
				break;
			case '2':
				flags[4]=1;
				
				for(counter=0;counter<6;counter++){
					
				
					if(counter!=4){
						
					flags[counter]=0;
					}

			
				}
				
				printf("right arm joint2\n");
				break;
			case '3':
				flags[5]=1;
				
				for(counter=0;counter<6;counter++){
					
				
					if(counter!=5){
						
					flags[counter]=0;
					}

			
				}
				
				
				printf("right arm joint2\n");
				break;
				
	
			default:
				break;

			return;
			}


	}
















}



void BaranKeyboardUpFunc(unsigned char key,int x , int y)
{

	/*
	switch(key){
	case '1':
		flags[0]=0;		
		break;
	
	case '2':
		flags[1]=0;
		break;
	case '3':
		flags[2]=0;
		break;



	default:
		break;

	return;
	}

  */
	
}





void RandomColor()
{
	int sayac;

	for(sayac=0;sayac<RecNum;sayac++)
	{
		random=rand()%100+1;
		random2=rand()%100+1;
		random3=rand()%100+1;

		rec[sayac].color1=random;
		rec[sayac].color2=random2;
		rec[sayac].color3=random3;
	}
}

void ChangeSize(GLsizei w, GLsizei h)
{
	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
	gluPerspective(45.0f,(float)w/h,0.1f,100.0f);
}


void Special(int key , int x,int y){


	switch(key){

	case 101:

			printf("leftarm=%d rightarm1=%d  up\n",arms[0],arms[1]);
		
		
		for(counter=0; counter<6 ;counter++){

	
			
			if(flags[counter]==1)
			{

				printf("heyooo\n");
				printf("counter === %d\n",counter);
				
				if(counter>2){
				rotation[counter]-=0.50f;
				}
				else{

					rotation[counter]-=0.50f;
				}
				continue;

			}

	
		
		
		
		
		}
	///	printf("yukari");
		break;

	case 102:

			printf("leftarm=%d rightarm1=%d  up\n",arms[0],arms[1]);
		
		
		for(counter=0; counter<6 ;counter++){

	
			
			if(flags[counter]==1)
			{

				printf("heyooo\n");
				printf("counter === %d\n",counter);
				
				if(counter>2){
				horotation[counter]-=0.50f;
				}
				else{

					horotation[counter]+=0.50f;
				}
				continue;

			}

	
		
		
		
		
		}
	///	printf("yukari");
		break;
	
		case 100:

			printf("leftarm=%d rightarm1=%d  up\n",arms[0],arms[1]);
		
		
		for(counter=0; counter<6 ;counter++){

	
			
			if(flags[counter]==1)
			{

				printf("heyooo\n");
				printf("counter === %d\n",counter);
				
				if(counter>2){
				horotation[counter]+=0.50f;
				}
				else{

					horotation[counter]-=0.50f;
				}
				continue;

			}

	
		
		
		
		
		}
	///	printf("yukari");
		break;

	case 103:

			printf("leftarm=%d rightarm1=%d  down\n",arms[0],arms[1]);

		for(counter=0; counter<6 ;counter++){

	
			
			if(flags[counter]==1)
			{

				printf("heyooo\n");
				printf("counter === %d\n",counter);

				if(counter>2){
				rotation[counter]+=0.50f;
				}
				else{

					rotation[counter]+=0.50f;
				}
				continue;
				
			}

		
		
		
		
		
		}

		//printf("assaaa");
		break;

	default:
		break;



		return;







	}





}


[Edited by - barantamer on December 3, 2007 10:49:49 AM]

Share this post


Link to post
Share on other sites
Advertisement
Very nice of you! You could at least have used the [ source ] tags so the code wouldn't take that much space and would be formatted better. You should also tell us more precisely what your problem is, as you can't assume everyone will read through all the source!

Share this post


Link to post
Share on other sites
My exact problem is . I wanna follow my robot from behind all the time . Even if it rotates left or right. Which means i need to change the view point when it rotates and put it 10 units behind the robot (as in the game HITMAN.. i hope u ve heard of it).
And u should only look inside display() function in the code to see the problem.I tried to use gluLookAt() to change the view point.
btw: variable 'rotate' is the value for how much the robot rotates
variable 'movez' is the value for hom much the robot moves

is that clear enough ?

Share this post


Link to post
Share on other sites

Hey there,

try this :

gluLookAt(0, 0,movez, 0, 0, movez-10, 0, 1, 0);

this will make ur camera follow ur object and the camera is behind ur object,

i hope this is what u wanted .

take care.

Share this post


Link to post
Share on other sites
Yea im not going to read your code ,but

The camera look at should be the characters x,y,z.
The camera position should be the characters move vector*-1*(how far you want the camera back).

Share this post


Link to post
Share on other sites
thx for ur answer ff8
but the actual problem is when i rotate my robot . Your answer is only about going forward and backwards , right ?

Share this post


Link to post
Share on other sites


yes , just forward and backward.

so u need ur camera to rotate based on ur char? if so then u need to do:

1) build coordinate system where its origin point at the center of ur char.

2) rotate ur coordinate sysem based on the up-vector(like y in stander system)

3) now u have camera position rotated based on ur char coordinate system use it on ur glLookAt() call.

i hope it works w/ u ^^.

take care.

Share this post


Link to post
Share on other sites
I've used this website for First person cameras before, it worked great. The article isn't very good on cameras, but download the source. They have quite a few first and third person cameas.
apron tutorials
Really nice stuff there.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!