예제 #1
0
Vec3
Camera::viewToWorld(const Vec3& p) const
//[]---------------------------------------------------[]
//|  Transform view coordinates in world coordinates.   |
//[]---------------------------------------------------[]
{
	Transf3 invVTM;

	VTM.inverse(invVTM);
	return invVTM.transform(p);
}
예제 #2
0
void
Camera::rotateYX(REAL ay, REAL ax)
//[]---------------------------------------------------[]
//|  Rotate YX.                                         |
//|                                                     |
//|  Composition of an azimuth of ay with an elavation  |
//|  of ax (in degrees).                                |
//[]---------------------------------------------------[]
{
	if (Math::isZero(ay))
	{
		elevation(ax);
		return;
	}

	Transf3 r;
	
	r.rotation(focalPoint, viewUp, Math::toRadians<REAL>(ay));
	if (!Math::isZero(ax))
	{
		Vec3 axis = directionOfProjection.cross(viewUp);
		Transf3 q;
		
		q.rotation(focalPoint, axis, Math::toRadians<REAL>(ax));
		q.transformVectorRef(viewUp);
		r.compose(q);
	}
	r.transformRef(position);
	updateDOP();
}
예제 #3
0
void
Camera::yaw(REAL angle)
//[]---------------------------------------------------[]
//|  Yaw.                                               |
//|                                                     |
//|  Rotate the focal point about the view up vector    |
//|  centered at the camera's position.                 |
//[]---------------------------------------------------[]
{
	if (!Math::isZero(angle))
	{
		Transf3 r;

		r.rotation(position, viewUp, Math::toRadians<REAL>(angle));
		r.transformRef(focalPoint);
		updateDOP();
	}
}
예제 #4
0
void
Camera::roll(REAL angle)
//[]---------------------------------------------------[]
//|  Roll.                                              |
//|                                                     |
//|  Rotate the view up vector around the view plane    |
//|  normal                                             |
//[]---------------------------------------------------[]
{
	if (!Math::isZero(angle))
	{
		Transf3 r;

		r.rotation(directionOfProjection, -Math::toRadians<REAL>(angle));
		r.transformVectorRef(viewUp);
		viewModified = true;
	}
}
예제 #5
0
void
Camera::azimuth(REAL angle)
//[]---------------------------------------------------[]
//|  Azimuth.                                           |
//|                                                     |
//|  Rotate the camera's position about the view up     |
//|  vector centered at the focal point.                |
//[]---------------------------------------------------[]
{
	if (!Math::isZero(angle))
	{
		Transf3 r;

		r.rotation(focalPoint, viewUp, Math::toRadians<REAL>(angle));
		r.transformRef(position);
		updateDOP();
	}
}
예제 #6
0
void
Camera::pitch(REAL angle)
//[]---------------------------------------------------[]
//|  Pitch.                                             |
//|                                                     |
//|  Rotate the focal point about the cross product of  |
//|  the view up vector and the view plane normal       |
//|  centered at the camera's position.                 |
//[]---------------------------------------------------[]
{
	if (!Math::isZero(angle))
	{
		Vec3 axis = directionOfProjection.cross(viewUp);
		Transf3 r;

		r.rotation(position, axis, Math::toRadians<REAL>(angle));
		r.transformRef(focalPoint);
		updateDOP();
		viewUp = axis.cross(directionOfProjection);
	}
}
예제 #7
0
void
Camera::elevation(REAL angle)
//[]---------------------------------------------------[]
//|  Elevation.                                         |
//|                                                     |
//|  Rotate the camera's position about the cross       |
//|  product of the view plane normal and the view up   |
//|  vector centered at the focal point.                |
//[]---------------------------------------------------[]
{
	if (!Math::isZero(angle))
	{
		Vec3 axis = directionOfProjection.cross(viewUp);
		Transf3 r;

		r.rotation(focalPoint, axis, Math::toRadians<REAL>(angle));
		r.transformRef(position);
		updateDOP();
		viewUp = axis.cross(directionOfProjection);
	}
}
예제 #8
0
static void
createRGBCube()
{
  // Create the model
  TriangleMeshShape* t = MeshSweeper::makeCube();
  Color* c = new Color[8];

  c[0] = Color::blue;
  c[1] = Color::magenta;
  c[2] = Color::white;
  c[3] = Color::cyan;
  c[4] = Color::black;
  c[5] = Color::red;
  c[6] = Color::yellow;
  c[7] = Color::green;
  t->setColors(c, 8);
  // Create an actor from model and add it into the scene
  scene->addActor(new Actor(*t));
  mesh = t;

  // Set model transformation matrix
  REAL a = Math::toRadians<REAL>(5);

  MTM.rotationY(a);

  Transf3 temp;

  temp.rotationX(a);
  MTM.compose(temp);
  temp.rotationZ(a);
  MTM.compose(temp);
}
예제 #9
0
	void setViewTransform(Transf3& VTM)
	{
		VTM.setRow(0, u.x, u.y, u.z, -(O.inner(u)));
		VTM.setRow(1, v.x, v.y, v.z, -(O.inner(v)));
		VTM.setRow(2, n.x, n.y, n.z, -(O.inner(n)));
	}
