Ejemplo n.º 1
0
vec3d IkSolver::stepIk()
{
	vec3d tip = boneStates[effectorBone->id].boneToWorld.translation();

	std::vector<const Bone*>::iterator it = ikChain.begin();
	// the first bone is the effector bone, so rotating it won't help; just skip it
	++it;
	while (it != ikChain.end())
	{
		const Bone &b = **it;
		BoneState &bs = boneStates[b.id];

		++it;
		if (it != ikChain.end())
		{
			const Bone &parent = **it;
			const Bone::Connection &joint = *b.findJointWith(parent);

			const mat4d worldToBone = vmath::fast_inverse(bs.boneToWorld);
			
			vec3d targetB = transform_point(worldToBone, targetPos);
			vec3d tipB = transform_point(worldToBone, tip);

			tipB = updateJointByIk(b, joint, targetB, tipB);

			tip = transform_point(bs.boneToWorld, tipB);
		}
	}

	return tip;
}
/* projection du point (objx,objy,obz) sur l'ecran (winx,winy,winz) */
GLint GLAPIENTRY
gluProject(GLdouble objx, GLdouble objy, GLdouble objz,
	   const GLdouble model[16], const GLdouble proj[16],
	   const GLint viewport[4],
	   GLdouble * winx, GLdouble * winy, GLdouble * winz)
{
   /* matrice de transformation */
   GLdouble in[4], out[4];

   /* initilise la matrice et le vecteur a transformer */
   in[0] = objx;
   in[1] = objy;
   in[2] = objz;
   in[3] = 1.0;
   transform_point(out, model, in);
   transform_point(in, proj, out);

   /* d'ou le resultat normalise entre -1 et 1 */
   if (in[3] == 0.0)
      return GL_FALSE;

   in[0] /= in[3];
   in[1] /= in[3];
   in[2] /= in[3];

   /* en coordonnees ecran */
   *winx = viewport[0] + (1 + in[0]) * viewport[2] / 2;
   *winy = viewport[1] + (1 + in[1]) * viewport[3] / 2;
   /* entre 0 et 1 suivant z */
   *winz = (1 + in[2]) / 2;
   return GL_TRUE;
}
Ejemplo n.º 3
0
void
transform_bezpoint (BezPoint *bpt, const DiaMatrix *m)
{
  transform_point (&bpt->p1, m);
  transform_point (&bpt->p2, m);
  transform_point (&bpt->p3, m);
}
Ejemplo n.º 4
0
bool gluProject(float objx, float objy, float objz,
		const float modelMatrix[16], const float projMatrix[16],
		const int viewport[4], float *winx, float *winy, float *winz) {
	// matrice transformation
	float in[4], out[4];
	//initialize matrice and column vector as a transformer
	in[0] = objx;
	in[1] = objy;
	in[2] = objz;
	in[3] = 1.0;
	transform_point(out, modelMatrix, in); //乘以模型视图矩阵
	transform_point(in, projMatrix, out); //乘以投影矩阵
	//齐次向量的第四项不能为0
	if (in[3] == 0.0)
		return false;
	//向量齐次化标准化
	in[0] /= in[3];
	in[1] /= in[3];
	in[2] /= in[3];
	//视口向量的作用
	*winx = viewport[0] + (1 + in[0]) * viewport[2] / 2;
	*winy = viewport[1] + (1 + in[1]) * viewport[3] / 2;
	*winz = (1 + in[2]) / 2;
	return true;
}
Ejemplo n.º 5
0
	void Timeline::render(gui::Compositor* compositor, gui::Renderer* renderer, gui::render::CommandList& render_commands)
	{
		// TODO: should get this from the style
		const gemini::Color frame_color = gemini::Color::from_rgba(96, 96, 96, 255);

		// draw the background
		render_commands.add_rectangle(geometry[0], geometry[1], geometry[2], geometry[3], gui::render::WhiteTexture, gemini::Color::from_rgba(64, 64, 64, 255));

		// add a top rule line to separate this panel
		render_commands.add_line(geometry[0], geometry[3], gemini::Color::from_rgba(0, 0, 0, 255), 1.0f);

		// center the individual frames
		Rect block;
		block.set(left_margin + 2.0f, 1.0, (frame_width_pixels - 4.0f), size.height - 2.0f);

		for (size_t index = 0; index < total_frames; ++index)
		{
			// draw frame ticks until we reach the end of the panel
			if (block.origin.x + block.size.width >= (origin.x + size.width))
			{
				break;
			}

			Point points[4];
			points[0] = transform_point(local_transform, block.origin);
			points[1] = transform_point(local_transform, Point(block.origin.x, block.origin.y + block.size.height));
			points[2] = transform_point(local_transform, Point(block.origin.x + block.size.width, block.origin.y + block.size.height));
			points[3] = transform_point(local_transform, Point(block.origin.x + block.size.width, block.origin.y));
			render_commands.add_rectangle(points[0], points[1], points[2], points[3], gui::render::WhiteTexture, frame_color);

			block.origin.x += frame_width_pixels;
		}

		render_children(compositor, renderer, render_commands);
	} // render
