Skip to content

Commit

Permalink
Made scale matrix
Browse files Browse the repository at this point in the history
  • Loading branch information
kthakore committed Nov 3, 2010
1 parent e586335 commit 1103500
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 6 deletions.
28 changes: 24 additions & 4 deletions matrix.c
Expand Up @@ -39,13 +39,13 @@ Matrix4x4MultiplyBy4x4( (GLdouble (*)[4])src, (GLdouble (*)[4])src2, (GLdouble (
}


GLdouble* mat_transform( vertex g)
GLdouble* mat_translate( vertex g)
{
GLdouble* t = (GLdouble*)malloc( sizeof(GLdouble) * 16 );

t[0] = 1; t[4] = 0; t[8] = 0; t[12] = g.x;
t[1] = 0; t[5] = 1; t[9] = 0; t[13] = g.x;
t[2] = 0; t[6] = 0; t[10] = 1; t[14] = g.x;
t[1] = 0; t[5] = 1; t[9] = 0; t[13] = g.y;
t[2] = 0; t[6] = 0; t[10] = 1; t[14] = g.z;
t[3] = 0; t[7] = 0; t[11] = 0; t[15] = 1;

return t;
Expand All @@ -59,9 +59,14 @@ GLdouble* mat_rotate( vertex g, GLdouble angle)

GLdouble* mat_scale( vertex g )
{
GLdouble* t = (GLdouble*)malloc( sizeof(GLdouble) * 16 );

t[0] = g.x; t[4] = 0; t[8] = 0; t[12] = 0;
t[1] = 0; t[5] = g.y; t[9] = 0; t[13] = 0;
t[2] = 0; t[6] = 0; t[10] = g.z; t[14] = 0;
t[3] = 0; t[7] = 0; t[11] = 0; t[15] = 1;

return NULL;
return t;
}

GLdouble* mat_combine( GLdouble* t, GLdouble* r, GLdouble* s)
Expand Down Expand Up @@ -141,3 +146,18 @@ GLdouble* get_clipping_space_transform( )


}


void mat_transform_vertex( vertex* out, GLdouble* m, vertex in)
{

GLdouble r_c[4];
glGetDoublev( GL_CURRENT_RASTER_POSITION, r_c );

GLdouble wc = r_c[3];

out->x = m[0]*in.x + m[4]*in.y + m[8]*in.z + m[12]*wc;
out->y = m[1]*in.x + m[5]*in.y + m[9]*in.z + m[13]*wc;
out->z = m[2]*in.x + m[6]*in.y + m[10]*in.z + m[14]*wc;

}
3 changes: 2 additions & 1 deletion matrix.h
@@ -1,10 +1,11 @@
#ifndef _SCENEGRAPH_
#define _SCENEGRAPH_

GLdouble* mat_transform( vertex g);
GLdouble* mat_translate( vertex g);
GLdouble* mat_rotate( vertex g, GLdouble angle);
GLdouble* mat_scale( vertex g );
GLdouble* mat_combine( GLdouble* t, GLdouble* r, GLdouble* s);
void mat_transform_vertex( vertex* out, GLdouble* m, vertex in);
bool mat_inv(const GLdouble m[16], GLdouble invOut[16]);

void convert16_4( GLdouble in[16], GLdouble out[4][4]);
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 1
#define FRUSTUM 10
#define DEBUG 1
#define MAX_POLYGONS 40

Expand Down

0 comments on commit 1103500

Please sign in to comment.