# mysterio123

Member

7

102 Neutral

• Rank
Newbie
1. ## bounding sphere collision detection problem

distance i got was 0.25. its correct right?
2. ## bounding sphere collision detection problem

could it be because there are some spheres that are on the negative axis? EDIT: No it wasn't. im very stuck on this. EDIT NO.2: the collision only works when the other sphere are on the 0 axis. Im having a huge headache trying to solve this major bug before i can proceed
3. ## bounding sphere collision detection problem

moving too fast. that explains it too. ill give the code a try and see what happens! [/quote] okay ive tried it but its still not working! same bug i had with the previous code!! anyway isnt minDist supposed to be minDist = radius1 + radius2?
4. ## bounding sphere collision detection problem

moving too fast. that explains it too. ill give the code a try and see what happens!

6. ## need help changing particle engine code to disperse dust

<br><pre><font face="Arial">#include "freeglut.h" #include "myengine.h" bool full_screen; struct CVector { public : CVector() : x( 0.0f ), y( 0.0f ), z( 0.0f ) {} CVector( float x, float y, float z ) : x( x ), y( y ), z( z ) {} float Magnitude() { return sqrt( x*x + y*y + z*z ); } CVector Normalize() { float m = Magnitude(); return CVector( x/m, y/m, z/m); } CVector operator +(CVector v) { return CVector ( x + v.x, y + v.y, z + v.z ); } CVector operator -( CVector v) { return CVector ( x -v.x, y -v.y, z -v.z ); } void operator += ( CVector v) { x=v.x+x; y=v.y+y; z=v.z+z; } CVector operator * ( float scale ) { return CVector( x * scale, y * scale, z * scale );} CVector operator ^ ( CVector v ) { return CVector( y * v.z -z * v.y, -x * v.z -z * v.x, x * v.y -y * v.x ); } float x, y, z; }; const int MAX_PARTICLE = 150; struct Particle{ Particle(){ life = 1.0f; } CVector pos,vel; float r,g,b; float life; }; Particle ps[MAX_PARTICLE]; void RenderScene() { glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); glClearDepth( 1.0 ); glDisable( GL_DEPTH_TEST ); glDepthFunc( GL_LESS ); glMatrixMode ( GL_MODELVIEW ); glLoadIdentity(); glEnable( GL_TEXTURE_2D ); glBlendFunc( GL_SRC_ALPHA, GL_ONE ); glEnable( GL_BLEND ); for ( int i = 0; i &lt; MAX_PARTICLE; i++ ) { ps.pos += ps.vel; ps.life -= 0.005f; if ( ps.life &lt; 0.0f) ps.life = 0.0f; if ( ps.life &gt; 0.0f ) { glPushMatrix(); glTranslatef( ps.pos.x, ps.pos.y-20, -80.0f); glColor4f( ps.r, ps.g, ps.b, ps.life); glBegin(GL_QUADS); glTexCoord2f( 0.0f, 0.0f ); glVertex3f( -1.0f, -1.0f, 1.0f ); glTexCoord2f( 1.0f, 0.0f ); glVertex3f( 1.0f, -1.0f, 1.0f ); glTexCoord2f( 1.0f, 1.0f ); glVertex3f( 1.0f, 1.0f, 1.0f ); glTexCoord2f( 0.0f, 1.0f ); glVertex3f( -1.0f, 1.0f, 1.0f); glEnd(); glPopMatrix(); } } glDisable(GL_BLEND); glDisable( GL_TEXTURE_2D ); glutSwapBuffers(); } void Resize( int width, int height ) { glViewport ( 0, 0, width, height ); glMatrixMode ( GL_PROJECTION ); glLoadIdentity(); gluPerspective( 45, (float)(width)/(float)(height), 0.1f, 1000 ); glMatrixMode ( GL_MODELVIEW ); glLoadIdentity (); } void SpecialKeys( int key, int x, int y ) { switch ( key ) { case GLUT_KEY_F1 : for ( int i = 0;i &lt; MAX_PARTICLE; i++ ) { float x = (((float) rand()/RAND_MAX)-0.5f)/15; float y = ((float) rand()/RAND_MAX)/2; float z = ((float) rand()/RAND_MAX)/15; ps.vel = CVector(x,y,z); x = (((float) rand()/RAND_MAX)-0.5f)/2; y = (((float) rand()/RAND_MAX)-0.5f)/2; z = (((float) rand()/RAND_MAX)-0.5f)/2; ps.pos = CVector(x,y,z); ps.life = 1.0f; } break ; } glutPostRedisplay(); } void InitApp(){ full_screen = false; srand((unsigned)time( NULL ) ); for ( int i = 0; i &lt; MAX_PARTICLE; i++ ) { float x = (((float) rand()/RAND_MAX)-0.5f)/15; float y = ((float) rand()/RAND_MAX)/2; float z = ((float) rand()/RAND_MAX)/15; ps.vel = CVector(x,y,z); x = ((float) rand()/RAND_MAX -0.5f)/2; y = ((float) rand()/RAND_MAX -0.5f)/2; z = ((float) rand()/RAND_MAX -0.5f)/2; ps.pos = CVector(x,y,z); ps.life = 1.0f; x = ((float) rand()/RAND_MAX); y = ((float) rand()/RAND_MAX); z = ((float) rand()/RAND_MAX); ps.r = x; ps.g = y; ps.b = z; } } void InitGL() { glClearColor( 0.0f, 0.0f, 0.0f, 0.0f ); glShadeModel( GL_SMOOTH ); glHint( GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST ); LoadTGA( &amp;textures[ 0 ], "images/particle1.tga",false ); } int main( int argc, char *argv[] ) { glutInit( &amp;argc, argv ); InitApp(); glutInitDisplayMode( GLUT_RGBA | GLUT_DOUBLE | GLUT_DEPTH ); glutInitWindowSize( 800, 600 ); if (full_screen) { glutGameModeString("800x600:16@60"); glutEnterGameMode(); } else glutCreateWindow( "Framework" ); InitGL(); glutIdleFunc( RenderScene ); glutReshapeFunc( Resize ); glutDisplayFunc( RenderScene ); glutSpecialFunc( SpecialKeys ); glutMainLoop(); return 0;</font> </pre>[/quote]<br><br>i havent tried anything as i do not know how to change the gravity, etc.
7. ## need help changing particle engine code to disperse dust

