示例#1
0
void TestTriangleStripsDX::Update()
{
	if (processInput)
	{
		float rotAmount = 0.0f;
		XMMATRIX rotMatrix = XMMatrixIdentity();
		if (input.right || input.left)
		{
			if (input.right)
				rotAmount = rotDelta;
			if (input.left)
				rotAmount = -rotDelta;
			rotMatrix = XMMatrixRotationAxis(XMLoadFloat4(&up), XMConvertToRadians(rotAmount));
		}
		else if (input.up || input.down)
		{
			if (input.up)
				rotAmount = rotDelta;
			if (input.down)
				rotAmount = -rotDelta;
			rotMatrix = XMMatrixRotationAxis(XMLoadFloat4(&right), XMConvertToRadians(rotAmount));
		}

		XMStoreFloat4(&eye, XMVector3Transform(XMLoadFloat4(&eye), rotMatrix));
		XMStoreFloat4(&right, XMVector3Normalize(XMVector3Cross(XMLoadFloat4(&up), (XMLoadFloat4(&center) - XMLoadFloat4(&eye)))));

		XMMATRIX viewMatrix = XMMatrixLookAtRH(XMLoadFloat4(&eye), XMLoadFloat4(&center), XMLoadFloat4(&up));
		mDeviceContext->UpdateSubresource(viewMatrixBuffer, 0, NULL, &viewMatrix, 0, 0);
	}
}
///////////////**************new**************////////////////////
void UpdateScene()
{
	//Keep the cubes rotating
	rot += .0005f;
	if(rot > 6.26f)
		rot = 0.0f;

	//Reset cube1World
	cube1World = XMMatrixIdentity();

	//Define cube1's world space matrix
    //Exercise 1. Orbit the first cube around a different axis.
	XMVECTOR rotaxis = XMVectorSet(1.0f, 0.5f, 0.0f, 0.0f);
	Rotation = XMMatrixRotationAxis( rotaxis, rot);
	Translation = XMMatrixTranslation( 4.0f, 0.0f, 0.0f );

	//Set cube1's world space using the transformations
    cube1World = Translation* Rotation;

	//Reset cube2World
	cube2World = XMMatrixIdentity();

	//Define cube2's world space matrix
	Rotation = XMMatrixRotationAxis( rotaxis, -rot);
	Scale = XMMatrixScaling( 1.3f, 1.3f, 1.3f );

	//Set cube2's world space matrix
	cube2World = Rotation * Scale;
    //Exercise 2.Play with the different transformations, and try to order them differently when multiplying them together,
    // to see different effects.
    //cube2World = Scale*Rotation;
}
示例#3
0
/*------------------------------------
------ UpdateScene() Funktion ------
Hier wird die Scene verändert
------------------------------------*/
void UpdateScene()
{
	// Rotation der Würfel:
	rot += 0.00005f;
	if (rot > 6.28f)
		rot = 0.0f;

	// Setze die cube1World Matrix wieder auf die Identität zurück
	cube1World = XMMatrixIdentity();

	XMVECTOR rotaxis1 = XMVectorSet(1.0f, 1.0f, 0.0f, 0.0f);
	Rotation = XMMatrixRotationAxis(rotaxis1, rot);
	Translation = XMMatrixTranslation(0.0f, 0.0f, 4.0f);
	// Bestimme die worldmatrix für würfel1
	cube1World = Translation*Rotation;

	//Jetzt cube2

	cube2World = XMMatrixIdentity();

	XMVECTOR rotaxis2 = XMVectorSet(0.0f, 1.0f, 0.0f, 0.0f);
	Rotation = XMMatrixRotationAxis(rotaxis2, -rot);
	Scale = XMMatrixScaling(1.3f, 1.3f, 1.3f);

	cube2World = Scale*Rotation;

}
示例#4
0
void Game::UpdateScene()
{
	floorWorld = XMMatrixIdentity();

	scale = XMMatrixScaling(250.0f, 1.0f, 250.0f);
	translation = XMMatrixTranslation(0.0f, 0.0f, 0.0f);

	floorWorld = scale*translation;

	//Keep the cubes rotating
	rotSpeed += .0005f;
	if (rotSpeed > 6.26f)
		rotSpeed = 0.0f;

	//When used, these matrices will rotate objects
	rotateAboutX = XMMatrixRotationAxis(rotXAxis, -rotSpeed);
	rotateAboutY = XMMatrixRotationAxis(rotYAxis, -rotSpeed);
	rotateAboutZ = XMMatrixRotationAxis(rotZAxis, -rotSpeed);

	scale = XMMatrixScaling(2, scaleY, 2);

	//Reset cubes locations
	cube1World = XMMatrixIdentity();
	cube2World = XMMatrixIdentity();

	//When used, these matrices will set an objects position
	translation = XMMatrixTranslation(-5.0f, 2.0f, 0.0f);

	//Set cube1's world space using the transformations
	cube1World = rotateAboutX * translation * scale;

	//When used, these matrices will set an objects position
	translation = XMMatrixTranslation(5.0f, 2.0f, 0.0f);

	//Set cube2's world space matrix
	cube2World = rotateAboutY * translation * scale;

	meshWorld = XMMatrixIdentity();
	
	travelSpeed += 0.0003f;
	//Setting meshes scale, translation and rotation
	scale = XMMatrixScaling(0.2f,0.2f,0.2f);
	translation = XMMatrixTranslation(-travelSpeed, 0.0f, 0.0f);
	rotation = XMMatrixRotationRollPitchYaw(0, XMConvertToRadians(180), 0);

	meshWorld = translation * rotation * scale;

	//Reset sphereWorld
	sphereWorld = XMMatrixIdentity();

	//Define sphereWorld's world space matrix
	scale = XMMatrixScaling(5.0f, 5.0f, 5.0f);
	//Make sure the sphere is always centered around camera
	translation = XMMatrixTranslation(XMVectorGetX(camPosition), XMVectorGetY(camPosition), XMVectorGetZ(camPosition));

	//Set sphereWorld's world space using the transformations
	sphereWorld = scale * translation;
}
示例#5
0
void Camera::Roll(float angle)
{
	XMMATRIX R = XMMatrixRotationAxis(XMLoadFloat3(&mLook), angle);
	XMStoreFloat3(&mUp, XMVector3TransformNormal(XMLoadFloat3(&mUp), R));
	XMStoreFloat3(&mRight, XMVector3TransformNormal(XMLoadFloat3(&mRight), R));

}
void Camera::RotatePitch(float deg)
{
	XMVECTOR right = XMVector3Normalize(XMVector3Cross(mEye, mUp));
	XMMATRIX rotation = XMMatrixRotationAxis(right, deg);

	mEye = XMVector3TransformCoord(mEye, rotation);
}
示例#7
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);

}
示例#8
0
void Camera::Yaw(float angle)
{
	// Rotate right and look vector about the up vector.
	XMMATRIX R = XMMatrixRotationAxis(XMLoadFloat3(&mUp), angle);
	XMStoreFloat3(&mRight, XMVector3TransformNormal(XMLoadFloat3(&mRight), R));
	XMStoreFloat3(&mLook, XMVector3TransformNormal(XMLoadFloat3(&mLook), R));
}
示例#9
0
//-------------------------------------------------------------------------------------
// Name: Update()
// Desc: Updates the world for the next frame
//-------------------------------------------------------------------------------------
void Update()
{
    // Set the world matrix
    float fAngle = fmodf( -g_Time.fAppTime, XM_2PI );
    static const XMVECTOR vAxisZ = { 0, 0, 1.0f, 0 };
    g_matWorld = XMMatrixRotationAxis( vAxisZ, fAngle );
}
示例#10
0
void Direct3D::update(float dt)
{
	static float rotDT = 0.f;
	rotDT = dt;
	XMMATRIX rot = XMMatrixRotationAxis(XMVectorSet(0.f, 0.f, 1.f, 0.f), rotDT);
	for(int i = 0; i < NROFLIGHTS; i++)
	{
		XMVECTOR vLightPos = XMLoadFloat4(&m_lightList[i].pos);
		vLightPos = XMVector4Transform(vLightPos, rot);
		XMStoreFloat4(&m_lightList[i].pos, vLightPos);
	}
	m_pCamera->update();
	//m_fps = 1/dt;
	m_time += dt;
	static int frameCnt = 0;
    static float t_base = 0.f;
	frameCnt++;
	
	if(m_time - t_base >= 1.f)
	{
		frameCnt /= 1;
		m_fps = (float)frameCnt;
		frameCnt = 0;
		t_base += 1.f;
	}

	updateConstantBuffers();
}
void D3DCamera::Pitch(float angle)
{
    XMMATRIX rot = XMMatrixRotationAxis(m_Right, angle);

    m_Up = XMVector3TransformNormal(m_Up, rot);
    m_LookAt = XMVector3TransformNormal(m_LookAt, rot);
}
示例#12
0
void Camera::pitch(float angle)
{
	// Rotate up and look vector about the right vector.
	XMMATRIX R = XMMatrixRotationAxis(XMLoadFloat3(&m_right), angle);

	XMStoreFloat3(&m_up,   XMVector3TransformNormal(XMLoadFloat3(&m_up), R));
	XMStoreFloat3(&m_look, XMVector3TransformNormal(XMLoadFloat3(&m_look), R));
}
void Camera::RotatePitch(float angleRad)
{
    XMVECTOR right = XMVector3Normalize(XMVector3Cross(mAt - mEye, mUp));
    XMMATRIX rotation = XMMatrixRotationAxis(right, angleRad);

    mEye = mAt + XMVector3TransformCoord(mEye - mAt, rotation);
    mUp = XMVector3TransformCoord(mUp, rotation);
}
示例#14
0
void Camera::Roll(float angle)
{
	// Rotate up and Right vector about the Look vector.

	XMMATRIX R = XMMatrixRotationAxis(XMVector3Cross(XMLoadFloat3(&mUp), XMLoadFloat3(&mRight)), angle);

	XMStoreFloat3(&mUp, XMVector3TransformNormal(XMLoadFloat3(&mUp), R));
	XMStoreFloat3(&mRight, XMVector3TransformNormal(XMLoadFloat3(&mLook), R));
}
示例#15
0
void Camera::Pitch(float p_Angle)
{
	//Rotate up and look vector about the right vector.
	XMMATRIX t_Right = XMMatrixRotationAxis(XMLoadFloat3(&m_Right), p_Angle);

	XMStoreFloat3(&m_Up, XMVector3TransformNormal(XMLoadFloat3(&m_Up), t_Right));
	XMStoreFloat3(&m_Look, XMVector3TransformNormal(XMLoadFloat3(&m_Look), t_Right));
	m_HasMoved = true;
}
示例#16
0
void CubeModel::Update(float time)
{
  mAngle += 90.0f * time;
  
  XMVECTOR rotationAxis = XMVectorSet(1, 0, 1, 0);
  mWorldPos.world = XMMatrixRotationAxis(rotationAxis, XMConvertToRadians(mAngle));
  
  mVertexShader->UpdateWorldMatrix(mWorldPos);
}
示例#17
0
// @brief 俯视和仰视
//
// @param angle 为正:  俯视; 为负: 仰视
void Camera::Pitch(float angle)
{
	// 相当于坐标系绕着mRight旋转

	XMMATRIX R = XMMatrixRotationAxis(XMLoadFloat3(&mRight), angle);

	XMStoreFloat3(&mUp,   XMVector3TransformNormal(XMLoadFloat3(&mUp), R));
	XMStoreFloat3(&mLook, XMVector3TransformNormal(XMLoadFloat3(&mLook), R));
}
    void FirstPersonCamera::Update(const GameTime& gameTime)
    {
		XMFLOAT2 movementAmount = Vector2Helper::Zero;
        if (mKeyboard != nullptr)
        {
            if (mKeyboard->IsKeyDown(DIK_W))
            {
                movementAmount.y = 1.0f;
            }

            if (mKeyboard->IsKeyDown(DIK_S))
            {
                movementAmount.y = -1.0f;
            }

            if (mKeyboard->IsKeyDown(DIK_A))
            {
                movementAmount.x = -1.0f;
            }

            if (mKeyboard->IsKeyDown(DIK_D))
            {
                movementAmount.x = 1.0f;
            }
        }

        XMFLOAT2 rotationAmount = Vector2Helper::Zero;
        if ((mMouse != nullptr) && (mMouse->IsButtonHeldDown(MouseButtons::Left)))
        {
            LPDIMOUSESTATE mouseState = mMouse->CurrentState();			
            rotationAmount.x = -mouseState->lX * mMouseSensitivity;
            rotationAmount.y = -mouseState->lY * mMouseSensitivity;
        }

		float elapsedTime = (float)gameTime.ElapsedGameTime();
        XMVECTOR rotationVector = XMLoadFloat2(&rotationAmount) * mRotationRate * elapsedTime;
        XMVECTOR right = XMLoadFloat3(&mRight);

        XMMATRIX pitchMatrix = XMMatrixRotationAxis(right, XMVectorGetY(rotationVector));
        XMMATRIX yawMatrix = XMMatrixRotationY(XMVectorGetX(rotationVector));

        ApplyRotation(XMMatrixMultiply(pitchMatrix, yawMatrix));

        XMVECTOR position = XMLoadFloat3(&mPosition);
		XMVECTOR movement = XMLoadFloat2(&movementAmount) * mMovementRate * elapsedTime;

		XMVECTOR strafe = right * XMVectorGetX(movement);
        position += strafe;

        XMVECTOR forward = XMLoadFloat3(&mDirection) * XMVectorGetY(movement);
        position += forward;
        
        XMStoreFloat3(&mPosition, position);

        Camera::Update(gameTime);
    }