Ejemplo n.º 6
0
void BVHSpatialSplit::split_triangle_primitive(const Mesh *mesh,
                                               const Transform *tfm,
                                               int prim_index,
                                               int dim,
                                               float pos,
                                               BoundBox& left_bounds,
                                               BoundBox& right_bounds)
{
	const int *inds = mesh->triangles[prim_index].v;
	const float3 *verts = &mesh->verts[0];
	float3 v1 = tfm ? transform_point(tfm, verts[inds[2]]) : verts[inds[2]];

	for(int i = 0; i < 3; i++) {
		float3 v0 = v1;
		int vindex = inds[i];
		v1 = tfm ? transform_point(tfm, verts[vindex]) : verts[vindex];
		float v0p = v0[dim];
		float v1p = v1[dim];

		/* insert vertex to the boxes it belongs to. */
		if(v0p <= pos)
			left_bounds.grow(v0);

		if(v0p >= pos)
			right_bounds.grow(v0);

		/* edge intersects the plane => insert intersection to both boxes. */
		if((v0p < pos && v1p > pos) || (v0p > pos && v1p < pos)) {
			float3 t = lerp(v0, v1, clamp((pos - v0p) / (v1p - v0p), 0.0f, 1.0f));
			left_bounds.grow(t);
			right_bounds.grow(t);
		}
	}
}
Ejemplo n.º 7
0
float3 Camera::transform_raster_to_world(float raster_x, float raster_y)
{
	float3 D, P;
	if(type == CAMERA_PERSPECTIVE) {
		D = transform_perspective(&rastertocamera,
		                          make_float3(raster_x, raster_y, 0.0f));
		float3 Pclip = normalize(D);
		P = make_float3(0.0f, 0.0f, 0.0f);
		/* TODO(sergey): Aperture support? */
		P = transform_point(&cameratoworld, P);
		D = normalize(transform_direction(&cameratoworld, D));
		/* TODO(sergey): Clipping is conditional in kernel, and hence it could
		 * be mistakes in here, currently leading to wrong camera-in-volume
		 * detection.
		 */
		P += nearclip * D / Pclip.z;
	}
	else if(type == CAMERA_ORTHOGRAPHIC) {
		D = make_float3(0.0f, 0.0f, 1.0f);
		/* TODO(sergey): Aperture support? */
		P = transform_perspective(&rastertocamera,
		                          make_float3(raster_x, raster_y, 0.0f));
		P = transform_point(&cameratoworld, P);
		D = normalize(transform_direction(&cameratoworld, D));
	}
	else {
		assert(!"unsupported camera type");
	}
	return P;
}
Ejemplo n.º 8
0
    void cairo_to_clipper(cairo_t* cr,
                          Polygons &pg,
                          int scaling_factor,
                          Transform transform)
    {
      if (scaling_factor > 8 || scaling_factor < 0)
        throw clipperCairoException("cairo_to_clipper: invalid scaling factor");
      double scaling = std::pow((double)10, scaling_factor);

      pg.clear();
      cairo_path_t *path = cairo_copy_path_flat(cr);

      int poly_count = 0;
      for (int i = 0; i < path->num_data; i += path->data[i].header.length) {
        if( path->data[i].header.type == CAIRO_PATH_CLOSE_PATH) poly_count++;
      }

      pg.resize(poly_count);
      int i = 0, pc = 0;
      while (pc < poly_count)
      {
        int vert_count = 1;
        int j = i;
        while(j < path->num_data &&
          path->data[j].header.type != CAIRO_PATH_CLOSE_PATH)
        {
          if (path->data[j].header.type == CAIRO_PATH_LINE_TO)
            vert_count++;
          j += path->data[j].header.length;
        }
        pg[pc].resize(vert_count);
        if (path->data[i].header.type != CAIRO_PATH_MOVE_TO) {
          pg.resize(pc);
          break;
        }
        pg[pc][0].X = Round(path->data[i+1].point.x *scaling);
        pg[pc][0].Y = Round(path->data[i+1].point.y *scaling);
        if (transform != tNone)
          transform_point(cr, transform, &pg[pc][0].X, &pg[pc][0].Y);

        i += path->data[i].header.length;

        j = 1;
        while (j < vert_count && i < path->num_data &&
          path->data[i].header.type == CAIRO_PATH_LINE_TO) {
          pg[pc][j].X = Round(path->data[i+1].point.x *scaling);
          pg[pc][j].Y = Round(path->data[i+1].point.y *scaling);
          if (transform != tNone)
            transform_point(cr, transform, &pg[pc][j].X, &pg[pc][j].Y);
          j++;
          i += path->data[i].header.length;
        }
        pc++;
        i += path->data[i].header.length;
      }
      cairo_path_destroy(path);
    }
