VOID UpdateViewMatrix()
{
    XMVECTOR vCameraPos = XMLoadFloat4A( &g_CameraPos );
    XMVECTOR vCameraTarget = vCameraPos * XMVectorSet( 1, 0, 1, 1 );
    XMMATRIX matView = XMMatrixLookAtLH( vCameraPos, vCameraTarget, XMVectorSet( 0, 0, 1, 0 ) );
    XMStoreFloat4x4A( &g_matView, matView );
}
void CameraClass::Render(){
	XMFLOAT3 f3_lookAt;
	XMVECTOR up, position, lookAt;
	float yaw, pitch, roll, radians;
	XMMATRIX rotationMatrix;

	// set "up vector"
	up = XMLoadFloat3(&XMFLOAT3(0.0f, 1.0f, 0.f));

	// setup camera's world position
	position = XMLoadFloat3(&XMFLOAT3(m_positionX, m_positionY, m_positionZ));

	//BIGCHANGES
	
	// set default lookAt
	lookAt = XMLoadFloat3(&XMFLOAT3(0.0f, 0.0f, 1.0f));

	// set yaw (Y axis), pitch (X axis), and roll (Z axis) rotations in radians
	pitch = m_rotationX * 0.0174532925f;
	yaw	  = m_rotationY * 0.0174532925f;
	roll  = m_rotationZ * 0.0174532925f;

	// create rotation matrix from yaw, pitch, roll values
	rotationMatrix = XMMatrixRotationRollPitchYaw(yaw, pitch, roll);

	// Transform the lookAt and up vector by the rotation matrix so the view is correctly rotated at the origin.
	lookAt = XMVector3TransformCoord(lookAt, rotationMatrix);
	up = XMVector3TransformCoord(up, rotationMatrix);

	// Translate the rotated camera position to the location of the viewer.
	lookAt = position + lookAt;

	// Finally create the view matrix from the three updated vectors.
	m_viewMatrix = XMMatrixLookAtLH(position, lookAt, up);
}
void CameraClass::RenderBaseViewMatrix()
{
	XMFLOAT3 f3_lookAt;
	XMVECTOR up, position, lookAt;
	float yaw, pitch, roll;
	XMMATRIX rotationMatrix;


	// Setup the vector that points upwards.
	up = XMLoadFloat3(&XMFLOAT3(0.0f, 1.0f, 0.0f));

	// Setup the position of the camera in the world.
	position = XMLoadFloat3(&XMFLOAT3(m_positionX, m_positionY, m_positionZ));

	// Setup where the camera is looking by default.
	lookAt = XMLoadFloat3(&XMFLOAT3(0.0f, 0.0f, 1.0f));

	// Set the yaw (Y axis), pitch (X axis), and roll (Z axis) rotations in radians.
	pitch = m_rotationX * 0.0174532925f;
	yaw   = m_rotationY * 0.0174532925f;
	roll  = m_rotationZ * 0.0174532925f;

	// Create the rotation matrix from the yaw, pitch, and roll values.
	rotationMatrix = XMMatrixRotationRollPitchYaw(yaw, pitch, roll);

	// Transform the lookAt and up vector by the rotation matrix so the view is correctly rotated at the origin.
	lookAt = XMVector3TransformCoord(lookAt, rotationMatrix);
	up = XMVector3TransformCoord(up, rotationMatrix);

	// Translate the rotated camera position to the location of the viewer.
	lookAt = position + lookAt;

	// Finally create the base view matrix from the three updated vectors.
	m_baseViewMatrix = XMMatrixLookAtLH(position, lookAt, up);
}
void TexColumnApp::UpdateScene(float dt)
{
	// Convert Spherical to Cartesian coordinates.
	float x = mRadius*sinf(mPhi)*cosf(mTheta);
	float z = mRadius*sinf(mPhi)*sinf(mTheta);
	float y = mRadius*cosf(mPhi);

	mEyePosW = XMFLOAT3(x, y, z);

	// Build the view matrix.
	XMVECTOR pos    = XMVectorSet(x, y, z, 1.0f);
	XMVECTOR target = XMVectorZero();
	XMVECTOR up     = XMVectorSet(0.0f, 1.0f, 0.0f, 0.0f);

	XMMATRIX V = XMMatrixLookAtLH(pos, target, up);
	XMStoreFloat4x4(&mView, V);

	//
	// Switch the number of lights based on key presses.
	//
	if( GetAsyncKeyState('0') & 0x8000 )
		mLightCount = 0; 

	if( GetAsyncKeyState('1') & 0x8000 )
		mLightCount = 1; 

	if( GetAsyncKeyState('2') & 0x8000 )
		mLightCount = 2; 

	if( GetAsyncKeyState('3') & 0x8000 )
		mLightCount = 3; 
}
Beispiel #5
0
void CameraHandler::Frame(float dt, InputHandler* inputH, GroundModel* model)
{
	XMVECTOR lookAt = XMVectorSet(0.0f, 0.0f, 1.0f, 0.0f);
	XMVECTOR camRight = XMVectorSet(1.0f, 0.0f, 0.0f, 0.0f);
	XMVECTOR camUp = XMVectorSet(0.0f, 1.0f, 0.0f, 0.0f);

	//Get input from keyboard and mouse movement to change camera values
	this->updateCamera(dt, inputH, model);

	this->camRotationMatrix = XMMatrixRotationRollPitchYaw(this->camPitch, this->camYaw, 0);

	lookAt = XMVector3TransformCoord(lookAt, this->camRotationMatrix);

	lookAt = XMVector3Normalize(lookAt);

	camRight = XMVector3TransformCoord(camRight, this->camRotationMatrix);
	camUp = XMVector3TransformCoord(camUp, this->camRotationMatrix);

	
	//Set new camPos
	this->camPos += this->moveLeftRight * camRight;
	this->camPos += this->moveBackForward * lookAt;
	this->camPos += this->moveUpDown * camUp;

	//Reset
	this->moveLeftRight = 0.0f;
	this->moveBackForward = 0.0f;
	this->moveUpDown = 0.0f;

	lookAt = this->camPos + lookAt;

	this->viewMatrix = XMMatrixLookAtLH(this->camPos, lookAt, camUp);

	return;
}
Beispiel #6
0
void Camera::UpdateCamera()
{
	camRotationMatrix = XMMatrixRotationRollPitchYaw(camPitch, camYaw, 0);		//Updates the rotation matrix in pitch and yaw
	camTarget = XMVector3TransformCoord(DefaultForward, camRotationMatrix);		//Updates the target with the NEW rotation matrix
	camTarget = XMVector3Normalize(camTarget);									//Normalizing

	Matrix RotateYTempMatrix;
	RotateYTempMatrix = XMMatrixRotationY(camYaw);								//To keep our camera's forward and right vectors pointing only in the x and z axis

	camRight = XMVector3TransformCoord(DefaultRight, RotateYTempMatrix);		//Transforms the vector using the RotateYTempMatrix
	camUp = XMVector3TransformCoord(camUp, RotateYTempMatrix);					//Transforms the vector using the RotateYTempMatrix
	camForward = XMVector3TransformCoord(DefaultForward, RotateYTempMatrix);	//Transforms the vector using the RotateYTempMatrix

	camPosition += moveLeftRight*camRight;										//Calculates the cameras NEW position in the right and left position
	camPosition += moveBackForward*camForward;									//Calculates the cameras NEW position in the back and forward position

	moveLeftRight = 0.0f;														//Resets the movement
	moveBackForward = 0.0f;														//Resets the movement

	camTarget = camPosition + camTarget;										//Adds the position with the target

	fbxPtr->test.camPos = camPosition;

	camView = XMMatrixLookAtLH(camPosition, camTarget, camUp);					//Stores the NEW View Matrix
}
void RenderSystem::init_camera()
{
	//Viewport Infomation
	D3D11_VIEWPORT vp;
	ZeroMemory(&vp, sizeof(D3D11_VIEWPORT));
	vp.TopLeftX = 0;
	vp.TopLeftY = 0;
	vp.MinDepth = 0.0f;
	vp.MaxDepth = 1.0f;
	vp.Width    = m_ScreenWidth;
	vp.Height   = m_ScreenHeight;
	m_pD3D11DeviceContext->RSSetViewports(1, &vp);

	//MVP Matrix
	XMVECTOR camPos    = XMVectorSet(0.0f,  5.0f, -8.0f, 0.0f);
	XMVECTOR camTarget = XMVectorSet( 0.0f, 0.0f, 0.0f, 0.0f );
	XMVECTOR camUp     = XMVectorSet( 0.0f, 1.0f, 0.0f, 0.0f );
	XMMATRIX View      = XMMatrixLookAtLH( camPos, camTarget, camUp );
	XMMATRIX Model     = XMMatrixIdentity();
	XMMATRIX Proj      = XMMatrixPerspectiveFovLH(0.4f*3.14f, GetAspect(), 1.0f, 1000.0f);

	XMStoreFloat4x4(&m_Proj, XMMatrixTranspose(Proj));
	XMStoreFloat4x4(&m_Model, XMMatrixTranspose(Model) );
	XMStoreFloat4x4(&m_View, XMMatrixTranspose(View) );

}
Beispiel #8
0
	void CubeObject::UpdateConstantBuffer() {
		//行列の定義
		Mat4x4 World, View, Proj;
		//ワールド行列の決定
		World.affineTransformation(
			m_Scale,			//スケーリング
			Vec3(0, 0, 0),		//回転の中心(重心)
			m_Qt,				//回転角度
			m_Pos				//位置
		);
		//転置する
		World.transpose();
		//ビュー行列の決定
		View = XMMatrixLookAtLH(Vec3(0, 2.0, -5.0f), Vec3(0, 0, 0), Vec3(0, 1.0f, 0));
		//転置する
		View.transpose();
		//射影行列の決定
		float w = static_cast<float>(App::GetApp()->GetGameWidth());
		float h = static_cast<float>(App::GetApp()->GetGameHeight());
		Proj = XMMatrixPerspectiveFovLH(XM_PIDIV4, w / h, 1.0f, 100.0f);
		//転置する
		Proj.transpose();

		m_StaticConstantBuffer.World = World;
		m_StaticConstantBuffer.View = View;
		m_StaticConstantBuffer.Projection = Proj;
		m_StaticConstantBuffer.Emissive = Col4(0, 0, 0, 0);
		//更新
		memcpy(m_pConstantBuffer, reinterpret_cast<void**>(&m_StaticConstantBuffer),
			sizeof(m_StaticConstantBuffer));
	}
