Пример #1
0
void Camera::LocalRotate( float x, float y )
{
	Matrix4 viewSpaceRotation;
	MakeRotationMatrixX(viewSpaceRotation, x);
	
	Matrix4 viewSpaceRotationY;
	MakeRotationMatrixY(viewSpaceRotationY, y);

	MatrixMultiply(viewSpaceRotation, viewSpaceRotation, viewSpaceRotationY);

	Vector4& newViewDirection = viewSpaceRotation.Transform(Vector3(0.0f, 0.0f, 1.0f));

	Matrix4 cameraRotation = GetViewMatrix();
	cameraRotation.m41 = cameraRotation.m42 = cameraRotation.m43 = 0.0f;

	Matrix4 inverseCameraRotation;
	MatrixTranspose(inverseCameraRotation, cameraRotation);

	Vector4& newWorldSpaceViewDir = inverseCameraRotation.Transform(newViewDirection);

	Vector3 newWorldSpaceViewDir3;
	newWorldSpaceViewDir3.x = newWorldSpaceViewDir.x;
	newWorldSpaceViewDir3.y = newWorldSpaceViewDir.y;
	newWorldSpaceViewDir3.z = newWorldSpaceViewDir.z;
	newWorldSpaceViewDir3.Normalize();

	m_position = m_lookAt - newWorldSpaceViewDir3 * m_distanceToLookAt;

	Vector3 right = m_up.Cross(newWorldSpaceViewDir3);
	m_up = newWorldSpaceViewDir3.Cross(right);
	m_up.Normalize();

	m_viewMatrixDirty = true;
}
Пример #2
0
	Vector3 Vector3::DirectionVector(const Vector3 &up, float rotX, float rotY, float rotZ)
	{
		Matrix4 rotMat = Matrix4::RotationYPRMatrix(rotY, rotX, rotZ);
		Vector3 invUp = -up;

		return rotMat.Transform(invUp);
	}
Пример #3
0
        TestScene * CreateTestScene5(ViewSettings & viewSettings, String baseDir)
        {
            auto rs = CreateTestSceneFromModel(viewSettings, baseDir + L"/warehouse/ep2_indoor.obj");
            Matrix4 modelView;
            float transformMatrix[] = { -0.669132f, 0.023659f, -0.742766f, 0.000000f,
                                        0.000000f, 0.999493f, 0.031837f, 0.000000f,
                                        0.743143f, 0.021303f, -0.668793f, 0.000000f,
                                        -7027.120605f, 1115.192993f, 6001.621094f, 1.000000f };
            for (int i = 0; i < 16; i++)
                modelView.values[i] = transformMatrix[i];
            Matrix4 flip;
            Matrix4::CreateIdentityMatrix(flip);
            flip.m[1][1] = 0.0f;
            flip.m[1][2] = -1.0f;
            flip.m[2][1] = 1.0f;
            flip.m[2][2] = 0.0f;
            Matrix4 flipped;
            Matrix4::Multiply(flipped, modelView, flip);
            modelView = flipped;
            rs->State.SetModelViewTransform(modelView);

            auto shader = new LightingShader();

            Light light;
            Vec3 lightPos = Vec3(282.73f, -9336.99f, -1269.75f);
            modelView.Transform(light.Position, lightPos);
            light.Ambient = 0.2f;
            light.Color = Vec3(1.65f, 1.65f, 1.70f);
            light.Decay = 850.0f;
            shader->Lights.Add(light);

            lightPos = Vec3(-196.555801f, -9157.416992f, -1255.329346f);
            modelView.Transform(light.Position, lightPos);
            light.Ambient = 0.0f;
            light.Color = Vec3(1.5f, 0.5f, 0.28f);
            light.Decay = 400.0f;
            shader->Lights.Add(light);

            rs->SetShader(shader);

            return rs;
        }
Пример #4
0
bool IMesh::TryUpdateVertex(VertexGraphicsBuffer& bufferObject, size_t vertexIndex, const ICollection<Point3F>& vertices, const Matrix4& matrix) const
{
	RETURN_TRUE_IF_EMPTY(vertices);
	bufferObject.ReserveSize(vertexIndex, vertices.Count());

	size_t count = vertices.Count();
	const Point3F* verticesPtr = vertices.Items();
	FOR_EACH_SIZE(i, count)
	{
		Point3F pos = matrix.Transform(verticesPtr[i]);
		bufferObject.AppendOrUpdateData(vertexIndex + i, pos);
	}
Пример #5
0
	Vector3F Viewport::Project(const Vector3F &source, const Matrix4 &projection, const Matrix4 &view, const Matrix4 &world)
	{
		Matrix4 mat = world * view * projection; // Matrix4::Multiply(Matrix4.Multiply(world, view), projection);		
		Vector3F vector;
		mat.Transform(source, vector); // Vector3F::Transform(source, mat);
		float a = (((source.x * mat.a14) + (source.y * mat.a24)) + (source.z * mat.a34)) + mat.a44;
		if (!WithinEpsilon(a, 1.0f))
		{
			vector = (Vector3F) (vector / a);
		}
		vector.x = (((vector.x + 1.0f) * 0.5f) * m_Width) + m_X;
		vector.y = (((-vector.y + 1.0f) * 0.5f) * m_Height) + m_Y;
		vector.z = (vector.z * (m_fFarClipPlane - m_fNearClipPlane)) + m_fNearClipPlane;
		return vector;
	}
Пример #6
0
	Vector3F Viewport::Unproject(const Vector3F &source, const Matrix4 &projection, const Matrix4 &view, const Matrix4 &world)
	{
		Vector3F vector = source;
		Matrix4 mat = (world * view * projection).Invert(); //Matrix4.Invert(Matrix4.Multiply(Matrix4.Multiply(world, view), projection));
		vector.x = (((source.x - m_X) / ((float) m_Width)) * 2.0f) - 1.0f;
		vector.y = -((((source.y - m_Y) / ((float) m_Height)) * 2.0f) - 1.0f);
		vector.z = (source.z - m_fNearClipPlane) / (m_fFarClipPlane - m_fNearClipPlane);

		mat.Transform(source, vector); // Vector3F.Transform(source, mat);
		float a = (((source.x * mat.a14) + (source.y * mat.a24)) + (source.z * mat.a34)) + mat.a44;
		if (!WithinEpsilon(a, 1.0f))
		{
			vector = (Vector3F) (vector / a);
		}
		return vector;
	}
Пример #7
0
void Camera::LocalMove( float x, float y, float z )
{
	Matrix4 rotationMatrix = GetViewMatrix();
	rotationMatrix.m41 = rotationMatrix.m42 = rotationMatrix.m43 = 0.0f;

	Matrix4 inverseRotationMatrix;
	MatrixTranspose(inverseRotationMatrix, rotationMatrix);

	Vector4 worldSpaceOffset = inverseRotationMatrix.Transform(Vector4(x, y, z, 1.0f));

	m_position.x += worldSpaceOffset.x;
	m_position.y += worldSpaceOffset.y;
	m_position.z += worldSpaceOffset.z;

	m_lookAt.x += worldSpaceOffset.x;
	m_lookAt.y += worldSpaceOffset.y;
	m_lookAt.z += worldSpaceOffset.z;

	m_viewMatrixDirty = true;
}