Ejemplo n.º 9
0
bool 
DiaOutputDev::doPath (GArray *points, GfxState *state, GfxPath *path, bool &haveClose)
{
  int i, j;
  Point start;
  haveClose = false;

  for (i = 0; i < path->getNumSubpaths(); ++i) {
    GfxSubpath *subPath = path->getSubpath(i);

    if (subPath->getNumPoints() < 2)
      continue;

    Point cp; // current point

    cp.x = subPath->getX(0) * scale;
    cp.y = subPath->getY(0) * scale;
    start = cp;
    transform_point (&cp, &this->matrix);
    _path_moveto (points, &cp);
    for (j = 1; j < subPath->getNumPoints(); ) {
      if (subPath->getCurve(j)) {
        BezPoint bp;

        bp.type = BezPoint::BEZ_CURVE_TO;
        bp.p1.x = subPath->getX(j) * scale;
        bp.p1.y = subPath->getY(j) * scale;
        bp.p2.x = subPath->getX(j+1) * scale;
        bp.p2.y = subPath->getY(j+1) * scale;
        bp.p3.x = subPath->getX(j+2) * scale;
        bp.p3.y = subPath->getY(j+2) * scale;
        cp = bp.p3;
        transform_bezpoint (&bp, &this->matrix);
        g_array_append_val (points, bp);
        j += 3;
      } else {
        cp.x = subPath->getX(j) * scale;
        cp.y = subPath->getY(j) * scale;
        transform_point (&cp, &this->matrix);
        _path_lineto (points, &cp);
        j += 1;
      }
    } // foreach point in subpath
    if (subPath->isClosed()) {
      // add an extra point just to be sure
      transform_point (&start, &this->matrix);
      _path_lineto (points, &start);
      haveClose = true;
    }
  } // foreach subpath
  return (i > 0);
}
GLint GLAPIENTRY
gluUnProject4(GLdouble winx, GLdouble winy, GLdouble winz, GLdouble clipw,
	      const GLdouble modelMatrix[16],
	      const GLdouble projMatrix[16],
	      const GLint viewport[4],
	      GLclampd nearZ, GLclampd farZ,
	      GLdouble * objx, GLdouble * objy, GLdouble * objz,
	      GLdouble * objw)
{
   /* matrice de transformation */
   GLdouble m[16], A[16];
   GLdouble in[4], out[4];
   GLdouble z = nearZ + winz * (farZ - nearZ);

   /* transformation coordonnees normalisees entre -1 et 1 */
   in[0] = (winx - viewport[0]) * 2 / viewport[2] - 1.0;
   in[1] = (winy - viewport[1]) * 2 / viewport[3] - 1.0;
   in[2] = 2.0 * z - 1.0;
   in[3] = clipw;

   /* calcul transformation inverse */
   matmul(A, projMatrix, modelMatrix);
   if (!invert_matrix(A, m))
      return GL_FALSE;

   /* d'ou les coordonnees objets */
   transform_point(out, m, in);
   if (out[3] == 0.0)
      return GL_FALSE;
   *objx = out[0] / out[3];
   *objy = out[1] / out[3];
   *objz = out[2] / out[3];
   *objw = out[3];
   return GL_TRUE;
}
Ejemplo n.º 11
0
float Camera::world_to_raster_size(float3 P)
{
	if(type == CAMERA_ORTHOGRAPHIC) {
		return min(len(full_dx), len(full_dy));
	}
	else if(type == CAMERA_PERSPECTIVE) {
		/* Calculate as if point is directly ahead of the camera. */
		float3 raster = make_float3(0.5f*width, 0.5f*height, 0.0f);
		float3 Pcamera = transform_perspective(&rastertocamera, raster);

		/* dDdx */
		float3 Ddiff = transform_direction(&cameratoworld, Pcamera);
		float3 dx = len_squared(full_dx) < len_squared(full_dy) ? full_dx : full_dy;
		float3 dDdx = normalize(Ddiff + dx) - normalize(Ddiff);

		/* dPdx */
		float dist = len(transform_point(&worldtocamera, P));
		float3 D = normalize(Ddiff);
		return len(dist*dDdx - dot(dist*dDdx, D)*D);
	}
	else {
		// TODO(mai): implement for CAMERA_PANORAMA
		assert(!"pixel width calculation for panoramic projection not implemented yet");
	}

	return 1.0f;
}
Ejemplo n.º 12
0
/* transformation du point ecran (winx,winy,winz) en point objet */
GLint gluUnProject(GLdouble winx,GLdouble winy,GLdouble winz,
                   const GLdouble model[16],const GLdouble proj[16],
                   const GLint viewport[4],
                   GLdouble *objx,GLdouble *objy,GLdouble *objz)
{
    /* matrice de transformation */
    GLdouble m[16], A[16];
    GLdouble in[4],out[4];

    /* transformation coordonnees normalisees entre -1 et 1 */
    in[0]=(winx-viewport[0])*2/viewport[2] - 1.0;
    in[1]=(winy-viewport[1])*2/viewport[3] - 1.0;
    in[2]=2*winz - 1.0;
    in[3]=1.0;

    /* calcul transformation inverse */
    matmul(A,proj,model);
    invert_matrix(A,m);

    /* d'ou les coordonnees objets */
    transform_point(out,m,in);
    *objx=out[0]/out[3];
    *objy=out[1]/out[3];
    *objz=out[2]/out[3];
    return GL_TRUE;
}
Ejemplo n.º 13
0
bvol_t *transform_bin_volume_2D(bvol_t *b, trans2D_t *T) {
    /* Test each point in the plane for inclusion in the new
     * (transformed) binary image */
    bvol_t *Tb = new_bin_volume(b->w, b->h, b->d, BVOL_BITS);

    /* Compute the inverse of T */
    trans2D_t *Tinv = transform_invert(T);

    int x, y, z;
    int xc, yc, zc;

    for (z = 0; z < (int) b->d; z++) {
        for (y = 0; y < (int) b->h; y++) {
            for (x = 0; x < (int) b->w; x++) {
                double out[3];
                
                transform_point(Tinv, (double) x, (double) y, out + 0, out + 1);
		out[2] = z;

                /* Check if the point lies in the set */
                xc = iround(out[0]);
                yc = iround(out[1]);
                zc = iround(out[2]);

                if (bvol_getbit(b, xc, yc, zc))
                    bvol_setbit(Tb, x, y, z);
            }
        }
    }
    
    transform_free(Tinv);

    return Tb;
}
Ejemplo n.º 14
0
Archivo: textobj.c Proyecto: GNOME/dia
static void
_textobj_get_poly (const Textobj *textobj, Point poly[4])
{
  Point ul, lr;
  Point pt = textobj->text_handle.pos;
  Rectangle box;
  DiaMatrix m = { 1, 0, 0, 1, pt.x, pt.y };
  DiaMatrix t = { 1, 0, 0, 1, -pt.x, -pt.y };
  int i;

  dia_matrix_set_angle_and_scales (&m, G_PI * textobj->text_angle / 180.0, 1.0, 1.0);
  dia_matrix_multiply (&m, &t, &m);

  text_calc_boundingbox (textobj->text, &box);
  ul.x = box.left - textobj->margin;
  ul.y = box.top - textobj->margin;
  lr.x = box.right + textobj->margin;
  lr.y = box.bottom + textobj->margin;

  poly[0].x = ul.x;
  poly[0].y = ul.y;
  poly[1].x = lr.x;
  poly[1].y = ul.y;
  poly[2].x = lr.x;
  poly[2].y = lr.y;
  poly[3].x = ul.x;
  poly[3].y = lr.y;

  for (i = 0; i < 4; ++i)
    transform_point (&poly[i], &m);
}
Ejemplo n.º 15
0
/// main draw method
void display() {
    hud_fps_display.start();
    if(draw_opts.cameralights) scene_cameralights_update(scene,draw_opts.cameralights_dir,draw_opts.cameralights_col);
    draw_scene(scene,draw_opts,true);
    draw_scene_decorations(scene,draw_opts,false);
    glFlush();
    hud_fps_display.stop();
    
    if(selected_frame) {
        auto axes = Axes();
        axes.frame = *selected_frame;
        draw_gizmo(&axes);
        if(selected_point) {
            auto dot = Dot();
            dot.pos = transform_point(*selected_frame, *selected_point);
            draw_gizmo(&dot);
        }
    }
    
    if(hud) display_hud();
    
    glutSwapBuffers();
    
    if(screenshotAndExit) {
        if(time_init_advance <= 0.0f or draw_opts.time >= time_init_advance ) {
            screenshot(filename_image.c_str());
            exit(0);
        }
    }
}
    int Mesh::GetTransformedFace(int const faceidx, matrix const & transform, float3* outverts) const
    {
        // origin code special cased identity matrix. TODO check speed regressions
        outverts[0] = transform_point(vertices_[faces_[faceidx].i0], transform);
        outverts[1] = transform_point(vertices_[faces_[faceidx].i1], transform);
        outverts[2] = transform_point(vertices_[faces_[faceidx].i2], transform);

        if (faces_[faceidx].type_ == FaceType::QUAD)
        {
            outverts[3] = transform_point(vertices_[faces_[faceidx].i3], transform);
            return 4;
        } else
        {
            return 3;
        }
    }
