Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Pipe



Several years ago when I was working on "Bugdom 2" I had to write a utility that did exactly this. It built a pipe and/or a half-pipe along a spline for two of the levels in the game where the player surfed the pipe. I didn't have to do anything particularly complicated to do this; at least no atan2() calls.

What I did was to build "spars" which were the rings of vertices that defined the outline of the tube along the spline. Then I would simply create a mesh from those spars. Below is the function I used to generate the spars from the spline points:

/*********************** GENERATE SPLINE SPARS **********************/
//
// Generates the spline cross-beam spars which are the base for the geometry
//


static void GenerateSplineSpars(void)
{
int		i,n;
float	a;
OGLPoint3D	refSpar[POINTS_PER_SPAR_FULLPIPE];
OGLVector3D	refNormals[POINTS_PER_SPAR_FULLPIPE];

/* GENERATE REFERENCE SPAR */
//
// just a set of points representing the "ring" of the spar
//

for (i = 0, a = -PI/2; i < gPointsPerSpar; a += (PI / (POINTS_PER_SPAR_HALFPIPE-1)), i++)
{
refSpar[i].x = -sin(a) * SPAR_DIAMATER;
refSpar[i].y = -cos(a) * SPAR_DIAMATER;
refSpar[i].z = 0;

refNormals[i].x = -refSpar[i].x; // calc normal
refNormals[i].y = -refSpar[i].y;
refNormals[i].z = -refSpar[i].z;
OGLVector3D_Normalize(&refNormals[i], &refNormals[i]);
}



/* CALC # OF SPARS TO GENERATE */


	gNumSplineSpars = gNumSplinePoints / SPAR_DENSITY;


/*******************/
/* BUILD THE SPARS */
/*******************/
//
// Calc a vector from spline pt 0 to spline p1, and then align
// the reference spar to that vector - that's our new spar!
//

for (i = n = 0; i < gNumSplineSpars; i++, n += SPAR_DENSITY)
{
OGLMatrix4x4 m;

SetLookAtMatrixAndTranslate(&m, &gSplinePoints[n].up, &gSplinePoints[n].point, &gSplinePoints[n+1].point);

OGLPoint3D_TransformArray(refSpar, &m, &gSparPoints[i][0], gPointsPerSpar);
OGLVector3D_TransformArray(refNormals, &m, &gSparNormals[i][0], gPointsPerSpar);
}
}



This code may not make much sense by itself, or maybe it does, but the jist of it is that I create a ring of points and then transform it to align with the spline. That is done at the bottom of the function by calculating a vector from spline point 0 to spline point 1 and then aligning the ring of points to that vector. Quite simply actually.


I'll be happy to sent you the entire project for this utility if you want, but it's an old CodeWarrior project.


-Brian


On May 24, 2007, at 6:42 AM, Lorenzo wrote:

I have to build a pipeline on a Bezier path. My profile is a circle.
For each point of the Bezier curve I have the tangent normalized vector.
I will draw the pipeline with GL_QUAD_STRIP.
So e.g. for each point "i" of the curve, to calculate the vertexes of one
circle (which can be rotated anyway on the 3 axes), I iterate from 0 to 360
degrees and get



__________________________________________________________ Brian Greenstone President & CEO email@hidden Pangea Software, Inc. http://www.pangeasoft.net 12405 John Simpson Ct. voice/fax: (512)266-9991 Austin, TX 78732 __________________________________________________________




_______________________________________________ Do not post admin requests to the list. They will be ignored. Mac-opengl mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/mac-opengl/email@hidden

This email sent to email@hidden
References: 
 >Pipe (From: Lorenzo <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.