Skip to main content
GameDev.net gamedev.net
🔒 Locked

Object become flipping

Started by dean78 Jan 5, 2002 at 8:02 AM 0 replies 200+ views
Original Post
dean78
dean78
Hi everyone, First of all this program is completely from NeHe tutorial ported to GLUT. This program will display target that we can shoot using mouse using picking. The original tutorial will create 30 target object that will be assign with 5 random texture. I've modify it so user can shoot with the keyboard.I assign the key 'a' to the first object and so on. I assign 5 object with it own texture using the original texture but not randomly as NeHe does. So in the Function Draw i try to randomly display the object using rand() function. But it become flipping when I run it. Is it because the rand() function or something else? And how do I solve it?
    struct objects {
	GLuint	rot;	
	.
	.			
	GLfloat	distance;									
};

static GLvoid InitObject(int num)									
{	
								
	object[num].rot=1;										
	object[num].frame=0;	
	object[num].hit=false;		
	object[num].texid=num;		
	object[num].distance=-(float(rand()%3501)/100.0f);	
	object[num].y=-1.5f+(float(rand()%401)/100.0f);		
	object[num].x=((object[num].distance-15.0f)/2.0f)-(5*level)-float(rand()%(5*level));
	object[num].dir=(rand()%2);				

	if (object[num].dir==0)					
	{
		object[num].rot=2;				
		object[num].x=-object[num].x;			
	}

	if (object[num].texid==0)				
		object[num].y=-2.0f;				

}


static void Object(GLuint texid)				
{
	// Draw Object Using

}



void DrawTargets(void)							// Draws The Targets (Needs To Be Seperate)

{

	glLoadIdentity();						// Reset The Modelview Matrix

	glTranslatef(0.0f,0.0f,-10.0f);					// Move Into The Screen 20 Units

	
	for (int loop1=0; loop1<bilObject; loop1++)			
	{
		
		int loop=(rand()%30);
		glPushMatrix();								// Push The Modelview Matrix

		glTranslatef(object[loop].x,object[loop].y,object[loop].distance);	// Position The Object (x,y)

		if (object[loop].hit)							// If Object Has Been Hit

		{
			Explosion(loop);
			
		}
		else							// Otherwise

		{
			glRotatef(object[loop].spin,0.0f,0.0f,1.0f);	// Rotate The Object

			Object(loop);	// Draw The Object

		}
		glPopMatrix();						// Pop The Modelview Matrix

	}

}

static void Draw(void)							// Draw Our Scene

{	


	glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);		// Clear Screen And Depth Buffer

	glLoadIdentity();						// Reset The Modelview Matrix


	glPushMatrix();							// Push The Modelview Matrix

	glBindTexture(GL_TEXTURE_2D, textures[7].texID);		// Select The Sky Texture

	glBegin(GL_QUADS);						// Begin Drawing Quads

		.
		.
		.
	glEnd();							// Done Drawing Quads


	glBindTexture(GL_TEXTURE_2D, textures[6].texID);		// Select The Ground Texture

	glBegin(GL_QUADS);						// Draw A Quad

		.
		.
		.
	glEnd();							// Done Drawing Quad

	


	DrawTargets();						     	// Draw Our Targets

	glPopMatrix();	
	
	// Pop The Modelview Matrix

	glMatrixMode(GL_PROJECTION);					// Select The Projection Matrix

	glPushMatrix();							// Store The Projection Matrix

	glLoadIdentity();						// Reset The Projection Matrix

	glOrtho(0,g_width,0,g_height,-1,1);				// Set Up An Ortho Screen

	glMatrixMode(GL_MODELVIEW);					// Select The Modelview Matrix

	
	// Game Stats / Title

		.
		.
		.
	glMatrixMode(GL_PROJECTION);					// Select The Projection Matrix

	glPopMatrix();							// Restore The Old Projection Matrix

	glMatrixMode(GL_MODELVIEW);					// Select The Modelview Matrix


	glFlush();													
	glutSwapBuffers();
}

  
    
Edited by - dean78 on January 5, 2002 9:19:06 AM

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.