Exemplo n.º 1
0
void keyboard2(unsigned char key, int x, int y) {
	float rotation[16];
	float translation[16];
    float camera_disp = -10.0;
    
    if ( key == 'w' || key == 'a' || key == 's' || key == 'd' || key == ' ') {
		SetTranslation(0.0, 0.0, camera_disp, translation);
		MultiplyMatrix(translation, ViewMatrix, ViewMatrix);
	} else {
		return;
	}
	
	switch(key) {
		case 'w' : SetRotationX(5, rotation); 	
			break;
		case 'a' : SetRotationY(5, rotation);
			break;
		case 's' : SetRotationX(-5, rotation);
			break;
		case 'd' : SetRotationY(-5, rotation);
			break;	
		case ' ' : SetTranslation(0.0, 0.0, camera_disp, ViewMatrix);
			return;	
		default : return;			
	}
	MultiplyMatrix(ViewMatrix, rotation, ViewMatrix);
	SetTranslation(0.0, 0.0,camera_disp * -1, translation);
	MultiplyMatrix(translation, ViewMatrix, ViewMatrix); 
}
Exemplo n.º 2
0
//********************************************
// Copy
//********************************************
void CTransform::Copy(CTransform *pTransform)
{
    SetScale(pTransform->GetScale());
    SetTranslation(pTransform->GetTranslation());
    SetRotation(pTransform->GetRotation());
    SetValueRotation(pTransform->GetValueRotation());
}
Exemplo n.º 3
0
void transform(int i, float rot_offset, float rot_speed, float size,
    float height, float radius, int wobble) {
    float angle = (glutGet(GLUT_ELAPSED_TIME) / 1000.0) * (180/M_PI);
    float RotationMatrixAnim[16];
    float ScaleMatrix[16];
    float InitialTransform[16];
    float scale = 0.001;
    float maxHeight = height + 0.5;
    float minHeight = height - 0.5;
    static int up[OBJECTS];
    static int time[OBJECTS];

    if(wobble == 1) {
        if(up[i] == 0)  height = maxHeight - (time[i]++) * scale;
        else            height = minHeight + (time[i]++) * scale;
        if(time[i] >= 1000) {
            up[i] = (up[i] == 0) ? 1 : 0;
            time[i] = 0;
        }
    }

    SetScaling(size, size, size, ScaleMatrix);

    SetRotationY(rot_speed*angle + rot_offset, RotationMatrixAnim);
    SetTranslation(radius, height, 0, InitialTransform);
    
    MultiplyMatrix(InitialTransform, ScaleMatrix, ModelMatrix[i]);
    MultiplyMatrix(RotationMatrixAnim, ModelMatrix[i], ModelMatrix[i]);
}
Exemplo n.º 4
0
TransformationMatrix::TransformationMatrix(
    const Precision tx, const Precision ty,
    const Precision tz, const Precision phi,
    const Precision theta, const Precision psi) {
  SetTranslation(tx, ty, tz);
  SetRotation(phi, theta, psi);
}
Exemplo n.º 5
0
//********************************************
// Copy
//********************************************
void CTransform::Copy(CTransform &transform)
{
    SetScale(transform.GetScale());
    SetTranslation(transform.GetTranslation());
    SetRotation(transform.GetRotation());
    SetValueRotation(transform.GetValueRotation());
}
Exemplo n.º 6
0
void CModel::Scale( const CVec3 &v ){
	SetTranslation( Translation() * v );
	TransformSurfaces( CMat4::ScaleMatrix( v ) );
	for( CEntity *child=Children();child;child=child->Next() ){
		if( CModel *model=dynamic_cast<CModel*>( child ) ) model->Scale( v );
	}
}
Exemplo n.º 7
0
VECGEOM_CUDA_HEADER_BOTH
TransformationMatrix::TransformationMatrix(TransformationMatrix const &other) {
  SetTranslation(other.Translation(0), other.Translation(1),
                 other.Translation(2));
  SetRotation(other.Rotation(0), other.Rotation(1), other.Rotation(2),
              other.Rotation(3), other.Rotation(4), other.Rotation(5),
              other.Rotation(6), other.Rotation(7), other.Rotation(8));
}
Exemplo n.º 8
0
void CPathCamera::ClampToClosedDoor(CStateManager& mgr) {
  if (TCastToConstPtr<CScriptDoor> door =
          mgr.GetObjectById(mgr.GetCameraManager()->GetBallCamera()->GetTooCloseActorId())) {
    if (!door->IsOpen() && CBallCamera::IsBallNearDoor(GetTranslation(), mgr)) {
      x1d4_pos = (x1d4_pos > x1d8_time) ? x1d8_time - x1dc_lengthExtent : x1d8_time + x1dc_lengthExtent;
      SetTranslation(x188_spline.GetInterpolatedSplinePointByLength(x1d4_pos).origin);
    }
  }
}
Exemplo n.º 9
0
Transformation3D::Transformation3D(
    const Precision tx, const Precision ty,
    const Precision tz, const Precision phi,
    const Precision theta, const Precision psi) :
