Skip to content

Commit

Permalink
Workign really well now
Browse files Browse the repository at this point in the history
  • Loading branch information
kthakore committed Nov 3, 2010
1 parent e0385ca commit 448fb91
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 95 deletions.
4 changes: 2 additions & 2 deletions main.cc
Expand Up @@ -85,8 +85,8 @@ void make_obj(int argc, char **argv)
obj_scale( second, 0.5, 0.5, 0.5 );
obj_scale( third, 0.5, 0.5, 0.5 );

obj_translate( first, 0, 0, 0 );
obj_translate( second, 0.5, 0.5, 0);
obj_translate( first, -1, 0, 0 );
obj_translate( second, 1, -2, 0);
obj_translate( third, -1, -2, 0);
// obj_translate( fourth, 0.1, 0.2, 0 );

Expand Down
25 changes: 9 additions & 16 deletions object.c
Expand Up @@ -183,35 +183,25 @@ void obj_render( object* obj)
vertex bb_plus_p_loc;
//add_vertex(& bb_plus_p_loc, obj->location, obj->bound_sphere_loc );
copy_vertex( &bb_plus_p_loc, &obj->location);
GLdouble* out_r = modelview_inv_get( );

glPushMatrix();
vertex displace;
add_vertex( &displace, obj->r_location, obj->bound_sphere_loc );
//GET INITIAL MATRIX
GLdouble* out_r = modelview_inv_get( );
fprintf( stderr, "asdsadasdasd %f \n", out_r[0]);
//COMPUTE INVERSE
//COMPUTE INVERSE

debug_vertex( obj->r_location, "ONLY NORMAL" );

glTranslate_vertex( obj->r_location);
/*
debug_vertex( obj->r_location, "ONLY TRANSLATE" );
glRotate_vertex( obj->r_location, obj->r_rotation, obj->is_root);

debug_vertex( obj->r_location, "ONLY ROTATION" );
glScalef( obj->scale.x, obj->scale.y, obj->scale.z );
// glRotate_vertex( obj->r_location, obj->r_rotation, obj->is_root);
// glScalef( obj->scale.x, obj->scale.y, obj->scale.z );
//GET FINAL MATRIX

// INV_IN_MAT * FIN_MATRIX * [ x, y, z, 1] = [ b_x, b_y, b_z, 1]
debug_vertex( obj->r_location, "ONLY SCALE" );
*/


// Get the local modelview matrix of this object and multiply
modelview_multiply( &obj->model_proj_bb, &out_r, bb_plus_p_loc);



if( DEBUG )
Expand All @@ -230,6 +220,9 @@ void obj_render( object* obj)

glEnd();
glPopMatrix();
modelview_multiply( &obj->model_proj_bb, &out_r, displace);


}
}

Expand Down
2 changes: 1 addition & 1 deletion scenegraph.h
Expand Up @@ -10,7 +10,7 @@
#include <GL/glu.h>
#include <GL/glut.h>

#define FRUSTUM 0
#define FRUSTUM 1
#define DEBUG 1
#define MAX_POLYGONS 40

Expand Down
101 changes: 25 additions & 76 deletions vertex.c
Expand Up @@ -77,29 +77,23 @@ void glTranslate_vertex( vertex a )
void glRotate_vertex( vertex r_loc, vertex r_rot, int root)
{

/*

if( root == 0 )
{
divide_vertex( &r_loc, -1 );
glTranslate_vertex( r_loc );
}
*/

glRotated( r_rot.x, 1, 0, 0 );
glRotated( r_rot.y, 0, 1, 0 );
glRotated( r_rot.z, 0, 0, 1 );
/*

if( root == 0 )
{
divide_vertex( &r_loc, -1 );
glTranslate_vertex( r_loc );
}

*/
// if(root == 0 )
//glTranslate_vertex( p_loc );


}


Expand Down Expand Up @@ -201,46 +195,6 @@ bool gluInvertMatrix(const GLdouble m[16], GLdouble invOut[16])