Ejemplo n.º 17
0
/* Compute how many points lie further in the direction given than the
   witness point.
   */
static int num_further( int npts, double errin, double * errout,
			REAL (*pts)[DIM], struct transf * t,
			REAL direction[DIM], REAL witness[DIM])
{
   double lpt[3], dirsize, *ptr, test_val, val, worst;
   int p, nbad;

   dirsize = sqrt( dot_product( direction, direction));
   test_val = dot_product( witness, direction) + dirsize * errin + ZETA;

   nbad = 0;
   for ( p=0 ; p<npts ; p++ )
     {
       if ( t==0 )
	 ptr = pts[p];
       else
	 {
	   transform_point( t, pts[p], lpt);
	   ptr = lpt;
	 }
       if ( dot_product( ptr, direction) > test_val ) {
	 val = dot_product( ptr, direction) - test_val - ZETA;
	 if ( ( nbad==0 ) || ( val > worst ) )
	   worst = test_val;
         nbad++;
       }
     }
   *errout = ( nbad>0 ) ? worst : 0.0;

   return nbad;
   }
Ejemplo n.º 18
0
void trans_polyhedron( matrixgl_t mat, polyhedron_t ph )
{
    int i;
    for (i=0; i<ph.num_vertices; i++) {
        ph.vertices[i] = transform_point( mat, ph.vertices[i] );
    } 
} 
Ejemplo n.º 19
0
Archivo: textobj.c Proyecto: GNOME/dia
static gboolean
textobj_transform(Textobj *textobj, const DiaMatrix *m)
{
  real a, sx, sy;

  g_return_val_if_fail(m != NULL, FALSE);

  if (!dia_matrix_get_angle_and_scales (m, &a, &sx, &sy)) {
    dia_log_message ("textobj_transform() can't convert given matrix");
    return FALSE;
  } else {
    /* XXX: what to do if width!=height */
    real height = text_get_height (textobj->text) * MIN(sx,sy);
    real angle = a*180/G_PI;
    Point p = textobj->object.position;

    /* rotation is invariant to the handle position */
    transform_point (&p, m);
    text_set_height (textobj->text, height);
    textobj->text_angle = angle;
    textobj->object.position = p;
 }

  textobj_update_data(textobj);
  return TRUE;
}
Ejemplo n.º 20
0
/* Try to push a rectangle given in object coordinates as a rectangle in window
 * coordinates instead of object coordinates */