fIdentity(false), fHasRotation(true), fHasTranslation(true) {
  SetTranslation(tx, ty, tz);
  SetRotation(phi, theta, psi);
  SetProperties();
}
Exemplo n.º 10
0
void GameObject::Update(float dt)
{
	// Do basic physics calcuations based on dt.
	velocity += acceleration * dt;
	position += velocity * dt;

	// Set the translation equal to the new position of the object.
	SetTranslation(position); // Note that this will also recalculate the transformation matrix.
}
Exemplo n.º 11
0
void Transform::TranslateByBasis(glm::vec3 distance)
{
    UpdateTransformMatrix();

    glm::vec3 const rightTranslation = m_rightVector * distance.x;
    glm::vec3 const upTranslation = m_upVector * distance.y;
    glm::vec3 const forwardTranslation = m_direction * distance.z;

    SetTranslation(GetTranslation() + rightTranslation + upTranslation + forwardTranslation);
}
Exemplo n.º 12
0
Transform3::Transform3(const vec3& translation, const quat& rotation)
{
	SetRotation(rotation);
	SetTranslation(translation);
		
	m41 = 0;
	m42 = 0;
	m43 = 0;
	m44 = 1;
}
Exemplo n.º 13
0
Transformation3D::Transformation3D(
    const Precision tx, const Precision ty, const Precision tz,
    const Precision r0, const Precision r1, const Precision r2,
    const Precision r3, const Precision r4, const Precision r5,
    const Precision r6, const Precision r7, const Precision r8) :
fIdentity(false), fHasRotation(true), fHasTranslation(true){
  SetTranslation(tx, ty, tz);
  SetRotation(r0, r1, r2, r3, r4, r5, r6, r7, r8);
  SetProperties();
}
Exemplo n.º 14
0
Matrix4x4::Matrix4x4(const EAngle& angDirection, const Vector& vecPosition)
{
	SetAngles(angDirection);
	SetTranslation(vecPosition);

	m[0][3] = 0;
	m[1][3] = 0;
	m[2][3] = 0;
	m[3][3] = 1;
}
Exemplo n.º 15
0
GLMatrix::GLMatrix(const GLVertex3 & translation)
{
   // Construct matrix with translation components x,y,z:
   //
   // 1 0 0 translation.X()
   // 0 1 0 translation.Y()
   // 0 0 1 translation.Z()
   // 0 0 0 1
   SetIdentity();
   SetTranslation(translation);
}
Exemplo n.º 16
0
GLMatrix::GLMatrix(double x, double y, double z)
{
   // Construct matrix with translation components x,y,z:
   //
   // 1 0 0 x
   // 0 1 0 y
   // 0 0 1 z
   // 0 0 0 1
   SetIdentity();
   SetTranslation(x, y, z);
}
Exemplo n.º 17
0
void MyFigureGlut::InitParameters()
{
  m_pos_x = m_pos_y = m_pos_z = 0.0f;
  m_rot_x = m_rot_y = 0.0f;
  m_zoom = 0.6f;
  m_last_mouse_location = CPoint(-1, -1);
  m_control = false;
  m_shift = false;
  auto_adjust = false;
  SetTranslation(0,0,-10); //my guess where to start
}
Exemplo n.º 18
0
Matrix4x4::Matrix4x4(const Vector& vecForward, const Vector& vecUp, const Vector& vecRight, const Vector& vecPosition)
{
	SetForwardVector(vecForward);
	SetUpVector(vecUp);
	SetRightVector(vecRight);
	SetTranslation(vecPosition);

	m[0][3] = 0;
	m[1][3] = 0;
	m[2][3] = 0;
	m[3][3] = 1;
}
Exemplo n.º 19
0
void GLMatrix::SetTranslation(double x, double y, double z)
{
   // Set matrix translation components x,y,z:
   //
   // . . . x
   // . . . y
   // . . . z
   // . . . .
   //
   // The other components are NOT modified
   SetTranslation(GLVertex3(x,y,z));
}
Exemplo n.º 20
0
void mouse(int button, int state, int x, int y){
	
	float rotation[16];
	float translation[16];
    float camera_disp = -10.0;
	if(button != 0) {return;} 
	
	/* mouse click*/
	if (state == 0) {
		mouse_x = x;
		mouse_y = y;
		return;
	/* mouse release*/	
	} else if ( state == 1) { 
		SetTranslation(0.0, 0.0, camera_disp, translation);
		MultiplyMatrix(translation, ViewMatrix, ViewMatrix);
		
		int diffX = mouse_x - x;
		int diffY = mouse_y - y;
		
		/* right to left or reverse*/
		if (fabs(diffX) > fabs(diffY)) {
			if(diffX < 0) {
				SetRotationY(-5, rotation);
			} else {
				SetRotationY(5, rotation);
			}
		} else {
			if (diffY < 0) {
				SetRotationX(-5, rotation);
			} else {
				 SetRotationX(5, rotation);
			 }
		}
	}
	MultiplyMatrix(ViewMatrix, rotation, ViewMatrix);
	SetTranslation(0.0, 0.0,camera_disp * -1, translation);
	MultiplyMatrix(translation, ViewMatrix, ViewMatrix); 
}
Exemplo n.º 21
0
    void transformCoords() {

        //rotModelX += lapse*0.001;
        for (unsigned i=0;i<objs.size();++i) {
            objs[i].rot_ = Rotation(rotModelX, Real3(0,1,0));
        }

        for (unsigned i=0;i<objs.size();++i) {
            Matrix4 rmx = objs[i].rot_;
            SetTranslation(rmx,objs[i].p_+Real3(0,offY,0));
        
            for (unsigned j=0;j<objs[i].vx_.size();++j) {
                objs[i].tvx_[j] =Matrix4Affine (rmx, objs[i].vx_[j]);
                objs[i].tnormals_[j] = Matrix4Rotate(rmx,objs[i].normals_[j]);
            }
        }
    }