Beispiel #9
0
void CameraClass::Render()
{
	XMVECTOR up, position, lookAt;
	float yaw, pitch, roll;
	XMMATRIX rotationMatrix;

	up = XMLoadFloat3(&mUp);
	position = XMLoadFloat3(&mPosition);
	lookAt = XMLoadFloat3(&mLookAt);

	pitch = XMConvertToRadians(mRotation.x);
	yaw = XMConvertToRadians(mRotation.y);
	roll = XMConvertToRadians(mRotation.z);

	rotationMatrix = XMMatrixRotationRollPitchYaw(pitch, yaw, roll);

	up = XMVector3TransformNormal(up, rotationMatrix);
	lookAt = XMVector3TransformNormal(lookAt, rotationMatrix);

	mLookZ = XMVectorGetByIndex(lookAt, 2);
	lookAt = position + lookAt;

	XMStoreFloat4x4(&mViewMatrix, XMMatrixLookAtLH(position, lookAt, up));


}
void RenderSystem::init_camera()
{
	//Viewport Infomation
	D3D11_VIEWPORT vp;
	ZeroMemory(&vp, sizeof(D3D11_VIEWPORT));
	vp.TopLeftX = 0;
	vp.TopLeftY = 0;
	vp.Width    = static_cast<FLOAT>(m_ScreenWidth);
	vp.Height   = static_cast<FLOAT>(m_ScreenHeight);
	m_pD3D11DeviceContext->RSSetViewports(1, &vp);

	//MVP Matrix
	XMVECTOR camPos    = XMVectorSet(0.0f, 0.0f, -5.0f, 0.0f);
	XMVECTOR camTarget = XMVectorSet(0.0f, 0.0f, 0.0f, 0.0f);
	XMVECTOR camUp     = XMVectorSet(0.0f, 1.0f, 0.0f, 0.0f);
	XMMATRIX View      = XMMatrixLookAtLH(camPos, camTarget, camUp);
	XMMATRIX Proj      = XMMatrixPerspectiveFovLH(0.4f*3.14f, GetAspect(), 1.0f, 1000.0f);
	XMMATRIX Model     = XMMatrixRotationY(60.0f);


	XMStoreFloat4x4(&m_Matrix.model, XMMatrixTranspose(Model) );
	XMStoreFloat4x4(&m_Matrix.view,  XMMatrixTranspose(View) );
	XMStoreFloat4x4(&m_Matrix.proj,  XMMatrixTranspose(Proj) );

}
bool processClass::initialize(int width, int height, ID3D11Device *device)
{
	HRESULT hr;
	m_width = width;
	m_height = height;

	camPosition = XMVectorSet(0.0f, 7.0f, -10.0f, 0.0f);
	camTarget = XMVectorSet(0.0f, 0.0f, 0.0f, 0.0f);
	camUp = XMVectorSet(0.0f, 1.0f, 0.0f, 0.0f);

	//Set the View matrix
	camView = XMMatrixLookAtLH(camPosition, camTarget, camUp);
	camProjection = XMMatrixPerspectiveFovLH(0.4f*XM_PI, (float)width / height, 1.0f, 1000.0f);
	ortho = XMMatrixOrthographicLH((float)width, (float)height, 0.1f, 1000.0f);

	D3D11_BUFFER_DESC cbbd;
	ZeroMemory(&cbbd, sizeof(D3D11_BUFFER_DESC));
	cbbd.Usage = D3D11_USAGE_DEFAULT;
	cbbd.ByteWidth = sizeof(cbPerObject);
	cbbd.BindFlags = D3D11_BIND_CONSTANT_BUFFER;
	cbbd.CPUAccessFlags = 0;
	cbbd.MiscFlags = 0;

	hr = device->CreateBuffer(&cbbd, NULL, &cbPerObjectBuffer);
	return true;
}
Beispiel #12
0
        void d3d_display::update_camera() {
            XMVECTOR DefaultForward, DefaultRight, camPosition;
            
            DefaultForward = XMLoadFloat4(&_camera.DefaultForward);
            DefaultRight = XMLoadFloat4(&_camera.DefaultRight);
            camPosition = XMLoadFloat4(&_camera.camPosition);

            XMMATRIX camRotationMatrix = XMMatrixRotationRollPitchYaw(_camera.camPitch, _camera.camYaw, 0);
            XMVECTOR camTarget = XMVector3TransformCoord(DefaultForward, camRotationMatrix);
            camTarget = XMVector3Normalize(camTarget);

            XMVECTOR camRight = XMVector3TransformCoord(DefaultRight, camRotationMatrix);
            XMVECTOR camForward = XMVector3TransformCoord(DefaultForward, camRotationMatrix);
            XMVECTOR camUp = XMVector3Cross(camForward, camRight);
           
            camPosition += _camera.moveLeftRight * camRight;
            camPosition += _camera.moveBackForward * camForward;
            XMStoreFloat4(&_camera.camPosition, camPosition);

            _camera.moveLeftRight = 0.0f;
            _camera.moveBackForward = 0.0f;

            camTarget = camPosition + camTarget;

            XMStoreFloat4x4(&_View, XMMatrixLookAtLH(camPosition, camTarget, camUp));
        }