gboolean
try_pushing_rect_as_window_rect (float x_1,
	                         float y_1,
                                 float x_2,
                                 float y_2)
{
  CoglMatrix matrix;
  CoglMatrix matrix_p;
  float v[4];

  cogl_get_modelview_matrix (&matrix);

  /* If the modelview meets these constraints then a transformed rectangle
   * should still be a rectangle when it reaches screen coordinates.
   *
   * FIXME: we are are making certain assumptions about the projection
   * matrix a.t.m and should really be looking at the combined modelview
   * and projection matrix.
   * FIXME: we don't consider rotations that are a multiple of 90 degrees
   * which could be quite common.
   */
  if (matrix.xy != 0 || matrix.xz != 0 ||
      matrix.yx != 0 || matrix.yz != 0 ||
      matrix.zx != 0 || matrix.zy != 0)
    return FALSE;

  cogl_get_projection_matrix (&matrix_p);
  cogl_get_viewport (v);

  transform_point (&matrix, &matrix_p, v, &x_1, &y_1);
  transform_point (&matrix, &matrix_p, v, &x_2, &y_2);

  /* Consider that the modelview matrix may flip the rectangle
   * along the x or y axis... */
#define SWAP(A,B) do { float tmp = B; B = A; A = tmp; } while (0)
  if (x_1 > x_2)
    SWAP (x_1, x_2);
  if (y_1 > y_2)
    SWAP (y_1, y_2);
#undef SWAP

  cogl_clip_push_window_rectangle (COGL_UTIL_NEARBYINT (x_1),
                                   COGL_UTIL_NEARBYINT (y_1),
                                   COGL_UTIL_NEARBYINT (x_2 - x_1),
                                   COGL_UTIL_NEARBYINT (y_2 - y_1));
  return TRUE;
}
Ejemplo n.º 21
0
void setup_view_matrix( player_data_t *plyr ) 
{
    vector_t view_x, view_y, view_z;
    matrixgl_t view_mat;
    point_t viewpt_in_view_frame;

    view_z = scale_vector( -1, plyr->view.dir );
    view_x = cross_product( plyr->view.up, view_z );
    view_y = cross_product( view_z, view_x );
    normalize_vector( &view_z );
    normalize_vector( &view_x );
    normalize_vector( &view_y );

    make_identity_matrix( plyr->view.inv_view_mat );

    plyr->view.inv_view_mat[0][0] = view_x.x;
    plyr->view.inv_view_mat[0][1] = view_x.y;
    plyr->view.inv_view_mat[0][2] = view_x.z;

    plyr->view.inv_view_mat[1][0] = view_y.x;
    plyr->view.inv_view_mat[1][1] = view_y.y;
    plyr->view.inv_view_mat[1][2] = view_y.z;

    plyr->view.inv_view_mat[2][0] = view_z.x;
    plyr->view.inv_view_mat[2][1] = view_z.y;
    plyr->view.inv_view_mat[2][2] = view_z.z;

    plyr->view.inv_view_mat[3][0] = plyr->view.pos.x;
    plyr->view.inv_view_mat[3][1] = plyr->view.pos.y;
    plyr->view.inv_view_mat[3][2] = plyr->view.pos.z;
    plyr->view.inv_view_mat[3][3] = 1;
    
    transpose_matrix( plyr->view.inv_view_mat, view_mat );

    view_mat[0][3] = 0;
    view_mat[1][3] = 0;
    view_mat[2][3] = 0;
    
    viewpt_in_view_frame = transform_point( view_mat, plyr->view.pos );
    
    view_mat[3][0] = -viewpt_in_view_frame.x;
    view_mat[3][1] = -viewpt_in_view_frame.y;
    view_mat[3][2] = -viewpt_in_view_frame.z;
    
    glLoadIdentity();
#ifdef __APPLE__DISABLED__
    GLfloat matrix[3][3];
    int i,j;
    for( i = 0; i < 3; i++ )
    {
        for( j = 0; j < 3; j++ )
            matrix[i][j] = view_mat[i][j];
    }
    glMultMatrixf( (GLfloat *) matrix );
#else
    glMultMatrixd( (scalar_t *) view_mat );
#endif

}
Ejemplo n.º 22
0
/* transform each point in the hull.
   */