Exemplo n.º 22
0
void MyFigureGlut::SetMesh(PointCloud& pts)
{
  m_mesh=pts;

  // back up viewpoint so we can see points
  {
    Cuboid box;
    GetBoundingBoxOfPoints(pts, &box);
    if(auto_adjust) {
		float zmax = box.max_z;
		// if zmax is too small, the object cannot be displayed.(?????)
		if ( zmax > 0 && zmax < 1) zmax += 1;  //zmax could be zero.
		if ( zmax == 0) zmax += 1.5;  
		SetTranslation(0, 0, -zmax);
	}
  }
}
Exemplo n.º 23
0
void CGeometry::SetObjectMatrix(D3DVECTOR *ObjectRotation,D3DVECTOR *ObjectPosition,D3DVECTOR *CameraPosition)
{
	D3DVECTOR RelVec;

	m_spin = m_identity;
	ConcatenateXRotation(&m_spin, ObjectRotation->x);
	ConcatenateZRotation(&m_spin, ObjectRotation->z);
	ConcatenateYRotation(&m_spin, ObjectRotation->y);

// Calculate position of the object relative to the camera.
	RelVec.x= ObjectPosition->x-CameraPosition->x;
	RelVec.y= ObjectPosition->y-CameraPosition->y;
	RelVec.z= ObjectPosition->z-CameraPosition->z;

// Set the translation in the object matrix.
	SetTranslation(&m_spin,&RelVec);
}
Exemplo n.º 24
0
// Not a true inversion, only works if the matrix is a translation/rotation matrix.
void Matrix4x4::InvertRT()
{
	TAssertNoMsg(fabs(GetForwardVector().LengthSqr() - 1) < 0.00001f);
	TAssertNoMsg(fabs(GetLeftVector().LengthSqr() - 1) < 0.00001f);
	TAssertNoMsg(fabs(GetUpVector().LengthSqr() - 1) < 0.00001f);

	Matrix4x4 t;

	for (int h = 0; h < 3; h++)
		for (int v = 0; v < 3; v++)
			t.m[h][v] = m[v][h];

	Vector vecTranslation = GetTranslation();

	Init(t);

	SetTranslation(t*(-vecTranslation));
}
Exemplo n.º 25
0
	void GameObject::LoadBox()
	{
		SetName("tree");
		auto meshComponent = MeshComponentPtr(
			new MeshComponent(
				MeshManager::Get().GetMesh("tree.mm"),
				PngManager::Get().GetPngTexture("tree.png")
			)
		);

		SetScale(1.f);

		SetRotation(Quaternion(Vector3(0.0f,0.0f,90.0f),0.0f));

		SetTranslation(Vector3(0.0f,0.f,-5.0f));

		AddComponent(meshComponent);

		AddComponent(std::make_shared<Sphere>(Sphere(GetTranslation() + Vector3(0,0.5f,0), Vector3(0, 0, 0), 1.0f, GetScale())));
	}
