• Advertisement
Sign in to follow this  

What's wrong with this?

This topic is 3405 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

Here's the code
void createSparkle(float x, float y, float z)
{
	srand(GetTickCount());
	
	glPushMatrix();
		glRotatef(rand() % 365, 1.0, 0.0, 0.0);
		glRotatef(rand() % 365, 0.0, 1.0, 0.0);
		glRotatef(rand() % 365, 0.0, 0.0, 1.0);
		
		glBegin(GL_LINES);
			// Green Line pointing RIGHT
			glColor3f(0.0f, 1.0f, 0.0f);
			glVertex3f(x, y, z);
			glVertex3f(1.0f, 0.0f, 0.0f);
			
			// Red Line pointing UP
			glColor3f(1.0f, 0.0f, 0.0f);
			glVertex3f(x, y, z);
			glVertex3f(0.0f, 1.0f, 0.0f);
			
			// Blue Line pointing LEFT
			glColor3f(0.0f, 0.0f, 1.0f);
			glVertex3f(x, y, z);
			glVertex3f(-1.0f, 0.0f, 0.0f);
			
			// Yellow Line pointing DOWN
			glColor3f(1.0f, 1.0f, 0.0f);
			glVertex3f(x, y, z);
			glVertex3f(0.0f, -0.0f, 0.0f);

			// White Line pointing Diagonal DOWN LEFT
			glColor3f(1.0f, 1.0f, 1.0f);
			glVertex3f(x, y, z);
			glVertex3f(-1.0f, -1.0f, 0.0f);

			// Black Line pointing Diagonal UP RIGHT
			glColor3f(0.0f, 0.0f, 0.0f);
			glVertex3f(x, y, z);
			glVertex3f(1.0f, 1.0f, 0.0f);
		glEnd();

		
	glPopMatrix();
}



Now when I tested this in Render() at 0,0,0 it works like I want it to. However, whenever I enter any other value, the 'sparkle' lines get away from the center that I designed for them. If I entered createSparkle(0.0f, 0.0f, 0.0f) it will create a rather nice looking (if cheaply done) centered sparkle on the point 0, 0, 0. Yet if I put createSparkle(1.0f, 0.0f, 0.0f) many of the lines are not on their proper centers, which SHOULD be 1,0,0. What the heck am I doing wrong or missing? (EDIT) OMG nevermind its so simple. I went to lay down to sleep and suddenly realized my error XD I neglected to change the end point of the lines. EDIT 2 Once again, I was wrong. this time I added x,y,z to the second Vertexes in each line set. This didn't solve the problem as I thought it would.... Help. :( [Edited by - Dark_Glitch on December 24, 2008 3:18:50 AM]

Share this post


Link to post
Share on other sites
Advertisement
each time you do this, you are drawing a line from the position you specified (x,y,z) to 1.0f,0.0f,0.0f (or whatever else).

These are points around the origin! if you have a situation where
x=y=z=20, then you will have a bunch of lines going from (20,20,20) to areas around the origin.

To fix this, you could either change it to something like


glVertex3f(x, y, z);
glVertex3f(x+1.0f, y+0.0f, z+0.0f);






OR


glTranslatef(x,y,z);
glVertex3f(0,0,0);
glVertex3f(1.0f, 0.0f, 0.0f);



(remember to untranslate / push-pop matrices.

Share this post


Link to post
Share on other sites
Thanks for that. Forgot to take that out.

EDIT:

New problem. I'm not sure why but when I try to call this more than once in Render() it won't create two of my 'sparkles'. Everything looks as the code says above save that I added a glTranslatef(x,y,z) instead of manipulating each vertex.

Why can't this function make multiple sparkles on the screen? Am I missing something?

[Edited by - Dark_Glitch on December 24, 2008 7:24:26 AM]

Share this post


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

  • Advertisement