예제 #10
0
/*
TriangleMeshShape*
MeshSweeper::makeCone(const Vec3& center,
  REAL radius,
  const Vec3& normal,
  REAL height,
  int segments)
//[]----------------------------------------------------[]
//|  Make cylinder                                       |
//[]----------------------------------------------------[]
{
  Polyline circle = makeCircle(center, radius, normal, segments);

  return makeCone(circle, normal * -height);
}
*/
TriangleMeshShape*
MeshSweeper::makeSphere(const Vec3& center, REAL radius, int mers)
//[]----------------------------------------------------[]
//|  Make sphere                                         |
//[]----------------------------------------------------[]
{
  if (mers < 6)
    mers = 6;

  int sections = mers;
  int nv = sections * mers + 2; // number of vertices (and normals)
  int nt = 2 * mers * sections; // number of triangles
  TriangleMesh::Arrays data;

  data.vertices = new Vec3[data.numberOfVertices = nv];
  data.normals = new Vec3[data.numberOfNormals = nv];
  data.triangles = new TriangleMesh::Triangle[data.numberOfTriangles = nt];
  {
    Polyline arc = makeArc(center, radius, Vec3(0, 0, 1), 180, sections + 1);
    Polyline::VertexIterator vit = arc.getVertexIterator();
    Transf3 rot;
    Vec3* vertex = data.vertices;
    Vec3* normal = data.normals;
    REAL invRadius = Math::inverse<REAL>(radius);

    *normal = ((*vertex = (vit++).position) - center) * invRadius;
    rot.rotation(center, *normal, Math::toRadians<REAL>(360) / mers);
    vertex++;
    normal++;
    for (int s = 0; s < sections; s++)
    {
      Vec3 p = *vertex = (vit++).position;

      *normal = (p - center) * invRadius;
      vertex++;
      normal++;
      for (int m = 1; m < mers; m++)
      {
        *vertex = rot.transformRef(p);
        *normal = (p - center) * invRadius;
        vertex++;
        normal++;
      }
    }
    *normal = ((*vertex = (vit++).position) - center) * invRadius;
  }

  TriangleMesh::Triangle* triangle = data.triangles;

  for (int i = 1; i <= mers; i++)
  {
    int j = i % mers + 1;

    triangle->setVertices(0, i, j);
    triangle->setNormals(0, i, j);
    triangle++;
  }
  for (int s = 1; s < sections; s++)
    for (int m = 0, b = (s - 1) * mers + 1; m < mers;)
    {
      int i = b + m;
      int k = b + ++m % mers;
      int j = i + mers;
      int l = k + mers;

      triangle->setVertices(i, j, k);
      triangle->setNormals(i, j, k);
      triangle[1].setVertices(k, j, l);
      triangle[1].setNormals(k, j, l);
      triangle += 2;
    }
  for (int m = 0, b = (sections - 1) * mers + 1, j = nv - 1; m < mers;)
  {
    int i = b + m;
    int k = b + ++m % mers;

    triangle->setVertices(i, j, k);
    triangle->setNormals(i, j, k);
    triangle++;
  }
  return new TriangleMeshShape(data);
}