Exemplo n.º 26
0
	void GameObject::LoadFloor()
	{
		SetName("Floor");
		auto meshComponent = MeshComponentPtr(
			new MeshComponent(
				MeshManager::Get().GetMesh("floor.mm"),
				PngManager::Get().GetPngTexture("MartEngine.png")
			)
		);

		SetScale(10.f);

		SetRotation(Quaternion(Vector3(0.0f, 0.0f, 0.0f), 0.0f));

		SetTranslation(Vector3(0.0f, 5.0f, 0.0f));

		AddComponent(meshComponent);

		//AddComponent(std::make_shared<Plane>(Vector3(0,0,0),Vector3(0,1,0)));
	}
Exemplo n.º 27
0
void CPathCamera::Think(float dt, CStateManager& mgr) {
  if (!GetActive())
    return;

  if (mgr.GetCameraManager()->GetPathCameraId() != GetUniqueId())
    return;

  if (x188_spline.GetSize() <= 0)
    return;

  zeus::CTransform xf = GetTransform();
  zeus::CVector3f ballLook = mgr.GetCameraManager()->GetBallCamera()->GetLookPos();
  if ((x1ec_flags & 0x10)) {
    if (const CScriptCameraHint* hint = mgr.GetCameraManager()->GetCameraHint(mgr))
      ballLook.z() = hint->GetTranslation().z();
  }

  if (!mgr.GetPlayer().GetVelocity().canBeNormalized() && (ballLook - GetTranslation()).canBeNormalized()) {
    if (x1ec_flags & 4)
      SetTransform(x188_spline.GetInterpolatedSplinePointByLength(x1d4_pos));
    else
      SetTransform(zeus::lookAt(GetTranslation(), ballLook));
    return;
  }

  xf = MoveAlongSpline(dt, mgr);
  SetTranslation(xf.origin);

  if (x1ec_flags & 0x20)
    ClampToClosedDoor(mgr);

  zeus::CVector3f tmp = ballLook - GetTranslation();
  tmp.z() = 0.f;
  if (tmp.canBeNormalized())
    SetTransform(zeus::lookAt(GetTranslation(), ballLook));

  if (x1ec_flags & 4)
    SetTransform(xf);
}
Exemplo n.º 28
0
// The scene object class constructor.
SceneObject::SceneObject( unsigned long type, char *meshName, char *meshPath, bool sharedMesh )
{
	// Set object's type
	SetType( type );

	// Zero scene object's translation and rotation.
	SetTranslation( 0.0f, 0.0f, 0.0f );
	SetRotation( 0.0f, 0.0f, 0.0f );

	// Set object at rest.
	SetVelocity( 0.0f, 0.0f, 0.0f );
	SetSpin( 0.0f, 0.0f, 0.0f );

	// Object is initially facing into the positive z-axis.
	m_forward = D3DXVECTOR3( 0.0f, 0.0f, 1.0f );
	m_right = D3DXVECTOR3( 1.0f, 0.0f, 0.0f );

	// Initially the object has no friction.
	m_friction = 0.0f;

	// Clear the collision stamp.
	m_collisionStamp = -1;

	// Object is visible, enabled, solid, and registering collisons by default.
	m_visible = true;
	m_enabled = true;
	m_ghost = false;
	m_ignoreCollisions = false;

	// Initially the object is not touching the ground.
	m_touchingGround = false;

	// Set the object's mesh.
	m_mesh = NULL;
	SetMesh( meshName, meshPath, sharedMesh );

}
Exemplo n.º 29
0
//same as SetPoints except for x,y scaling
void MyFigureGlut::SetDepthPoints(PointCloud& pts, int win_width, int win_height)
{
  PointCloud::ConstIterator p = pts.Begin();
  ColoredPoint temp;
  int cnt=0;
  float x_full, y_full;
  x_full=pts.Max().x - pts.Min().x;
  y_full=pts.Max().y - pts.Min().y;

	while(p != pts.End())
	{
		if(p->x != 0)
		{
			temp.x=(float)(((float(cnt%win_width))*x_full)/win_width) + pts.Min().x;
			temp.y=(float)(((float(cnt/win_width))*y_full)/win_height) + pts.Min().y;
			temp.z=(*p).z;
			temp.color=(*p).color;
			m_pts.Add(temp);
		}
		p++;
		cnt++;
	}

  // back up viewpoint so we can see points
  {
    Cuboid box;
    GetBoundingBoxOfPoints(pts, &box);
    if(auto_adjust) {
		float zmax = box.max_z;
		// if zmax is too small, the object cannot be displayed.(?????)
		if ( zmax > 0 && zmax < 1) zmax += 1;  //zmax could be zero.
		if ( zmax == 0) zmax += 1.5;  
		SetTranslation(0, 0, -zmax);
	}
  }
}
Exemplo n.º 30
0
TransformationMatrix::TransformationMatrix() {
  SetTranslation(0, 0, 0);
  SetRotation(1, 0, 0, 0, 1, 0, 0, 0, 1);
}