Advertisement

Great Idea For An App

Started by November 05, 2000 01:16 PM
9 comments, last by Bezzant 24 years ago
I like the scale idea, but it isn't as fast as inputing the coordinates yourself.

Hmm, maybe this could be easier then you think. You could specify the center of the object, and the size. So, say the object, a cube, is at 0,0,0, and the size is 1. We have to figure 8 points, so in our code you could have the following code:

#define TOPFRONTLEFT 0
#define TOPFRONTRIGHT 1
#define TOPBACKLEFT 2
#define TOPBACKRIGHT 3
// and so on, defining all corners

typedef struct
{
float x, y, z;
} vertex;

typedef struct
{
vertex corners[8];
} cube;

In order to specify each corner, the code would look like this:

int lr = 1; // left/right
int fb = 1; // front/back
int tb = 1; // top/bottom
vertex coord; // the coordinate of the object
float size; // the object size
int i = 0;
for(int x=0; x < 2; x++)
{
for(int y=0; y < 2; y++)
{
for(int z=0; z < 2; z++)
{
cube.corners.x = (lr)(coord+size);
cube.corners.y = (tb)(coord+size);<br> cube.corners.z = (fb)(coord+size);<br> fb = -fb; // set the front/back to its opposite<br> i++; // increment<br> }<br> tb = -tb; // set the top/bottom to its opposite<br> }<br>lr = -lr; // set the left/right to its opposite<br>}<br><br>Now you have a perfect cube! Is that automatic, or what? But don't stop here. Pyramids and more are just around the corner! Have fun<img src="wink.gif" width=15 height=15 align=middle><br><br> <br><br><br><br>Edited by - Rainmaker on November 6, 2000 10:42:28 PM </i>

This topic is closed to new replies.

Advertisement