Advertisement

Need a little help from some demo coders.

Started by September 14, 2000 11:54 AM
5 comments, last by sinistrx 24 years, 2 months ago
And before anyone answers my first question yes I know I could go look through all the demo source on hornet.org, look back through my college precalc book, or use the graphing functions of my ti89 to figure this out, but does anyonehave anice quick and dirty referrence to some good sin/cos and x^2 curves for apps for objects to follow? (and this is the example if I had like 10 objects and wanted them to follow a repeated curve on the screen for those effects you used to see on old intros) And second does anyone have a handy referrence to implementing invisible animation paths into a scene? I know in 3dsmax all you have to do is create a spline/nurb/bezier and use the animation controls to have the object follow/bank on it but how would I implement that into an OGL scene?
If you are meaning moving a single (or bunch) of objects on a predetermined path around the screen, all you have to do is use your glTranslatef() or glTranslated() function to move it. Use a look to increment the variables in the translate function.
ie.

inside WinMain()

GLfloat y;

for (GLfloat x = 0; x < 5; x += 0.01)
{
y = x * x; // this is the line that makes the path a parabola
RenderScene(x, y);
}

and inside RenderScene(x, y)
Translatef(x, y, 0);
... draw object

This is about as quick and dirty as it gets to produce a path for an object in the shape of a half parabola starting at (0, 0, 0). If you want more path shapes then a parabola, then add them in after the loop in another loop.
Advertisement
Well yeah I know all that good stuff, what I was more specifically asking is if anyone had a handy referrence for some curves I could use for some nice effects like figure 8 patterns along the x,y,&z axis as well as some code so i could make my own quadrics with using the glu library functions so I could make my own deformations to them (and helixes too). I''m talking Calculus I in college this semester but we haven''t covered that section yet and the book has it all in vectors which is kind of hard for me to understand how I would implement that into a glVertex3f(x,y,z) (within some kind of loop) format. If you know or have any good referrences to that kind of stuff let me know I''ve been web searching the past few nights and to no avail, couldn''t even find anything of use to me in the Graphics Gems collections! Of course everytime I go to a gaming/3d site they try to use terminology like Bezier-patches and BSP trees and Quadrilopodiotopopopics ( (: ) which confuses the hell out of me.
To move something along a vector you use...

    // needed for sqrt() function#include <math.h>// your x, y, z for the glTranslatefGLfloat Translate[3];// your original vectorGLfloat vector[3] = (3, 1, 2); // x-coord, y-coord, z-coord// the unit vector in the direction of vector[3]GLfloat unitVector[3];// the magnitude of vector[3]GLfloat magnitude;// to calculate magnitude take the sqrt of the sum of the coords squaredmagnitude = sqrt((vector[0] * vector[0]) + (vector[1] * vector[1]) + (vector[2] * vector[2]));// assign the unitVector coords by dividing vector[3] by it''s magnitudefor (int count = 0; count < 3; count++)  unitVector[count] = vector[count] / magnitude;// assign the start values for the start point of the vector as x, y, zTranslate[0] = 0;Translate[1] = 0;Translate[2] = 0;// now increment x, y, z until they equal the desired vectordo{  for (count = 0; count < 3; count++)    Translate[count] += unitVector[count];  // move the object  glTranslatef(Translate[0], Translate[1], Translate[2]);}while(Translate != vector);    


There, that should do the trick.

S.
I don''t know exactly how to go about thanking you but I''ve been trying to figure that out for a week now! Thanks!
Liked your demo there... But you could''ve at least mentioned me in your shouts in the readme, don''t ya think?

S.
Advertisement
Sorry I made the readme at like 3 in the morning the other night, I''m working on a tetris gl game right now though (yeah I know everyone''s got their own) and I''ll give ya some shouts out.

This topic is closed to new replies.

Advertisement