示例#19
0
void Entity::Pitch(float angle)
{
	prevPitch = angle;
	// Rotate up and look vector about the right vector.

	XMMATRIX R = XMMatrixRotationAxis(XMLoadFloat3(&mRight), angle);

	XMStoreFloat3(&mUp, XMVector3TransformNormal(XMLoadFloat3(&mUp), R));
	XMStoreFloat3(&mLook, XMVector3TransformNormal(XMLoadFloat3(&mLook), R));
}
示例#20
0
void Entity::Roll(float angle)
{
	//Rotate Up and Right on Look Vector
	prevRoll = angle;

	XMMATRIX R = XMMatrixRotationAxis(XMLoadFloat3(&mLook), angle);

	XMStoreFloat3(&mUp, XMVector3TransformNormal(XMLoadFloat3(&mUp), R));
	XMStoreFloat3(&mRight, XMVector3TransformNormal(XMLoadFloat3(&mRight), R));
}
示例#21
0
Player::Player(SoundManager* SoundManager, int MapWidth, int MapLength,XMFLOAT3 Position, XMFLOAT3 Scale, int Health, Input* input) : Entity(SoundManager, MapWidth, MapLength, Position, Scale, Health)
{
	m_input = input;
	//Loading death sounds FIX LATER :)
	//m_soundManager->LoadSound("DickbuttSound.mp3", "PlayerDeathSound", "PlayerSound", LOAD_MEMORY);

	XMVECTOR _rotzAxis{ 0,1,0,0 };
	m_rotation = XMMatrixRotationAxis(_rotzAxis, XM_PI);
	m_entityBox.Extents = XMFLOAT3(2.5f, 0.0f, 2.5f);
}
void GCamera::Rotate(XMFLOAT3 axis, float degrees)
{
	if (XMVector3Equal(GMathFV(axis), XMVectorZero()) ||
		degrees == 0.0f)
		return;

	// rotate vectors
	XMFLOAT3 look_at_target = GMathVF(GMathFV(mTarget) - GMathFV(mPosition));
	XMFLOAT3 look_at_up = GMathVF(GMathFV(mUp) - GMathFV(mPosition));
	look_at_target = GMathVF(XMVector3Transform(GMathFV(look_at_target),
		XMMatrixRotationAxis(GMathFV(axis), XMConvertToRadians(degrees))));
	look_at_up = GMathVF(XMVector3Transform(GMathFV(look_at_up),
		XMMatrixRotationAxis(GMathFV(axis), XMConvertToRadians(degrees))));

	// restore vectors's end points mTarget and mUp from new rotated vectors
	mTarget = GMathVF(GMathFV(mPosition) + GMathFV(look_at_target));
	mUp = GMathVF(GMathFV(mPosition) + GMathFV(look_at_up));

	this->lookatViewMatrix();
}
示例#23
0
void Camera::rotateX(float amount)
{
	XMMATRIX mRotate = XMMatrixRotationAxis(XMLoadFloat4(&v_Right), amount);
	
	XMVECTOR new_y = XMVector4Transform(XMLoadFloat4(&v_Up), mRotate);
	XMVECTOR new_z = XMVector4Transform(XMLoadFloat4(&v_Look), mRotate);
	
	XMStoreFloat4(&v_Up, new_y);
	XMStoreFloat4(&v_Look, new_z);

	update();
}
示例#24
0
void Bullet_e::Update(double time)
{
	m_position.x += m_travelVec.x * m_speed * time;
	m_position.y += m_travelVec.y * m_speed * time;
	m_position.z += m_travelVec.z * m_speed * time;
	XMVECTOR _rotzAxis{ m_travelVec.x, m_travelVec.y, m_travelVec.z,0 };
	m_rotationValue += time;
	m_rotation = XMMatrixRotationAxis(_rotzAxis, XM_PI * m_rotationValue);
	m_light->SetPos(XMFLOAT4(m_position.x, m_position.y, m_position.z, 1.0f));


	m_entityBox.Center = m_position;
}
示例#25
0
void Camera::Rotate(XMFLOAT3 axis, float degrees)
{
	if (XMVector3Equal(to(axis), XMVectorZero()) ||
		degrees == 0.0f)
		return;

	// rotate vectors
	XMFLOAT3 look_at_target = to(to(mTarget) - to(mPosition));
	XMFLOAT3 look_at_up = to(to(mUp) - to(mPosition));
	look_at_target = to(XMVector3Transform(to(look_at_target),
		XMMatrixRotationAxis(to(axis), XMConvertToRadians(degrees))));
	look_at_up = to(XMVector3Transform(to(look_at_up),
		XMMatrixRotationAxis(to(axis), XMConvertToRadians(degrees))));

	// restore vectors's end points mTarget and mUp from new rotated vectors
	mTarget = to(to(mPosition) + to(look_at_target));
	mUp = to(to(mPosition) + to(look_at_up));

	this->initViewMatrix();

	XMVECTOR w = XMVectorZero();
}
示例#26
0
Bullet_e::Bullet_e(SoundManager * SoundManager, int MapWidth, int MapLength, XMFLOAT3 Position, XMFLOAT3 Scale, int Health, XMFLOAT3 Color, XMFLOAT3 TravelVec)
{
	XMVECTOR _rotzAxis{ TravelVec.x, TravelVec.y, TravelVec.z, 0 };
	m_rotation = XMMatrixRotationAxis(_rotzAxis, 0.0f);
	m_rotationValue = 0.0f;
	m_scale = Scale;
	m_position = Position;
	m_entityBox.Extents = XMFLOAT3(1, 0, 1);
	m_health = Health;
	m_speed = 28;
	m_travelVec = TravelVec;
	m_light = new Light(XMFLOAT4(Position.x, Position.y, Position.z, 1.0f), XMFLOAT4(Color.x, Color.y, Color.z, 1.0f), XMFLOAT4(2, 1, 0, 0));
}
//
// Update the program's state
//
void DirectXClass::Update(float deltaTime)
{
	XMVECTOR eyePosition = XMVectorSet(0, 30, -50, 1);
	XMVECTOR focusPoint = XMVectorSet(0, 0, 0, 1);
	XMVECTOR upDirection = XMVectorSet(0, 1, 0, 0);
	m_ViewMatrix = XMMatrixLookAtLH(eyePosition, focusPoint, upDirection);
	m_3dDeviceContext->UpdateSubresource(g_d3dConstantBuffers[CB_Frame], 0, nullptr, &m_ViewMatrix, 0, 0);

	static float angle = 0.0f;
	angle += 90.0f * deltaTime/5;
	XMVECTOR rotationAxis = XMVectorSet(0, 1, 0, 0);

	m_WorldMatrix = XMMatrixRotationAxis(rotationAxis, XMConvertToRadians(angle));
	m_3dDeviceContext->UpdateSubresource(g_d3dConstantBuffers[CB_Object], 0, nullptr, &m_WorldMatrix, 0, 0);
}
示例#28
0
void glRotatef (GLfloat angle, GLfloat x, GLfloat y, GLfloat z) {
	// replicates the OpenGL glRotatef with 3 components and angle in degrees
	XMVECTOR vec;
	XMMATRIX mat;

	vec.x = x;
	vec.y = y;
	vec.z = z;

	mat = XMMatrixRotationAxis(vec, D3DXToRadian(angle));
	current_matrix->stack[current_matrix->stackdepth] = mat * current_matrix->stack[current_matrix->stackdepth];

	// dirty the matrix
	current_matrix->dirty = 1;
}
示例#29
0
void FPSCamera::Roll(float angle)
{
	XMVECTOR right = XMLoadFloat3(&mRight);
	XMVECTOR look = XMLoadFloat3(&mLook);
	XMVECTOR up = XMLoadFloat3(&mUp);

	XMMATRIX rotate = XMMatrixRotationAxis(look, angle);

	up = XMVector3TransformNormal(up, rotate);
	right = XMVector3Cross(up, look);
	right = XMVector3Normalize(right);

	XMStoreFloat3(&mUp, up);
	XMStoreFloat3(&mRight, right);

	mViewUpdated = true;
}
示例#30
0
/**
 *	Creates a rotation matrix about the described axis.
 *
 *  @param fX Describes the x component of the axis.
 *  @param fY Describes the y component of the axis.
 *  @param fZ Describes the z component of the axis.
 *  @param fRadians Angle of rotation, measured clockwise when looking along the rotation axis.
 *  @return The resulting matrix.
 */
CFMat4x4	CFMat4x4::CreateRotationAxis( FLOAT32 fX, FLOAT32 fY, FLOAT32 fZ, FLOAT32 fRadians )
{
	CFMat4x4 matReturn;
	CFVec3 v3Axis;

	v3Axis.X( fX );
	v3Axis.Y( fY );
	v3Axis.Z( fZ );

	XMMATRIX& matResult = *reinterpret_cast<XMMATRIX*>( &matReturn );
	XMVECTOR& vAxis = *reinterpret_cast<XMVECTOR*>( &v3Axis );

	vAxis = XMVectorSetW( vAxis, 0.0f );

	matResult = XMMatrixRotationAxis( vAxis, fRadians );

	return matReturn;
}