Beispiel #13
0
void MatrixStack::setCamera2D(int w,int h)
{
	XMVECTOR Eye = XMVectorSet(w/2.0f,- h/2.0f, -5.0f, 0.0f );
	XMVECTOR At = XMVectorSet(w/2.0f,- h/2.0f, 0.0f, 0.0f );
	XMVECTOR Up = XMVectorSet( 0.0f, 1.0f, 0.0f, 0.0f );
	m_View = XMMatrixLookAtLH( Eye, At, Up );
}
Beispiel #14
0
void TextureDemo::UpdateScene(float dt)
{
    float x = m_radius * sinf(m_phi) * cosf(m_theta);
    float z = m_radius * sinf(m_phi) * sinf(m_theta);
    float y = m_radius * cosf(m_phi);

    XMVECTOR pos = XMVectorSet(x, y, z, 1.0f);
    XMVECTOR target = XMVectorZero();
    XMVECTOR up = XMVectorSet(0.0f, 1.0f, 0.0f, 0.0f);

    m_view = XMMatrixLookAtLH(pos, target, up);

    if (GetAsyncKeyState('1') & 0x8000)
    {
        m_currentSamplerState = m_wrapModeSampler.Get();
    }

    if (GetAsyncKeyState('2') & 0x8000)
    {
        m_currentSamplerState = m_boderColorModeSampler.Get();
    }

    if (GetAsyncKeyState('3') & 0x8000)
    {
        m_currentSamplerState = m_mirrorModeSampler.Get();
    }

    if (GetAsyncKeyState('4') & 0x8000)
    {
        m_currentSamplerState = m_clampModeSampler.Get();
    }
}
void Camera::Render()
{
	XMFLOAT3 position, lookAt;
	XMVECTOR upVector, positionVector, lookAtVector;

	upVector = XMLoadFloat3(&m_UP);

	//Setup camera position
	position = XMFLOAT3(m_positionX, m_positionY, m_positionZ);
	positionVector = XMLoadFloat3(&position);

	//Setup where the camera is looking
	lookAt = XMFLOAT3(0, 0, 1);
	lookAtVector = XMLoadFloat3(&lookAt);

	

	//Transform lookat and up by rotation matrix
	lookAtVector = XMVector3TransformCoord(lookAtVector, m_rotationMatrix);
	upVector = XMVector3TransformCoord(upVector, m_rotationMatrix);

	//Translate to position
	lookAtVector = XMVectorAdd(positionVector, lookAtVector);

	//Create view matrix
	m_viewMatrix = XMMatrixLookAtLH(positionVector, lookAtVector, upVector);

	return;
}
Beispiel #16
0
CameraClass::CameraClass()
{
	mPosition = XMFLOAT3(0.0f, 0.0f, -10.0f);
	mRotation = XMFLOAT3(0.0f, 0.0f, 0.0f);
	mLookAt = XMFLOAT3(0.0f, 0.0f, 1.0f);
	mUp = XMFLOAT3(0.0f, 1.0f, 0.0f);

	XMStoreFloat4x4(&mViewMatrix, XMMatrixLookAtLH(XMLoadFloat3(&mPosition), XMLoadFloat3(&mLookAt), XMLoadFloat3(&mUp)));

	mFrameTime = 0.0f;

	mForwardSpeed = 0.0f;
	mBackwardSpeed = 0.0f;
	mLeftSpeed = 0.0f;
	mRightSpeed = 0.0f;
	mUpwardSpeed = 0.0f;
	mDownwardSpeed = 0.0f;
	mLeftTurnSpeed = 0.0f;
	mRightTurnSpeed = 0.0f;
	mLookUpSpeed = 0.0f;
	mLookDownSpeed = 0.0f;

	mLastMousePosition.x = 400;
	mLastMousePosition.y = 300;

	ClientToScreen(GetActiveWindow(), &mLastMousePosition);
}
void Camera::RenderReflection(float height)
{
	XMFLOAT3 up, position, lookAt;
	float yaw, pitch, roll;
	

	//Up vector
	up = XMFLOAT3(0, 1, 0);

	//World position of reflection camera
	position = XMFLOAT3(m_positionX, -m_positionY + (height*2.0f), m_positionZ);

	lookAt = XMFLOAT3(0, 0, 1);

	pitch = m_rotationX * 0.0174532925f;
	yaw = m_rotationY * 0.0174532925f;
	roll = m_rotationZ * 0.0174532925f;

	XMMATRIX rotationMatrix = XMMatrixRotationRollPitchYaw(pitch, yaw, roll);

	//Transform lookat and up by rotation matrix
	
	XMVECTOR lookAtVec = XMVector3TransformCoord(XMLoadFloat3(&lookAt), rotationMatrix);
	XMVECTOR upVec = XMVector3TransformCoord(XMLoadFloat3(&up), rotationMatrix);
	XMVECTOR positionVec = XMLoadFloat3(&position);

	lookAtVec = XMVectorAdd(positionVec, lookAtVec);

	m_reflectionViewMatrix = XMMatrixLookAtLH(positionVec, lookAtVec, upVec);

	return;
}
Beispiel #18
0
void DemoApp::BuildShadowMapMatrices()
{
	//Calculate the radius of the scene's bounding sphere. Approximately use the half of ground plane diagonal.
	float aabbRadius = sqrt(grndLength * grndLength + grndWidth * grndWidth) / 2.0f ;

	//Set up light parameter
	XMVECTOR lightDir = XMLoadFloat3(&mDirLight.Direction);
	XMVECTOR lightPos = -1.0f * lightDir * aabbRadius;
	XMFLOAT3 tar = XMFLOAT3(0.0f, 0.0f, 0.0f);
	XMVECTOR targetPos = XMLoadFloat3(&tar); 
	XMVECTOR up = XMVectorSet(0.0f, 1.0f, 0.0f, 0.0f);
	mLightView = XMMatrixLookAtLH(lightPos, targetPos, up);

	// Transform bounding sphere to light space.
	XMFLOAT3 aabbCenterLightSpace;
	XMStoreFloat3(&aabbCenterLightSpace, XMVector3TransformCoord(targetPos, mLightView));

	//// Ortho frustum in light space encloses scene.
	float l = aabbCenterLightSpace.x - aabbRadius;
	float b = aabbCenterLightSpace.y - aabbRadius;
	float n = aabbCenterLightSpace.z - aabbRadius;
	float r = aabbCenterLightSpace.x + aabbRadius;
	float t = aabbCenterLightSpace.y + aabbRadius;
	float f = aabbCenterLightSpace.z + aabbRadius;
	mLightProj = XMMatrixOrthographicOffCenterLH(l, r, b, t, n, f);

	// Transform NDC space [-1,+1]^2 to texture space [0,1]^2
	mLightViewport = XMMATRIX(
		0.5f, 0.0f, 0.0f, 0.0f,
		0.0f, -0.5f, 0.0f, 0.0f,
		0.0f, 0.0f, 1.0f, 0.0f,
		0.5f, 0.5f, 0.0f, 1.0f);

	 mLightVPT = mLightView*mLightProj*mLightViewport;
}
Beispiel #19
0
void CameraHandler::GenerateBaseViewMatrix()
{
	XMVECTOR lookAt = XMVectorSet(0.0f, 0.0f, 1.0f, 0.0f);
	XMVECTOR camRight = XMVectorSet(1.0f, 0.0f, 0.0f, 0.0f);
	XMVECTOR camUp = XMVectorSet(0.0f, 1.0f, 0.0f, 0.0f);

	this->camRotationMatrix = XMMatrixRotationRollPitchYaw(this->camPitch, this->camYaw, 0);

	lookAt = XMVector3TransformCoord(lookAt, this->camRotationMatrix);

	lookAt = XMVector3Normalize(lookAt);

	camRight = XMVector3TransformCoord(camRight, this->camRotationMatrix);
	camUp = XMVector3TransformCoord(camUp, this->camRotationMatrix);
	

	//Set new camPos
	this->camPos += this->moveLeftRight * camRight;
	this->camPos += this->moveBackForward * lookAt;
	this->camPos += this->moveUpDown * camUp;

	//Reset
	this->moveLeftRight = 0.0f;
	this->moveBackForward = 0.0f;
	this->moveUpDown = 0.0f;

	lookAt = this->camPos + lookAt;

	this->baseViewMatrix = XMMatrixLookAtLH(this->camPos, lookAt, camUp);

	return;
}
Beispiel #20
0
XMMATRIX LightHandler::CalcView(Camera* camera)
{
	XMVECTOR posVec = XMLoadFloat3(&mPoints[0].Position);
	XMVECTOR up = XMLoadFloat3(&XMFLOAT3(0.0f, 1.0f, 0.0f));
	XMVECTOR look = XMLoadFloat3(&XMFLOAT3(0.0f, 0.0f, 1.0f));
	return XMMatrixLookAtLH(posVec, look, up);
}
void Camera::Render()
{
	// Load the rotation and make radian vectors.
	XMVECTOR rotationVector = XMLoadFloat3( &m_Rotation );
	XMVECTOR radianVector = XMVectorReplicate( 0.0174532925f );

	// Setup the vector that points upwards.
	XMVECTOR upVector = XMVectorSet( 0.f, 1.f, 0.f, 0.f );

	// Load the position into an XMVECTOR structure.
	XMVECTOR positionVector = XMLoadFloat3(&m_Position);

	// Setup where the camera is looking by default.
	XMVECTOR lookAtVector = XMVectorSet( 0.f, 0.f, 1.f, 0.f );

	// Create the rotation matrix from the product of the rotation vector and the radian vector.
	// This converts the rotations to radians before creating the rotation matrix
	XMMATRIX rotationMatrix = XMMatrixRotationRollPitchYawFromVector(rotationVector * radianVector);

	// Transform the lookAt and up vector by the rotation matrix so the view is correctly 
	// rotated at the origin.
	lookAtVector = XMVector3TransformCoord(lookAtVector, rotationMatrix);
	upVector = XMVector3TransformCoord(upVector, rotationMatrix);

	// Translate the rotated camera position to the location of the viewer.
	lookAtVector = XMVectorAdd(positionVector, lookAtVector);

	// Finally create the view matrix from the three updated vectors.
	m_ViewMatrix = XMMatrixLookAtLH(positionVector, lookAtVector, upVector);
}
Beispiel #22
0
void mouseMovement(POINT mouseInfoNew, XMMATRIX* ViewMatrix){

	LONG x = mouseInfoNew.x;
	LONG y = mouseInfoNew.y;

	float xMovement = (float)960 - x;
	float yMovement = (float)540 - y;

	//---------------------------------------

	*ViewMatrix = XMMatrixTranspose(*ViewMatrix);
	XMMATRIX ViewInverse = XMMatrixInverse(NULL, *ViewMatrix);

	XMFLOAT4X4 View4x4;
	XMStoreFloat4x4(&View4x4, ViewInverse);

	XMVECTOR CamPos = XMVectorSet(View4x4._41, View4x4._42, View4x4._43, 0);
	
	XMMATRIX RotationX = XMMatrixRotationAxis(XMVectorSet(0.0f, 1.0f, 0.0f, 0.0f), cameraSpeed*xMovement);

	XMVECTOR newCamLook = (XMVectorSet(View4x4._31, View4x4._32 + cameraSpeed*yMovement, View4x4._33, 0)) + CamPos;

	*ViewMatrix = XMMatrixLookAtLH(CamPos, newCamLook, { 0, 1, 0 });
	*ViewMatrix = *ViewMatrix * RotationX;
	*ViewMatrix = XMMatrixTranspose(*ViewMatrix);

}
// レンダリング
HRESULT Render( void )
{
    // 画面クリア
	XMFLOAT4	v4Color = XMFLOAT4( 0.0f, 0.0f, 0.0f, 1.0f );
    g_pImmediateContext->ClearRenderTargetView( g_pRTV, ( float * )&v4Color );
	// *** Zバッファクリア ***
    g_pImmediateContext->ClearDepthStencilView( g_pDepthStencilView, D3D11_CLEAR_DEPTH, 1.0f, 0 );

    // サンプラセット
    g_pImmediateContext->PSSetSamplers( 0, 1, &g_pSamplerState );
    
    // 描画設定
    UINT nStrides = sizeof( CUSTOMVERTEX );
    UINT nOffsets = 0;
    g_pImmediateContext->IASetVertexBuffers( 0, 1, &g_pVertexBuffer, &nStrides, &nOffsets );
    g_pImmediateContext->IASetIndexBuffer( g_pIndexBuffer, DXGI_FORMAT_R16_UINT, 0 );
    g_pImmediateContext->IASetPrimitiveTopology( D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST );
    g_pImmediateContext->IASetInputLayout( g_pInputLayout );

    // シェーダ設定
    g_pImmediateContext->VSSetShader( g_pVertexShader, NULL, 0 );
    g_pImmediateContext->VSSetConstantBuffers( 0, 1, &g_pCBNeverChanges );
    g_pImmediateContext->PSSetShader( g_pPixelShader, NULL, 0 );
    g_pImmediateContext->PSSetConstantBuffers( 0, 1, &g_pCBNeverChanges );
		
	// 変換行列
    CBNeverChanges	cbNeverChanges;
	XMMATRIX		mWorld;
	XMMATRIX		mView;
	XMMATRIX		mProjection;
	XMMATRIX		mViewProjection;

	// Initialize the view matrix
	XMVECTOR Eye = XMVectorSet( Player_1.v3Pos.x, Player_1.v3Pos.y + 3.0f, Player_1.v3Pos.z - 5.0f, 0.0f );
	XMVECTOR At = XMVectorSet( 0.0f, 0.0f, 0.0f, 0.0f );
	XMVECTOR Up = XMVectorSet( 0.0f, 1.0f, 0.0f, 0.0f );
	mView = XMMatrixLookAtLH( Eye, At, Up );

    // Initialize the projection matrix
	mProjection = XMMatrixPerspectiveFovLH( XM_PIDIV4, VIEW_WIDTH / ( FLOAT )VIEW_HEIGHT, 0.01f, 100.0f );

	mViewProjection = mView * mProjection;

    // 描画
	g_pImmediateContext->OMSetDepthStencilState( g_pDSDepthState, 1 );
    g_pImmediateContext->RSSetState( g_pRS_Cull_CW );				// カリングあり

	// 地面
    g_pImmediateContext->OMSetBlendState( NULL, NULL, 0xFFFFFFFF );
	g_mmGround.v4AddColor = XMFLOAT4( 0.0f, 0.0f, 0.0f, 1.0f );
	DrawMyModel( &g_mmGround, &mViewProjection );

	// ビルボード
    g_pImmediateContext->RSSetState( g_pRS );						// カリングなし
    g_pImmediateContext->OMSetBlendState( g_pbsAddBlend, NULL, 0xFFFFFFFF );	// 加算ブレンド
	DrawMyModel( &g_mmBillboard, &mViewProjection );

    return S_OK;
}
Beispiel #24
0
void Camera::moveCam()
{
	XMVECTOR tempRight = XMLoadFloat3(&mRight);
	XMVECTOR tempUp = XMLoadFloat3(&mUp);
	XMVECTOR tempPosition = XMLoadFloat3(&mPosition);
	XMVECTOR tempForward = XMLoadFloat3(&mLook);
	



	//set the camera to look at the character
	camTarget = playerPosition;






	XMVECTOR tempTarget = XMLoadFloat3(&camTarget);

	tempTarget = XMVectorSetY(tempTarget,10);


	
	//rotate camera around the character
	camRotationMatrix = XMMatrixRotationRollPitchYaw(-camPitch, camYaw, 0);
	tempPosition = XMVector3TransformNormal(PlayerForward, camRotationMatrix);
	tempPosition = XMVector3Normalize(tempPosition);


	tempPosition = (tempPosition * -50) + tempTarget;
		
	tempPosition = XMVectorSetY(tempPosition, 30.0f);

	tempForward = XMVector3Normalize(tempTarget - tempPosition);	// Get forward vector based on target
	tempForward = XMVectorSetY(tempForward, 0.0f);	// set forwards y component to 0 so it lays only on

	tempForward= XMVector3Normalize(tempForward);

	tempRight = XMVectorSet(XMVectorGetZ(-tempForward), 0.0f, XMVectorGetX(tempForward), 0.0f);

	tempUp = XMVector3Normalize(XMVector3Cross(XMVector3Normalize(tempPosition - tempTarget), tempRight));



	XMStoreFloat3(&mRight, tempRight);
	XMStoreFloat3(&mUp, tempUp);
	XMStoreFloat3(&mPosition, tempPosition);
	XMStoreFloat3(&mLook, tempForward);

	XMMATRIX tempView = XMLoadFloat4x4(&mView);


	tempView = XMMatrixLookAtLH(tempPosition, tempTarget, tempUp);

	XMStoreFloat4x4(&mView, tempView);

	///////////mising some code maybe
}
void CameraComponent::update()
{
	Transform transf = m_pOwnerGameObject->getTransform();
	XMFLOAT3 position = transf.getPosition();
	m_View=XMMatrixLookAtLH(XMLoadFloat3(&position),XMLoadFloat3(&m_LookAt),XMLoadFloat3(&m_Up));
    m_Projection=XMMatrixPerspectiveFovLH(m_FOV,m_AspectRatio,m_Near,m_Far);

}
Beispiel #26
0
void DX11::LookAt(float eyeX, float eyeY, float eyeZ, float x, float y, float z, float upX, float upY, float upZ)
{
  XMVECTOR Eye = XMVectorSet(eyeX, eyeY, eyeZ, 0);
  XMVECTOR At = XMVectorSet(x, y, z, 0);
  XMVECTOR Up = XMVectorSet(upX, upY, upZ, 0);
  // Use RH Version
  g_View = XMMatrixLookAtLH(Eye, At, Up);
}
Beispiel #27
0
void D3DRenderer::UpdateScene(const EnMatrix4x4& camPos, const EnVector3& target)
{
	XMVECTOR up = XMVectorSet(camPos.c[1].x, camPos.c[1].y, camPos.c[1].z, 1.0f);
	XMVECTOR camPosVector = XMVectorSet(camPos.c[3].x, camPos.c[3].y, camPos.c[3].z, 1.0f);
	XMVECTOR camTarget = XMVectorSet(target.x, target.y, target.z, 1.0f);
	mCamViewMatrix = XMMatrixLookAtLH(camPosVector, camTarget, up);
	//mCamViewMatrix = ConvertToXMMatrix(camPos);
}
Beispiel #28
0
void ShadowLight::CreateViewMatrix()
{
	XMVECTOR up = XMVectorSet(0.0f, 1.0f, 0.0f, .0f);
	XMVECTOR pos = XMVectorSet(position.x, position.y, position.z, .0f);
	XMVECTOR look = XMVectorSet(lookAt.x, lookAt.y, lookAt.z, .0f);

	viewMatrix = XMMatrixLookAtLH(pos, look, up);
}
/**
 *	Create view matrix using position, target and up vectors
 *
 *	@param vPos Position of the camera.
 *	@param vTarget Target for the camera to look at.
 *	@param vUp A vector that describes the up direction of the camera.
 *	@return View matrix
 */