GLdouble* modelview_inv_get( )
{

GLdouble m[16];
glGetDoublev( GL_MODELVIEW_MATRIX, m );

///Take m and send to MatrixInversion

float **in;
in = new float*[16];
int i;
for(i=0;i<16;i++)
in[i] = new float[16];

in[0][1] = m[0]; in[0][1] = m[4]; in[0][2] = m[8]; in[0][4] = m[12];
in[1][1] = m[1]; in[1][1] = m[5]; in[1][2] = m[9]; in[1][4] = m[13];
in[2][1] = m[2]; in[2][1] = m[6]; in[2][2] = m[10]; in[2][4] = m[14];
in[3][1] = m[3]; in[3][1] = m[7]; in[3][2] = m[11]; in[3][4] = m[15];

float **Y;
Y = new float*[16];
for(i=0;i<16;i++)
Y[i] = new float[16];

MatrixInversion( (float **)in , 4, (float** )Y );


GLdouble* out = (GLdouble*)malloc( sizeof( GLdouble) * 16 );

out[0] = Y[0][1]; out[4] = Y[0][2]; out[8] = Y[0][3]; out[12] = Y[0][4];
out[1] = Y[1][1]; out[5] = Y[1][2]; out[9] = Y[1][3]; out[13] = Y[1][4];
out[2] = Y[2][1]; out[6] = Y[2][2]; out[10] = Y[2][3]; out[14] = Y[2][4];
out[3] = Y[3][1]; out[7] = Y[3][2]; out[11] = Y[3][3]; out[15] = Y[3][4];

fprintf(stderr, "ASDSD %f %f \n", Y[0][1], out[0]);

return out;
}


static inline void Matrix4x4MultiplyBy4x4 (GLdouble src1[4][4], GLdouble src2[4][4], GLdouble dest[4][4])
{
dest[0][0] = src1[0][0] * src2[0][0] + src1[0][1] * src2[1][0] + src1[0][2] * src2[2][0] + src1[0][3] * src2[3][0];
Expand Down Expand Up @@ -271,6 +225,27 @@ static inline void convert16_4( GLdouble in[16], GLdouble out[4][4])
};




GLdouble* modelview_inv_get( )
{

double m[16];
glGetDoublev( GL_MODELVIEW_MATRIX, m );

///Take m and send to MatrixInversion
GLdouble* out = (GLdouble*)malloc( sizeof( GLdouble) * 16 );
if( gluInvertMatrix( m, out) )
{
fprintf(stderr, "bah m %f, %f \n", m[5],out[5]);

}

return out;
}



GLdouble modelview_multiply( vertex* s, GLdouble** inv, vertex t)
{

Expand All @@ -279,15 +254,9 @@ GLdouble modelview_multiply( vertex* s, GLdouble** inv, vertex t)
GLdouble m[16];
glGetDoublev( GL_MODELVIEW_MATRIX, m );
GLdouble a = 0;
GLdouble b,c,d;

GLdouble m_[4][4];
GLdouble inv_[4][4];
convert16_4( m, m_ );


GLdouble ins[4][4];

convert16_4( *inv, inv_ );

GLdouble out[4][4];
Expand All @@ -297,26 +266,6 @@ GLdouble modelview_multiply( vertex* s, GLdouble** inv, vertex t)
s->y = out[1][0]*t.x + out[1][1]*t.y + out[1][2]*t.z + out[1][3]*a;
s->z = out[2][0]*t.x + out[2][1]*t.y + out[2][2]*t.z + out[2][3]*a;
//c = out[0][0]*t.x + out[0][1]*t.y + out[0][2]*t.z + out[0][3]*a;
return c;

/*
GLdouble x,y,z,zdepth;
GLdouble projection[16];
GLdouble modelview[16];
GLint viewport[4];
glGetDoublev(GL_PROJECTION_MATRIX , projection);
glGetDoublev (GL_MODELVIEW_MATRIX , modelview);
glGetIntegerv (GL_VIEWPORT ,viewport);
//gluProject(GLdouble, GLdouble, GLdouble, const GLdouble*, const GLdouble*, const GLint*, GLdouble*, GLdouble*, GLdouble*)
gluUnProject( t.x, t.y, t.z ,modelview,projection,viewport , &x, &y , &z);
s->x = x;
s->y = y;
s->z = z;
debug_vertex( t, "IN:" );
debug_vertex_p( s, "OUT:");
return 1.0;
*/
return 0.0;
}

0 comments on commit 448fb91

Please sign in to comment.