Ejemplo n.º 1
0
t_camera	*create_camera(t_vector position)
{
	t_camera	*camera;

	camera = (t_camera *)malloc(sizeof(t_camera));
	camera->campos = position;
	camera->camdir = normalize(NEG(SUB(camera->campos, D_VEC)));
	camera->camright = normalize(CROSS_PROD(Y_VEC, camera->camdir));
	camera->camdown = CROSS_PROD(camera->camright, camera->camdir);
	return (camera);
}
Ejemplo n.º 2
0
Archivo: api_eval.c Proyecto: aosm/X11
static void do_EvalCoord2f( GLcontext* ctx, GLfloat u, GLfloat v )
{   
   /** Color Index **/
   if (ctx->Eval.Map2Index) {
      GLfloat findex;
      struct gl_2d_map *map = &ctx->EvalMap.Map2Index;
      GLfloat uu = (u - map->u1) * map->du;
      GLfloat vv = (v - map->v1) * map->dv;
      _math_horner_bezier_surf(map->Points, &findex, uu, vv, 1,
                         map->Uorder, map->Vorder);
      glIndexi( (GLuint) (GLint) findex );
   }

   /** Color **/
   if (ctx->Eval.Map2Color4) {
      GLfloat fcolor[4];
      struct gl_2d_map *map = &ctx->EvalMap.Map2Color4;
      GLfloat uu = (u - map->u1) * map->du;
      GLfloat vv = (v - map->v1) * map->dv;
      _math_horner_bezier_surf(map->Points, fcolor, uu, vv, 4,
                         map->Uorder, map->Vorder);
      glColor4fv( fcolor );
   }

   /** Normal **/
   if (ctx->Eval.Map2Normal &&
       (!ctx->Eval.AutoNormal || (!ctx->Eval.Map2Vertex3 && 
				  !ctx->Eval.Map2Vertex4))) {
      GLfloat normal[3];
      struct gl_2d_map *map = &ctx->EvalMap.Map2Normal;
      GLfloat uu = (u - map->u1) * map->du;
      GLfloat vv = (v - map->v1) * map->dv;
      _math_horner_bezier_surf(map->Points, normal, uu, vv, 3,
			 map->Uorder, map->Vorder);
      glNormal3fv( normal );
   }

   /** Texture Coordinates **/
   if (ctx->Eval.Map2TextureCoord4) {
      GLfloat texcoord[4];
      struct gl_2d_map *map = &ctx->EvalMap.Map2Texture4;
      GLfloat uu = (u - map->u1) * map->du;
      GLfloat vv = (v - map->v1) * map->dv;
      _math_horner_bezier_surf(map->Points, texcoord, uu, vv, 4,
                         map->Uorder, map->Vorder);
      glTexCoord4fv( texcoord );
   }
   else if (ctx->Eval.Map2TextureCoord3) {
      GLfloat texcoord[4];
      struct gl_2d_map *map = &ctx->EvalMap.Map2Texture3;
      GLfloat uu = (u - map->u1) * map->du;
      GLfloat vv = (v - map->v1) * map->dv;
      _math_horner_bezier_surf(map->Points, texcoord, uu, vv, 3,
                         map->Uorder, map->Vorder);
      glTexCoord3fv( texcoord );
   }
   else if (ctx->Eval.Map2TextureCoord2) {
      GLfloat texcoord[4];
      struct gl_2d_map *map = &ctx->EvalMap.Map2Texture2;
      GLfloat uu = (u - map->u1) * map->du;
      GLfloat vv = (v - map->v1) * map->dv;
      _math_horner_bezier_surf(map->Points, texcoord, uu, vv, 2,
                         map->Uorder, map->Vorder);
      glTexCoord2fv( texcoord );
   }
   else if (ctx->Eval.Map2TextureCoord1) {
      GLfloat texcoord[4];
      struct gl_2d_map *map = &ctx->EvalMap.Map2Texture1;
      GLfloat uu = (u - map->u1) * map->du;
      GLfloat vv = (v - map->v1) * map->dv;
      _math_horner_bezier_surf(map->Points, texcoord, uu, vv, 1,
                         map->Uorder, map->Vorder);
      glTexCoord1fv( texcoord );
   }

   /** Vertex **/
   if(ctx->Eval.Map2Vertex4) {
      GLfloat vertex[4];
      GLfloat normal[3];
      struct gl_2d_map *map = &ctx->EvalMap.Map2Vertex4;
      GLfloat uu = (u - map->u1) * map->du;
      GLfloat vv = (v - map->v1) * map->dv;

      if (ctx->Eval.AutoNormal) {
         GLfloat du[4], dv[4];

         _math_de_casteljau_surf(map->Points, vertex, du, dv, uu, vv, 4,
				 map->Uorder, map->Vorder);

         CROSS_PROD(normal, du, dv);
         NORMALIZE_3FV(normal);
	 glNormal3fv( normal );
	 glVertex4fv( vertex );
      }
      else {
         _math_horner_bezier_surf(map->Points, vertex, uu, vv, 4,
                            map->Uorder, map->Vorder);
	 glVertex4fv( vertex );
      }
   }
   else if (ctx->Eval.Map2Vertex3) {
      GLfloat vertex[4];
      struct gl_2d_map *map = &ctx->EvalMap.Map2Vertex3;
      GLfloat uu = (u - map->u1) * map->du;
      GLfloat vv = (v - map->v1) * map->dv;
      if (ctx->Eval.AutoNormal) {
         GLfloat du[3], dv[3];
	 GLfloat normal[3];
         _math_de_casteljau_surf(map->Points, vertex, du, dv, uu, vv, 3,
				 map->Uorder, map->Vorder);
         CROSS_PROD(normal, du, dv);
         NORMALIZE_3FV(normal);
	 glNormal3fv( normal );
	 glVertex3fv( vertex );
      }
      else {
         _math_horner_bezier_surf(map->Points, vertex, uu, vv, 3,
                            map->Uorder, map->Vorder);
	 glVertex3fv( vertex );
      }
   }
}