Mail Archives: djgpp/1997/07/12/17:02:10
I am realively new to Allegro, as well as 3D graphics, and I am trying
to write a program that does 3d graphics, and I don't seem to get the right
results. I call persp_project() and it returns numbers that seem way off the
wall, or is it that I am not using RHIDE correctly?.
Here is the code:
//Excuse me if this isn't the best looking code in the world.
//#include <conio.h>
#include <stdio.h>
#include "allegro.h"
//****************************
//structure that we might need
//****************************
//this one is a list of points
struct vertex_type
{
fix lx, //local X
ly, //y
lz, //z
wx, //world x, for after the transformations
wy, // y
wz, // z
sx, // x //screen X and Y coordinates
sy; // y
};
//******************************************************
//this one describes each face as indexes to vertex_type
//******************************************************
struct quad_type
{
int v1,v2,v3,v4;
};
//*************************
//info about each data type
//*************************
class object_type
{
private:
public:
fix x,y,z; //location
fix rx,ry,rz; //the angles for x,y,z axis
fix d_x,d_y,d_z; //where it is heading/how fast
fix d_rx,d_ry,d_rz; //rotation speed, and direction
int num_vertices; //we need the number of sides
int num_faces;
vertex_type *coords; //pointer to the point defs
quad_type *quads; //pointer to the quad defs
object_type(quad_type *quads1,vertex_type *coords1,int num_sides,int
num_points):
quads(quads1),
coords(coords1),
num_vertices(num_points),
num_faces(num_sides),
d_x(0),d_y(0),d_z(0),
d_rx(0),d_ry(0),d_rz(0),
rx(0),ry(0),rz(0){x=160;y=100;z=50;}
void transform();
void draw(); //I'm not sure if this works, as I have
not been able to test it.
};
vertex_type points[] = /* a cube, centered on the origin */
{
/* vertices of the cube */
{ -32, -32,-32,
0,0,0,
0,0},
{ -32,32,-32,
0,0,0,
0,0},
{ 32,32,-32,
0,0,0,
0,0},
{ 32, -32,-32,
0,0,0,
0,0},
{ -32,-32,32,
0,0,0,
0,0},
{ -32,32,32,
0,0,0,
0,0},
{ 32,32,32,
0,0,0,
0,0},
{ 32,-32,32,
0,0,0,
0,0},
};
quad_type faces[] = /* group the vertices into polygons */
{
{ 0, 3, 2, 1 },
{ 4, 5, 6, 7 },
{ 0, 1, 5, 4 },
{ 2, 3, 7, 6 },
{ 0, 4, 7, 3 },
{ 1, 2, 6, 5 }
};
//**********
//prototypes
//**********
void main (void);
//===============================================================================
==========
void main (void)
{
object_type cube (faces,points,6,8);
allegro_init();
//set my graphics mode
if (set_gfx_mode (GFX_VGA, 320, 200, 0, 0) != 0)
{
printf ("error setting VGA 320x200x256\n");
exit (1);
}
//if we make it this far, we are in graphics mode do what we want from here
set_projection_viewport (0,0,320,200);
cube.transform();
// cube.draw();
}
//*******************************************************************************
**
void object_type::transform()
{
MATRIX matrix;
get_transformation_matrix (&matrix,(fix) 1,rx,ry,rz,x,y,z);
vertex_type *c = coords;
for (int i=0;i<num_vertices;i++,c++)
{
apply_matrix (&matrix,c->lx,c->ly,c->lz,
&c->wx,&c->wy,&c->wz);
persp_project (c->wx,c->wy,c->wz,
&c->sx,&c->sy); //these are the
two varibles that don't seem right
}
}
//*******************************************************************************
**
void object_type::draw()
{
//simple wireframe for now, until understand more
for (int i=0;i<num_faces;i++)
{
line (screen,(int)
coords[quads[i].v1].sx,(int)coords[quads[i].v1].sy,(int)coords[quads[i].v2].sx,(i
nt)coords[quads[i].v1].sy,2);
line
(screen,(int)coords[quads[i].v2].sx,(int)coords[quads[i].v2].sy,(int)coords[quads
[i].v3].sx,(int)coords[quads[i].v1].sy,2);
line
(screen,(int)coords[quads[i].v3].sx,(int)coords[quads[i].v3].sy,(int)coords[quads
[i].v4].sx,(int)coords[quads[i].v4].sy,2);
line
(screen,(int)coords[quads[i].v1].sx,(int)coords[quads[i].v1].sy,(int)coords[quads
[i].v4].sx,(int)coords[quads[i].v4].sy,2);
}
}
//*******************************************************************************
**
Thanks in advance.
Joe Davidson
<100661 DOT 1576 AT compuserve DOT com>
- Raw text -