Quake3World.com Forums
     Programming Discussion
        VectorToScreen tools for QuakeIII


Post new topicReply to topic
Login | Profile | | FAQ | Search | IRC




Print view Previous topic | Next topic 
Topic Starter Topic: VectorToScreen tools for QuakeIII

Gibblet
Gibblet
Joined: 10 Jun 2010
Posts: 17
PostPosted: 08-08-2010 05:53 PM           Profile Send private message  E-mail  Edit post Reply with quote


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:
//
//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:
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:
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




Top
                 

Gibblet
Gibblet
Joined: 10 Nov 2007
Posts: 13
PostPosted: 08-21-2010 01:28 PM           Profile Send private message  E-mail  Edit post Reply with quote


Really cool, thanks for sharing this! I'll probably get around to integrating this into my project at some point.




Top
                 
Quake3World.com | Forum Index | Programming Discussion


Post new topic Reply to topic


cron
Quake3World.com
© ZeniMax. Zenimax, QUAKE III ARENA, Id Software and associated trademarks are trademarks of the ZeniMax group of companies. All rights reserved.
This is an unofficial fan website without any affiliation with or endorsement by ZeniMax.
All views and opinions expressed are those of the author.