Archived

This topic is now archived and is closed to further replies.

Saqib

Starfield

Recommended Posts

Well I am making a space sim demo and a tried generating some starfields. The code i used for setting up the values of the x,y and z were as follows: (sorry for the lenght of message ) int starscape=2000; void reshape(){ int s = 0; for (s = 0; s < starscape; s++) { starsv[s].x = rand() % 320; starsv[s].y = rand() % 320; starsv[s].z = rand() % 30 ; starsv[s].w = rand() % 6 ; starsv[s].vx = rand() / (float)RAND_MAX/5; starsv[s].vy = rand() / (float)RAND_MAX; starsv[s].vz =rand() / (float)RAND_MAX; } } void Draw(){ int s=0; for (s = 0; s < starscape; s++) { gluOrtho2D(0,320,0,320); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glColorMaterial (GL_FRONT_AND_BACK,GL_DIFFUSE); glEnable (GL_COLOR_MATERIAL); if (starsv[s].x < 320) { glBegin(GL_LINE_STRIP); glColor3ub(0, 0, 0); glVertex3f(starsv[s].x-starsv[s].vx/2, starsv[s].y, starsv[s].z+0.01f); glColor3ub(255, 255, 255); glVertex3f(starsv[s].x, starsv[s].y, starsv[s].z); glEnd(); } } but the stars seem to move way too fast and do not seem to like come towards the user. Plz anyone tell me what i am doing wrong in order to get the stars as in the Space Wars demo on Nehe''s website.

Share this post


Link to post
Share on other sites
Yeah i know its for 2d but i have to other choice. I mean i am displaying a 3d spaceship and a starfield so i can''t display both with out using ortho2d for the starfield. Here''s the code i use for the DrawScene:
gldAspect = (GLdouble) glnWidth / (GLdouble) glnHeight;

glMatrixMode (GL_PROJECTION);
glLoadIdentity ();
gluPerspective (30.0,gldAspect,0.01f,10.0);

glViewport (0, 0, glnWidth, glnHeight);
glClear (GL_COLOR_BUFFER_BIT / GL_DEPTH_BUFFER_BIT);
glMatrixMode(GL_PROJECTION); //switch to a projection mode
glPushMatrix(); //store current projection mode
glDisable(GL_DEPTH_TEST); //disable z buffer
// include DrawStars() for my last post
glMatrixMode(GL_PROJECTION);
glPopMatrix(); //restore previous projection
glMatrixMode (GL_MODELVIEW);
glLoadIdentity ();
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LESS);
glTranslatef (0.0f, 0.0f, -8.0f);
glRotatef (360, 0.0f, 1.0f, 0.0f);
glRotatef (yrot, 0.0f, 0.0f, 1.0f);
glRotatef (xrot, 1.0f, 0.0f, 0.0f);
glScalef (2.5f-upspeed,2.5f-upspeed,2.5f-upspeed);

glMaterialf (GL_FRONT_AND_BACK, GL_SHININESS,20);
int mcount=0;
int mindex=0;
glBegin (GL_TRIANGLES);
for(int i=0;i {
if(!mcount)
{
SelectMaterial(material_ref[mindex][0]);
mcount=material_ref[mindex][1];
mindex++;
}
mcount--;
for(int j=0;j<3;j++)
{
int vi=face_indicies[j];
int ni=face_indicies[i][j+3];
int ti=face_indicies[i][j+6];
glNormal3f (normals[ni][0],normals[ni][1],normals[ni][2]);
glTexCoord2f(textures[ti][0],textures[ti][1]);
glVertex3f (verticies[vi][0],verticies[vi][1],verticies[vi][2]);
}
}
glEnd ();
yrot+=yspeed;
xrot+=xspeed;
SwapBuffers (hdc);

so now tell me what i should do?(if only the Space Wars demo src code could be public available and sorry for the long post)

Share this post


Link to post
Share on other sites
I did a thingy like this u want to do. I make a particle system. Them, when i press H, the particles (the star) come straight the camera. I take one of the vertex and increased the z in 3 or more. It looks like X-Wing, when we go to the HyperSpace. And, i could help u more if u knew what Push and PopMatrix do. I do many things in OpenGL, but...

"There are people who live in the reality. We recreate it!"

Share this post


Link to post
Share on other sites