CFMat4x4 CFMat4x4::CreateViewLookAt(CFVec3Arg vPos, CFVec3Arg vTarget, CFVec3Arg vUp)
{
	CFMat4x4 mOut;
	XMMATRIX& rmOut = *reinterpret_cast<XMMATRIX*>(&mOut);
	rmOut = XMMatrixLookAtLH(*reinterpret_cast<const XMVECTOR*>(&vPos),
		*reinterpret_cast<const XMVECTOR*>(&vTarget),
		*reinterpret_cast<const XMVECTOR*>(&vUp));
	return mOut;
}
Beispiel #30
0
	void intiData(){
		people = loadPUBModel("resources/456.BINARY",m_pd3dDevice,m_pImmediateContext);

		
		// Initialize the world matrix
		m_World = XMMatrixIdentity();

		// Initialize the view matrix
		XMVECTOR Eye = XMVectorSet( 0, 1.1, -2.0, 0.0f );
		XMVECTOR At = XMVectorSet( 0.0f, 1.1, 0.0f, 0.0f );
		XMVECTOR Up = XMVectorSet( 0.0f, 1.0f, 0.0f, 0.0f );
		m_View = XMMatrixLookAtLH( Eye, At, Up );

		// Initialize the projection matrix
		m_Projection = XMMatrixPerspectiveFovLH( XM_PIDIV4, getWindowWidth() / (FLOAT)getWindowHeight(), 0.01f, 1000.0f );
		m_Projection = XMMatrixOrthographicLH(4,4*getWindowHeight()/(FLOAT)getWindowWidth(),0,100);
		
		bone_shader =new ShaderProgram(m_pd3dDevice);
		bone_shader->setLayout(CUSTOM_LAYOUT_PUB,CUSTOM_LAYOUT_PUB_NUM);
		bone_shader->requestConstantBuffer(192,0);
		bone_shader->requestConstantBuffer(sizeof(XMMATRIX)*BONE_MAX_NUM,1);
		bone_shader->loadShader(L"FX/boneAnime.fx");
		people->useShader(bone_shader);


		Sampler* samp=new Sampler(m_pd3dDevice);
		samp->createSampleState(D3D11_FILTER_MIN_MAG_MIP_LINEAR,D3D11_TEXTURE_ADDRESS_WRAP,-1);
		samp->useSamplerAt(m_pImmediateContext,0);

	//	MyLuaManager::getInstance()->registerFun(ConsleGlue);






		/***********************************************************************/
		
		view_shader= new ShaderProgram(m_pd3dDevice);
		view_shader->setLayout(CUSTOM_LAYOUT_PU,CUSTOM_LAYOUT_PU_NUM);
		view_shader->requestConstantBuffer(192,0);
		view_shader->loadShader(L"FX/Tutorial04.fx");
		quard=new ImageView(m_pd3dDevice);
		quard->setBorder(getWindowWidth(),getWindowHeight());
		quard->setSize(200,150);
		quard->setShader(view_shader);


		backTarget=RenderTarget::generateRenderTarget(m_pd3dDevice,getWindowWidth(),getWindowHeight());
		quard->setTexture(*backTarget->getShaderResource());
		/**********************************************************************/
		setDrawMode(Triangle);
		/*********************************************************************/
		controller=new ObjectController(m_pd3dDevice);
		controller->addObject(quard);
	}