static void transform_hull( int npts, REAL (*src)[DIM], REAL (*tgt)[DIM],
			    struct transf * t)
{
  int i;
  for ( i=0 ; i<npts ; i++ )
    transform_point( t, src[i], tgt[i]);
  return;
}
Ejemplo n.º 23
0
// determines if our viewing ray intersects this given object
// abstractly speaking we construct the following system: 
// e + T(d) = a + BETA(b-a) + GAMMA(c-a)
// And solve for T, BETA, and GAMMA using cramer's rule  
real_t Triangle::is_intersecting(Vector3 &s, Vector3 &e, real_t* T) const
{
	Vector3 d  = transform_vector(s);
	Vector3 e1 = transform_point(e);  
	Vector3 a = vertices[0].position; 
	Vector3 b = vertices[1].position;
	Vector3 c = vertices[2].position;
        camera_eye = e1; 
	ray_direction = d; 	

	// we construct each of the entries of the matrix
	// of a linear system 
	real_t A = a.x - b.x;
	real_t B = a.y - b.y;
	real_t C = a.z - b.z;
	
	real_t D = a.x - c.x; 
	real_t E = a.y - c.y; 
	real_t F = a.z - c.z; 
	
	real_t G = d.x; 
	real_t H = d.y;
	real_t I = d.z; 
	
	real_t J = a.x - e1.x;
	real_t K = a.y - e1.y; 
	real_t L = a.z - e1.z; 
 	// store results of arithemtic to save operations 
	real_t EIHF = E*I - H*F; 
	real_t GFDI = G*F - D*I; 
	real_t DHEG = D*H - E*G; 
	
	real_t AKJB = A*K - J*B;
	real_t JCAL = J*C - A*L; 
	real_t BLKC = B*L - K*C;    	

	// use cramers rule to solve 3 by 3 linear system 
	// results are given by the formulas below. 	
	real_t  M   =  A*(EIHF) + B*(GFDI) + C*(DHEG); 
	real_t beta = (J*(EIHF) + K*(GFDI) + L*(DHEG))/M;
	real_t gamma = (I*(AKJB) + H*(JCAL) + G*(BLKC))/M; 
	real_t	 TIME =-(F*(AKJB) + E*(JCAL) + D*(BLKC))/M; 
 	// conditions for returning true, note that T must be within the interval [0, infinity) 
	if((TIME >= 0.0) && (gamma >= 0.0) && (gamma <= 1.0) && (beta >= 0.0) && (beta <= 1.0 - gamma)){		
		ray_time = TIME;
		real_t alpha = 1.0 - beta - gamma;
		// the intersection returns -1 if the time of intersection is 
		// in fact a minimal time 
		if(TIME < *T || *T == -1.0){
			ALPHA = alpha;
			BETA = beta; 
			GAMMA = gamma;
			*T = TIME;					
			return -1.0; 
		}	
	}
	return 0.0; 
}
Ejemplo n.º 24
0
static void cmdedit( void )
{
   double pt[ 3 ], r[ 3 ], c[ 3 ], h, xrot, yrot, rot;
   int i, j, n, vi, snum;


   csSetLayer( layer1 );
   csMergePoints( 0 );

   if ( atom_type == ATYPE_SPHERE ) {
      mgMonitorBegin( "Sphere Atoms", NULL, seqlen );

      csSetLayer( layer1 );
      for ( j = 0; j < seqlen; j++ ) {
         n = atom_count( seq[ j ] );
         for ( i = 0; i < n; i++ ) {
            atom_info( seq[ j ], i, &vi, &snum );
            vert_coords( seq[ j ], vi, pt );
            transform_point( j * 3.4, j * 36.0, pt );
            r[ 0 ] = r[ 1 ] = r[ 2 ] = atom_radius[ snum ];
            csSetDefaultSurface( surface_name( snum ));
            csMakeBall( r, atom_nsides, atom_nsegments, pt );
         }
         if ( userabort = mgMonitorStep( 1 ))
            break;
      }
      mgMonitorDone();
   }

   if ( bond_type == BTYPE_CYLINDER && !userabort ) {
      mgMonitorBegin( "Cylinder Bonds", NULL, seqlen );

      for ( j = 0; j < seqlen; j++ ) {
         n = bond_count( seq[ j ] );
         for ( i = 0; i < n; i++ ) {
            bond_coords( seq[ j ], i, pt, &h, &xrot, &yrot, &snum );
            pt[ 1 ] += 3.4 * j;
            csSetLayer( layer2 );
            csSetDefaultSurface( surface_name( snum ));
            r[ 0 ] = r[ 1 ] = r[ 2 ] = bond_radius;
            c[ 0 ] = c[ 2 ] = 0.0;
            c[ 1 ] = h / 2.0;
            csMakeDisc( r, h, 0, "Y", bond_nsides, bond_nsegments, c );
            csRotate( xrot, "X", NULL );
            csRotate( yrot, "Y", NULL );
            csMove( pt );
            rot = 36 * j;
            csRotate( rot, "Y", NULL );
            csCut();
            csSetLayer( layer1 );
            csPaste();
         }
         if ( userabort = mgMonitorStep( 1 ))
            break;
      }
      mgMonitorDone();
   }
}
Ejemplo n.º 25
0
void BVHSpatialSplit::split_curve_primitive(const Mesh *mesh,
                                            const Transform *tfm,
                                            int prim_index,
                                            int segment_index,
                                            int dim,
                                            float pos,
                                            BoundBox& left_bounds,
                                            BoundBox& right_bounds)
{
	/* curve split: NOTE - Currently ignores curve width and needs to be fixed.*/
	const int k0 = mesh->curves[prim_index].first_key + segment_index;
	const int k1 = k0 + 1;
	const float4& key0 = mesh->curve_keys[k0];
	const float4& key1 = mesh->curve_keys[k1];
	float3 v0 = float4_to_float3(key0);
	float3 v1 = float4_to_float3(key1);

	if(tfm != NULL) {
		v0 = transform_point(tfm, v0);
		v1 = transform_point(tfm, v1);
	}

	float v0p = v0[dim];
	float v1p = v1[dim];

	/* insert vertex to the boxes it belongs to. */
	if(v0p <= pos)
		left_bounds.grow(v0);

	if(v0p >= pos)
		right_bounds.grow(v0);

	if(v1p <= pos)
		left_bounds.grow(v1);

	if(v1p >= pos)
		right_bounds.grow(v1);

	/* edge intersects the plane => insert intersection to both boxes. */
	if((v0p < pos && v1p > pos) || (v0p > pos && v1p < pos)) {
		float3 t = lerp(v0, v1, clamp((pos - v0p) / (v1p - v0p), 0.0f, 1.0f));
		left_bounds.grow(t);
		right_bounds.grow(t);
	}
}
Ejemplo n.º 26
0
void scene_renderer_t::convert_to_path( const shape_t& s, agg::path_storage& path, const Imath::V2i& offset, int subsample) const
{
	path.remove_all();
	
	Imath::V2f p0, p1, p2;
	Imath::V2f shape_offset = s.offset();

	Imath::M33f m( s.global_xform());
	
	p0 = transform_point( s.triples()[0].p1(), shape_offset, m, subsample, offset);
	path.move_to( p0.x, p0.y);
	
	for( int i = 0; i < s.triples().size() - 1; ++i)
	{
		p2 = transform_point( s.triples()[i].p2(), shape_offset, m, subsample, offset);
		p0 = transform_point( s.triples()[i+1].p0(), shape_offset, m, subsample, offset);
		p1 = transform_point( s.triples()[i+1].p1(), shape_offset, m, subsample, offset);
		path.curve4( p2.x, p2.y, p0.x, p0.y, p1.x, p1.y);
	}

	// last segment
	p2 = transform_point( s.triples()[s.triples().size()-1].p2(), shape_offset, m, subsample, offset);
	p0 = transform_point( s.triples()[0].p0(), shape_offset, m, subsample, offset);
	p1 = transform_point( s.triples()[0].p1(), shape_offset, m, subsample, offset);
	path.curve4( p2.x, p2.y, p0.x, p0.y, p1.x, p1.y);
	path.close_polygon();
}
Ejemplo n.º 27
0
void
transform_length (real *len, const DiaMatrix *m)
{
  Point pt = { *len, 0 };
  transform_point (&pt, m);
  /* not interested in the offset */
  pt.x -= m->x0;
  pt.y -= m->y0;
  *len = point_len (&pt);
}
Ejemplo n.º 28
0
float3 DiagSplit::to_world(Patch *patch, float2 uv)
{
	float3 P;

	patch->eval(&P, NULL, NULL, NULL, uv.x, uv.y);
	if(params.camera)
		P = transform_point(&params.objecttoworld, P);

	return P;
}
Ejemplo n.º 29
0
void setup_view_matrix( player_data_t *plyr ) 
{
    GLfloat matrix[4][4];
    int i,j;
    vector_t view_x, view_y, view_z;
    matrixgl_t view_mat;
    point_t viewpt_in_view_frame;

    view_z = scale_vector( -1, plyr->view.dir );
    view_x = cross_product( plyr->view.up, view_z );
    view_y = cross_product( view_z, view_x );
    normalize_vector( &view_z );
    normalize_vector( &view_x );
    normalize_vector( &view_y );

    make_identity_matrix( plyr->view.inv_view_mat );

    plyr->view.inv_view_mat[0][0] = view_x.x;
    plyr->view.inv_view_mat[0][1] = view_x.y;
    plyr->view.inv_view_mat[0][2] = view_x.z;

    plyr->view.inv_view_mat[1][0] = view_y.x;
    plyr->view.inv_view_mat[1][1] = view_y.y;
    plyr->view.inv_view_mat[1][2] = view_y.z;

    plyr->view.inv_view_mat[2][0] = view_z.x;
    plyr->view.inv_view_mat[2][1] = view_z.y;
    plyr->view.inv_view_mat[2][2] = view_z.z;

    plyr->view.inv_view_mat[3][0] = plyr->view.pos.x;
    plyr->view.inv_view_mat[3][1] = plyr->view.pos.y;
    plyr->view.inv_view_mat[3][2] = plyr->view.pos.z;
    plyr->view.inv_view_mat[3][3] = 1;
    
    transpose_matrix( plyr->view.inv_view_mat, view_mat );

    view_mat[0][3] = 0;
    view_mat[1][3] = 0;
    view_mat[2][3] = 0;
    
    viewpt_in_view_frame = transform_point( view_mat, plyr->view.pos );
    
    view_mat[3][0] = -viewpt_in_view_frame.x;
    view_mat[3][1] = -viewpt_in_view_frame.y;
    view_mat[3][2] = -viewpt_in_view_frame.z;
    
    //glLoadIdentity();

	for( i = 0; i < 4; i++ )
    {
        for( j = 0; j < 4; j++ )
            matrix[i][j] = view_mat[i][j];
    }
    util_set_view(matrix);
}
Ejemplo n.º 30
0
	void Label::render(Compositor* compositor,
						Renderer* renderer,
						gui::render::CommandList& render_commands)
	{
		render_commands.add_rectangle(
			geometry[0],
			geometry[1],
			geometry[2],
			geometry[3],
			render::WhiteTexture,
			background_color
		);

		if (text.empty())
			return;

		const int32_t upper_bound = (LABEL_TOP_MARGIN - font_height);
		const int32_t lower_bound = (LABEL_TOP_MARGIN + size.height + font_height);

		// draw cache items
		float item_offset = 0.0f;
		for (const font_cache_entry& item : font_cache)
		{
			Rect current_rect;
			current_rect.origin = item.origin - scroll_offset;
			current_rect.size = size;

			// Don't draw text above the panel. This shouldn't overlap
			// by more than a single line -- clipping will take care of it.
			if (current_rect.origin.y < upper_bound)
				continue;

			// Don't draw text below the panel. This shouldn't overlap
			// by more than a single line -- clipping will take care of it.
			if ((current_rect.origin.y+item.height) > (lower_bound + item.height))
				break;

			current_rect.origin = transform_point(get_transform(0), current_rect.origin);

			render_commands.add_font(font_handle, &text[item.start], item.length, current_rect, foreground_color);
		}

		//const bool content_larger_than_bounds = content_bounds.height() > size.height;
		//if (content_larger_than_bounds)
		//{
		//	Point start(origin.x, origin.y + content_bounds.height());
		//	Point end(origin.x + size.width, origin.y + content_bounds.height());
		//	render_commands.add_line(start, end, gemini::Color::from_rgba(0, 255, 0, 255));
		//}

		render_children(compositor, renderer, render_commands);
	}