Exemple #1
0
Matrix3x2 SliceRenderer::calculateFacingRotationMatrix() {
	assert(_sliceFramePtr);

	Vector3 viewPos = _view->_sliceViewMatrix * _position;
	float dir = atan2(viewPos.x, viewPos.z) + _facing;
	float s = sin(dir);
	float c = cos(dir);

	Matrix3x2 mRotation(c, -s, 0.0f,
	                    s,  c, 0.0f);

	Matrix3x2 mView(_view->_sliceViewMatrix(0,0), _view->_sliceViewMatrix(0,1), 0.0f,
	                _view->_sliceViewMatrix(2,0), _view->_sliceViewMatrix(2,1), 0.0f);

	return mView * mRotation;
}
void GCamera::buildViewMatrix()
{
	XMVECTOR vecLookW = XMVector3Normalize(GMathFV(mLook));
	XMVECTOR vecRightW = XMVector3Normalize(XMVector3Cross(GMathFV(mUp), vecLookW));
	XMVECTOR vecUpW = XMVector3Normalize(XMVector3Cross(vecLookW, vecRightW));
	XMVECTOR vecPosW = GMathFV(mPosition);





	float x = -GMathVF(XMVector3Dot(vecPosW, vecRightW)).x;
	float y = -GMathVF(XMVector3Dot(vecPosW, vecUpW)).x;
	float z = -GMathVF(XMVector3Dot(vecPosW, vecLookW)).x;
	mRight = GMathVF(vecRightW);
	mUp = GMathVF(vecUpW);
	mLook = GMathVF(vecLookW);

	mView(0, 0) = mRight.x;
	mView(1, 0) = mRight.y;
	mView(2, 0) = mRight.z;
	mView(3, 0) = x;

	mView(0, 1) = mUp.x;
	mView(1, 1) = mUp.y;
	mView(2, 1) = mUp.z;
	mView(3, 1) = y;

	mView(0, 2) = mLook.x;
	mView(1, 2) = mLook.y;
	mView(2, 2) = mLook.z;
	mView(3, 2) = z;

	mView(0, 3) = 0.0f;
	mView(1, 3) = 0.0f;
	mView(2, 3) = 0.0f;
	mView(3, 3) = 1.0f;



}
void Camera::UpdateViewMatrix()
{
	XMVECTOR R = XMLoadFloat3(&mRight);
	XMVECTOR U = XMLoadFloat3(&mUp);
	XMVECTOR L = XMLoadFloat3(&mLook);
	XMVECTOR P = XMLoadFloat3(&mPosition);

	// Keep camera's axes orthogonal to each other and of unit length.
	L = XMVector3Normalize(L);
	U = XMVector3Normalize(XMVector3Cross(L, R));

	// U, L already ortho-normal, so no need to normalize cross product.
	R = XMVector3Cross(U, L); 

	// Fill in the view matrix entries.
	float x = -XMVectorGetX(XMVector3Dot(P, R));
	float y = -XMVectorGetX(XMVector3Dot(P, U));
	float z = -XMVectorGetX(XMVector3Dot(P, L));

	XMStoreFloat3(&mRight, R);
	XMStoreFloat3(&mUp, U);
	XMStoreFloat3(&mLook, L);

	mView(0,0) = mRight.x; 
	mView(1,0) = mRight.y; 
	mView(2,0) = mRight.z; 
	mView(3,0) = x;   

	mView(0,1) = mUp.x;
	mView(1,1) = mUp.y;
	mView(2,1) = mUp.z;
	mView(3,1) = y;  

	mView(0,2) = mLook.x; 
	mView(1,2) = mLook.y; 
	mView(2,2) = mLook.z; 
	mView(3,2) = z;   

	mView(0,3) = 0.0f;
	mView(1,3) = 0.0f;
	mView(2,3) = 0.0f;
	mView(3,3) = 1.0f;

	mSphereCollider.Center = mPosition;
}
void Camera::rebuildView()
{
    // Keep camera's axes orthogonal to each other and of unit length.
    D3DXVec3Normalize(&mLook, &mLook);

    D3DXVec3Cross(&mUp, &mLook, &mRight);
    D3DXVec3Normalize(&mUp, &mUp);

    D3DXVec3Cross(&mRight, &mUp, &mLook);
    D3DXVec3Normalize(&mRight, &mRight);

    // Fill in the view matrix entries.
    float x = -D3DXVec3Dot(&mPosition, &mRight);
    float y = -D3DXVec3Dot(&mPosition, &mUp);
    float z = -D3DXVec3Dot(&mPosition, &mLook);

    mView(0,0) = mRight.x;
    mView(1,0) = mRight.y;
    mView(2,0) = mRight.z;
    mView(3,0) = x;

    mView(0,1) = mUp.x;
    mView(1,1) = mUp.y;
    mView(2,1) = mUp.z;
    mView(3,1) = y;

    mView(0,2) = mLook.x;
    mView(1,2) = mLook.y;
    mView(2,2) = mLook.z;
    mView(3,2) = z;

    mView(0,3) = 0.0f;
    mView(1,3) = 0.0f;
    mView(2,3) = 0.0f;
    mView(3,3) = 1.0f;
}
Exemple #5
0
void Camera:: UpdateViewMatrix()
{
    XMVECTOR R = XMLoadFloat3(&mRight);
    XMVECTOR U = XMLoadFloat3(&mUp);
    XMVECTOR L = XMLoadFloat3(&mLook);
    XMVECTOR P = XMLoadFloat3(&mPosition);

    //
    // Orthonormalize the right, up and look vectors.
    //
    // Make look vector unit length.
    L = XMVector3Normalize(L);

    // Compute a new corrected "up" vector and normalize it.
    U = XMVector3Normalize(XMVector3Cross(L, R));

    // Compute a new corrected "right" vector. U and L are
    // already ortho-normal, so no need to normalize cross product.
    // ||up × look|| = ||up|| ||look|| sin90° = 1
    R = XMVector3Cross(U, L);

    //
    // Fill in the view matrix entries.
    //
    float x = -XMVectorGetX(XMVector3Dot(P, R));
    float y = -XMVectorGetX(XMVector3Dot(P, U));
    float z = -XMVectorGetX(XMVector3Dot(P, L));

    XMStoreFloat3(&mRight, R);
    XMStoreFloat3(&mUp, U);
    XMStoreFloat3(&mLook, L);

    mView(0,0) = mRight.x;
    mView(1,0) = mRight.y;
    mView(2,0) = mRight.z;
    mView(3,0) = x;
    mView(0,1) = mUp.x;
    mView(1,1) = mUp.y;
    mView(2,1) = mUp.z;
    mView(3,1) = y;
    mView(0,2) = mLook.x;
    mView(1,2) = mLook.y;
    mView(2,2) = mLook.z;
    mView(3,2) = z;
    mView(0,3) = 0.0f;
    mView(1,3) = 0.0f;
    mView(2,3) = 0.0f;
    mView(3,3) = 1.0f;
}
Exemple #6
0
void Camera::UpdateMatrix()
{
	D3DXVECTOR3 R = mRight;
	D3DXVECTOR3 U = mUp;
	D3DXVECTOR3 L = mLook;
	D3DXVECTOR3 P = mPosition;

	D3DXVec3Normalize(&L, &L);
	D3DXVECTOR3 temp;
	D3DXVec3Cross(&temp, &L, &R);
	D3DXVec3Normalize(&U, &temp);
	D3DXVec3Cross(&R, &U, &L);

	
	float x = -D3DXVec3Dot(&P, &R);
	float y = -D3DXVec3Dot(&P, &U);
	float z = -D3DXVec3Dot(&P, &L);

	mRight = R;
	mUp = U;
	mLook = L;

	mView(0, 0) = mRight.x;
	mView(1, 0) = mRight.y;
	mView(2, 0) = mRight.z;
	mView(3, 0) = x;

	mView(0, 1) = mUp.x;
	mView(1, 1) = mUp.y;
	mView(2, 1) = mUp.z;
	mView(3, 1) = y;

	mView(0, 2) = mLook.x;
	mView(1, 2) = mLook.y;
	mView(2, 2) = mLook.z;
	mView(3, 2) = z;

	mView(0, 3) = 0.0f;
	mView(1, 3) = 0.0f;
	mView(2, 3) = 0.0f;
	mView(3, 3) = 1.0f;
}