示例#1
0
void glopOrtho(GLContext *c,GLParam *p)
{
  float *r;
  M4 m;
  float left=p[1].f;
  float right=p[2].f;
  float bottom=p[3].f;
  float top=p[4].f;
  float near=p[5].f;
  float far=p[6].f;
  float x,y,A,B,C,D;

  x = 2.0 / (right-left);
  y = 2.0 / (top-bottom);
  A = -(right+left) / (right-left);
  B = -(top+bottom) / (top-bottom);
  C = -2.0 / (far-near);
  D = -(far+near) / (far-near);

  r=&m.m[0][0];
  r[0]  = x; r[1]  = 0; r[2]  = 0; r[3]  = A;
  r[4]  = 0; r[5]  = y; r[6]  = 0; r[7]  = B;
  r[8]  = 0; r[9]  = 0; r[10] = C; r[11] = D;
  r[12] = 0; r[13] = 0; r[14] = 0; r[15] = 1;

  gl_M4_MulLeft(c->matrix_stack_ptr[c->matrix_mode],&m);

  gl_matrix_update(c);
}
示例#2
0
文件: matrix.c 项目: plzombie/ne
void glopFrustum(GLContext *c,GLParam *p)
{
  float *r;
  M4 m;
  float left=p[1].f;
  float right=p[2].f;
  float bottom=p[3].f;
  float top=p[4].f;
  float n_e_a_r=p[5].f;
  float farp=p[6].f;
  float x,y,A,B,C,D;

  x = (2.0f*n_e_a_r) / (right-left);
  y = (2.0f*n_e_a_r) / (top-bottom);
  A = (right+left) / (right-left);
  B = (top+bottom) / (top-bottom);
  C = -(farp+n_e_a_r) / ( farp-n_e_a_r);
  D = -(2.0f*farp*n_e_a_r) / (farp-n_e_a_r);

  r=&m.m[0][0];
  r[0]= x; r[1]=0; r[2]=A; r[3]=0;
  r[4]= 0; r[5]=y; r[6]=B; r[7]=0;
  r[8]= 0; r[9]=0; r[10]=C; r[11]=D;
  r[12]= 0; r[13]=0; r[14]=-1; r[15]=0;

  gl_M4_MulLeft(c->matrix_stack_ptr[c->matrix_mode],&m);

  gl_matrix_update(c);
}
示例#3
0
void glopFrustum(GLContext *c,GLParam *p)
{
  GLfloat *r;
  M4 m;
  GLfloat left=p[1].f;
  GLfloat right=p[2].f;
  GLfloat bottom=p[3].f;
  GLfloat top=p[4].f;
  GLfloat near=p[5].f;
  GLfloat farp=p[6].f;
  GLfloat x,y,A,B,C,D,tmp2=int2sll(2);

  x = slldiv(sllmul(tmp2,near), sllsub(right,left));
  y = slldiv(sllmul(tmp2,near), sllsub(top,bottom));
  A = slldiv(slladd(right,left), sllsub(right,left));
  B = slldiv(slladd(top,bottom), sllsub(top,bottom));
  C = slldiv(sllneg(slladd(farp,near)), sllsub(farp,near));
  D = slldiv(sllneg(sllmul(sllmul(tmp2,farp),near)), sllsub(farp,near));

  r=&m.m[0][0];
  r[0]= x; r[1]=int2sll(0);  r[2]=A;            r[3]=int2sll(0);
  r[4]= int2sll(0); r[5]=y;  r[6]=B;            r[7]=int2sll(0);
  r[8]= int2sll(0); r[9]=int2sll(0);  r[10]=C;           r[11]=D;
  r[12]=int2sll(0); r[13]=int2sll(0); r[14]=int2sll(-1); r[15]=int2sll(0);

  gl_M4_MulLeft(c->matrix_stack_ptr[c->matrix_mode],&m);

  gl_matrix_update(c);
}
示例#4
0
void glopMultMatrix(GLContext *c, GLParam *p) {
	M4 m;
	int i;

	GLParam *q;
	q = p + 1;

	for (i = 0; i < 4; i++) {
		m.m[0][i] = q[0].f;
		m.m[1][i] = q[1].f;
		m.m[2][i] = q[2].f;
		m.m[3][i] = q[3].f;
		q += 4;
	}

	gl_M4_MulLeft(c->matrix_stack_ptr[c->matrix_mode], &m);

	gl_matrix_update(c);
}
示例#5
0
void glopRotate(GLContext *c,GLParam *p)
{
  M4 m;
  float u[3];
  float angle;
  int dir_code;

  angle = p[1].f * M_PI / 180.0;
  u[0]=p[2].f;
  u[1]=p[3].f;
  u[2]=p[4].f;

  /* simple case detection */
  dir_code = ((u[0] != 0)<<2) | ((u[1] != 0)<<1) | (u[2] != 0);

  switch(dir_code) {
  case 0:
    gl_M4_Id(&m);
    break;
  case 4:
    if (u[0] < 0) angle=-angle;
    gl_M4_Rotate(&m,angle,0);
    break;
  case 2:
    if (u[1] < 0) angle=-angle;
    gl_M4_Rotate(&m,angle,1);
    break;
  case 1:
    if (u[2] < 0) angle=-angle;
    gl_M4_Rotate(&m,angle,2);
    break;
  default:
    {
      float cost, sint;

      /* normalize vector */
      float len = u[0]*u[0]+u[1]*u[1]+u[2]*u[2];
      if (len == 0.0f) return;
      len = 1.0f / sqrt(len);
      u[0] *= len;
      u[1] *= len;
      u[2] *= len;

      /* store cos and sin values */
      cost=cos(angle);
      sint=sin(angle);

      /* fill in the values */
      m.m[3][0]=m.m[3][1]=m.m[3][2]=
        m.m[0][3]=m.m[1][3]=m.m[2][3]=0.0f;
      m.m[3][3]=1.0f;

      /* do the math */
      m.m[0][0]=u[0]*u[0]+cost*(1-u[0]*u[0]);
      m.m[1][0]=u[0]*u[1]*(1-cost)-u[2]*sint;
      m.m[2][0]=u[2]*u[0]*(1-cost)+u[1]*sint;
      m.m[0][1]=u[0]*u[1]*(1-cost)+u[2]*sint;
      m.m[1][1]=u[1]*u[1]+cost*(1-u[1]*u[1]);
      m.m[2][1]=u[1]*u[2]*(1-cost)-u[0]*sint;
      m.m[0][2]=u[2]*u[0]*(1-cost)-u[1]*sint;
      m.m[1][2]=u[1]*u[2]*(1-cost)+u[0]*sint;
      m.m[2][2]=u[2]*u[2]+cost*(1-u[2]*u[2]);
    }
  }

  gl_M4_MulLeft(c->matrix_stack_ptr[c->matrix_mode],&m);

  gl_matrix_update(c);
}
示例#6
0
void glopRotate(GLContext *c,GLParam *p)
{
#define SLL_M_PI dbl2sll(M_PI)
  M4 m;
  GLfloat u[3];
  GLfloat angle;
  int dir_code;

  angle = slldiv(sllmul(p[1].f, SLL_M_PI), int2sll(180));
  u[0]=p[2].f;
  u[1]=p[3].f;
  u[2]=p[4].f;

  /* simple case detection */
  dir_code = ((sllvalue(u[0]) != sllvalue(int2sll(0)))<<2) | ((sllvalue(u[1]) != sllvalue(int2sll(0)))<<1) | (sllvalue(u[2]) != sllvalue(int2sll(0)));

  switch(dir_code) {
  case 0:
    gl_M4_Id(&m);
    break;
  case 4:
    if (sllvalue(u[0]) < sllvalue(int2sll(0))) angle=sllneg(angle);
    gl_M4_Rotate(&m,angle,0);
    break;
  case 2:
    if (sllvalue(u[1]) < sllvalue(int2sll(0))) angle=sllneg(angle);
    gl_M4_Rotate(&m,angle,1);
    break;
  case 1:
    if (sllvalue(u[2]) < sllvalue(int2sll(0))) angle=sllneg(angle);
    gl_M4_Rotate(&m,angle,2);
    break;
  default:
    {
      GLfloat cost, sint;

      /* normalize vector */
      GLfloat len = slladd(
		      slladd(
			      sllmul(u[0],u[0]),
			      sllmul(u[1],u[1])
			),
		     sllmul(u[2],u[2]));
      if (sllvalue(len) == sllvalue(int2sll(0))) return;
      len = slldiv(int2sll(1), sllsqrt(len));
      u[0] = sllmul(u[0], len);
      u[1] = sllmul(u[1], len);
      u[2] = sllmul(u[2], len);

      /* store cos and sin values */
      cost=sllcos(angle);
      sint=sllsin(angle);

      /* fill in the values */
      m.m[3][0]=m.m[3][1]=m.m[3][2]=
        m.m[0][3]=m.m[1][3]=m.m[2][3]=int2sll(0);
      m.m[3][3]=int2sll(1);

      /* do the math */
      m.m[0][0]=slladd(sllmul(u[0],u[0]), sllmul(cost, sllsub(int2sll(1), sllmul(u[0],u[0]))));
      m.m[1][0]=sllsub(sllmul(sllmul(u[0],u[1]), sllsub(int2sll(1), cost)), sllmul(u[2],sint));
      m.m[2][0]=slladd(sllmul(sllmul(u[2],u[0]), sllsub(int2sll(1), cost)), sllmul(u[1],sint));
      m.m[0][1]=slladd(sllmul(sllmul(u[0],u[1]), sllsub(int2sll(1), cost)), sllmul(u[2],sint));
      m.m[1][1]=slladd(sllmul(u[1],u[1]), sllmul(cost, sllsub(int2sll(1), sllmul(u[1],u[1]))));
      m.m[2][1]=sllsub(sllmul(sllmul(u[1],u[2]), sllsub(int2sll(1), cost)), sllmul(u[0],sint));
      m.m[0][2]=sllsub(sllmul(sllmul(u[2],u[0]), sllsub(int2sll(1), cost)), sllmul(u[1],sint));
      m.m[1][2]=slladd(sllmul(sllmul(u[1],u[2]), sllsub(int2sll(1), cost)), sllmul(u[0],sint));
      m.m[2][2]=slladd(sllmul(u[2],u[2]), sllmul(cost, sllsub(int2sll(1), sllmul(u[2],u[2]))));
    }
  }

  gl_M4_MulLeft(c->matrix_stack_ptr[c->matrix_mode],&m);

  gl_matrix_update(c);
}