ok i am having some trouble modifying this code to make the particles engine make dust. #include "freeglut.h" #include "myengine.h" bool full_screen; struct CVector { public : CVector() : x( 0.0f ), y( 0.0f ), z( 0.0f ) {} CVector( float x, float y, float z ) : x( x ), y( y ), z( z ) {} float Magnitude() { return sqrt( x*x + y*y + z*z ); } CVector Normalize() { float m = Magnitude(); return CVector( x/m, y/m, z/m); } CVector operator +(CVector v) { return CVector ( x + v.x, y + v.y, z + v.z ); } CVector operator -( CVector v) { return CVector ( x -v.x, y -v.y, z -v.z ); } void operator += ( CVector v) { x=v.x+x; y=v.y+y; z=v.z+z; } CVector operator * ( float scale ) { return CVector( x * scale, y * scale, z * scale );} CVector operator ^ ( CVector v ) { return CVector( y * v.z -z * v.y, -x * v.z -z * v.x, x * v.y -y * v.x ); } float x, y, z; }; const int MAX_PARTICLE = 150; struct Particle{ Particle(){ life = 1.0f; } CVector pos,vel; float r,g,b; float life; }; Particle ps[MAX_PARTICLE]; void RenderScene() { glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); glClearDepth( 1.0 ); glDisable( GL_DEPTH_TEST ); glDepthFunc( GL_LESS ); glMatrixMode ( GL_MODELVIEW ); glLoadIdentity(); glEnable( GL_TEXTURE_2D ); glBlendFunc( GL_SRC_ALPHA, GL_ONE ); glEnable( GL_BLEND ); for ( int i = 0; i < MAX_PARTICLE; i++ ) { ps.pos += ps.vel; ps.life -= 0.005f; if ( ps.life < 0.0f) ps.life = 0.0f; if ( ps.life > 0.0f ) { glPushMatrix(); glTranslatef( ps.pos.x, ps.pos.y-20, -80.0f); glColor4f( ps.r, ps.g, ps.b, ps.life); glBegin(GL_QUADS); glTexCoord2f( 0.0f, 0.0f ); glVertex3f( -1.0f, -1.0f, 1.0f ); glTexCoord2f( 1.0f, 0.0f ); glVertex3f( 1.0f, -1.0f, 1.0f ); glTexCoord2f( 1.0f, 1.0f ); glVertex3f( 1.0f, 1.0f, 1.0f ); glTexCoord2f( 0.0f, 1.0f ); glVertex3f( -1.0f, 1.0f, 1.0f); glEnd(); glPopMatrix(); } } glDisable(GL_BLEND); glDisable( GL_TEXTURE_2D ); glutSwapBuffers(); } void Resize( int width, int height ) { glViewport ( 0, 0, width, height ); glMatrixMode ( GL_PROJECTION ); glLoadIdentity(); gluPerspective( 45, (float)(width)/(float)(height), 0.1f, 1000 ); glMatrixMode ( GL_MODELVIEW ); glLoadIdentity (); } void SpecialKeys( int key, int x, int y ) { switch ( key ) { case GLUT_KEY_F1 : for ( int i = 0;i < MAX_PARTICLE; i++ ) { float x = (((float) rand()/RAND_MAX)-0.5f)/15; float y = ((float) rand()/RAND_MAX)/2; float z = ((float) rand()/RAND_MAX)/15; ps.vel = CVector(x,y,z); x = (((float) rand()/RAND_MAX)-0.5f)/2; y = (((float) rand()/RAND_MAX)-0.5f)/2; z = (((float) rand()/RAND_MAX)-0.5f)/2; ps.pos = CVector(x,y,z); ps.life = 1.0f; } break ; } glutPostRedisplay(); } void InitApp(){ full_screen = false; srand((unsigned)time( NULL ) ); for ( int i = 0; i < MAX_PARTICLE; i++ ) { float x = (((float) rand()/RAND_MAX)-0.5f)/15; float y = ((float) rand()/RAND_MAX)/2; float z = ((float) rand()/RAND_MAX)/15; ps.vel = CVector(x,y,z); x = ((float) rand()/RAND_MAX -0.5f)/2; y = ((float) rand()/RAND_MAX -0.5f)/2; z = ((float) rand()/RAND_MAX -0.5f)/2; ps.pos = CVector(x,y,z); ps.life = 1.0f; x = ((float) rand()/RAND_MAX); y = ((float) rand()/RAND_MAX); z = ((float) rand()/RAND_MAX); ps.r = x; ps.g = y; ps.b = z; } } void InitGL() { glClearColor( 0.0f, 0.0f, 0.0f, 0.0f ); glShadeModel( GL_SMOOTH ); glHint( GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST ); LoadTGA( &textures[ 0 ], "images/particle1.tga",false ); } int main( int argc, char *argv[] ) { glutInit( &argc, argv ); InitApp(); glutInitDisplayMode( GLUT_RGBA | GLUT_DOUBLE | GLUT_DEPTH ); glutInitWindowSize( 800, 600 ); if (full_screen) { glutGameModeString("800x600:16@60"); glutEnterGameMode(); } else glutCreateWindow( "Framework" ); InitGL(); glutIdleFunc( RenderScene ); glutReshapeFunc( Resize ); glutDisplayFunc( RenderScene ); glutSpecialFunc( SpecialKeys ); glutMainLoop(); return 0; } myengine.h is just my image loader.