Page 1 of 1

VectorToScreen tools for QuakeIII

Posted: Mon Aug 09, 2010 1:53 am
by Hxrmn
Project 3D vectors to 2D screen space! :D

It took me a while to figure this stuff out, here's the code so you don't have to.
http://pastebin.com/CKkdDTfm

You'll want to put this code in your cg_local.h depending on what functions you want to use:

Code: Select all

//
//cg_project.c
//
void VectorToScreen(vec3_t vector, refdef_t def, vec3_t out, qboolean screenScale);
qboolean quickProject(vec3_t v, float *x, float *y);
void BoundingBoxPoints(vec3_t origin, vec3_t mins, vec3_t maxs, vec3_t nodes[8]);
void CompareMins(vec3_t pmins, vec3_t cmins, vec3_t out);
void CompareMaxs(vec3_t pmaxs, vec3_t cmaxs, vec3_t out);
void RotateFoxAxis(vec3_t v, vec3_t axis[3]);
qboolean ProjectBounds( vec3_t mins, vec3_t maxs, vec3_t origin, float *xv, float *yv);
qboolean ProjectRotatedBounds( vec3_t mins, vec3_t maxs, vec3_t axis[3], float *xv, float *yv, vec3_t origin );
Here's how you use it:

Code: Select all

VectorToScreen(vec3_t vector, refdef_t refdef, vec3_t out, qboolean screenScale);
//if screenScale is true the size of the refdef will be converted from the renderer screen size.
Alternatively you can use:

Code: Select all

qboolean quickProject(vec3_t v, float *x, float *y);
//The refdef is cg.refdef and it returns true if the point is visible on the screen.
//Pass in a float pointer for *x and *y
This code also includes some other useful functions:

BoundingBoxPoints fills out nodes[8] with the 8 vectors that make up the box.
ProjectBounds and ProjectRotatedBounds out *xv, *yv with the 8 projected values that make up the box.
Pass in an 8 float array for *xv, *yv

So have fun and make some cool stuff.
Image

Re: VectorToScreen tools for QuakeIII

Posted: Sat Aug 21, 2010 9:28 pm
by JPL
Really cool, thanks for sharing this! I'll probably get around to integrating this into my project at some point.