PDA

View Full Version : frustum class / particle generator



arctbl
02-24-2009, 09:11 AM
I am working on a sim of moving through a field of objects. when an object disappears behind you, another is supposed to appear in front no matter which way the camera has turned. i am using a frustum class that calculates the parameters of the viewable area but i can't seem to figure out the math after the camera has been turned.

this is the part that generates and displays objects
for ( int i = 0; i < NUM_STARS; i++ )

{

glPushMatrix();

glTranslatef( g_xyz[i][0], g_xyz[i][1], g_xyz[i][2] );

if (g_color==GL_TRUE)

glColor3fv( g_colors[i] );

else

glColor3f( 255,255,255);

glPointSize(g_pointsize); //sets the pixel size of the stars

glBegin(GL_POINTS); // render with points

glVertex2i(0,0); //display a point at current x,y,z

glEnd();

glPopMatrix();



GLfloat lowest, highest, range;

GLfloat xp,yp,zp;

camera.GetPosition(&xp,&yp,&zp);

Vec3 star(g_xyz[i][1], g_xyz[i][0],g_xyz[i][2]);

Vec3 pos(xp, yp, zp);

Vec3 dist;

dist=pos-star;

GLfloat rPos=sqrt(xp*xp+yp*yp+zp*zp);

GLfloat xr=FIELD_WIDTH,yr=FIELD_HEIGHT;


Vec3 a( g_xyz[i][0], g_xyz[i][1], g_xyz[i][2] );

GLfloat tmp;

if (camera.pointInFrustum(a) == CCamera::OUTSIDE)

//if star is outside of frustum then recalc to somewhere inside ? ...

{

lowest=camera.ftl.x; highest=camera.ftr.x;

if (lowest> highest){tmp=lowest;lowest=highest;highest=tmp; }

range=(highest-lowest)+1;

g_xyz[i][0] = -(lowest+int(range*rand()/(RAND_MAX + 1.0)));





lowest=camera.fbl.y; highest=camera.ftl.y;

if (lowest> highest){tmp=lowest;lowest=highest;highest=tmp; }

range=(highest-lowest)+1;

g_xyz[i][1] = -(lowest+int(range*rand()/(RAND_MAX + 1.0)));



lowest=camera.ntr.z; highest=camera.ftr.z;

if (lowest> highest){tmp=lowest;lowest=highest;highest=tmp; }

range=(highest-lowest)+1;

g_xyz[i][2] = lowest+int(range*rand()/(RAND_MAX + 1.0));

}


}

}
the project files are at
http://sf.srwlab.com/

Brolingstanz
02-26-2009, 05:11 AM
this isn't a coder forum. Please post coding questions down below in the developer section.

(If a point leaves the view frustum it'll be behind at least 1 frustum plane (signed dist to plane < 0). Simplify things a bit by just testing near/far planes which are just translates along the view direction. Otherwise either project the point for a test against the (unit) cube or transform your frustum into world/view space for a point test against the planes of the view pyramid. Heck simpler still you could just test the point against a sphere or an AABB of max radius centered on the view. Or better still, ...)

arctbl
02-26-2009, 02:05 PM
this isn't a coder forum. Please post coding questions down below in the developer section.

(If a point leaves the view frustum it'll be behind at least 1 frustum plane (signed dist to plane < 0). Simplify things a bit by just testing near/far planes which are just translates along the view direction. Otherwise either project the point for a test against the (unit) cube or transform your frustum into world/view space for a point test against the planes of the view pyramid. Heck simpler still you could just test the point against a sphere or an AABB of max radius centered on the view. Or better still, ...)



Hi
i have forward and back working pretty much. but it is turning that seems to be the problem. i was attempting a sphere when something went horribly wrong - my math isn't very good

I will try the developer forum
thanks