コード例 #1
0
ファイル: Camera.cpp プロジェクト: KimRestad/3D-II-Lab2
// Tilt the camera horisontally: look left/right
void Camera::TurnHorizontal(float angle)
{
	D3DXVECTOR3 up;
	D3DXVec3Cross(&up, &mDirection, &GetRight());
	D3DXMATRIX rotation;

	D3DXMatrixRotationAxis(&rotation, &up, angle);
	D3DXVec3TransformCoord(&mDirection, &mDirection, &rotation);
	D3DXVec3Normalize(&mDirection, &mDirection);
}
コード例 #2
0
ファイル: polymesh3.cpp プロジェクト: Ochakko/MameRoid3D
int CPolyMesh3::MultVert( D3DXMATRIX multmat )
{
	int pno;
	for( pno = 0; pno < m_orgpointnum; pno++ ){
		D3DXVECTOR3 tmpv;
		D3DXVec3TransformCoord( &tmpv, m_pointbuf + pno, &multmat );
		*( m_pointbuf + pno ) = tmpv;
	}
	return 0;
}
コード例 #3
0
ファイル: SpotLight.cpp プロジェクト: reima/sep3d
void SpotLight::OnFrameMove(float elapsed_time) {
  assert(SpotLight::pPos != NULL);
  D3DXMATRIX rotation_matrix;
  D3DXMatrixRotationYawPitchRoll(&rotation_matrix,
    elapsed_time * rotation_.y,
    elapsed_time * rotation_.x,
    elapsed_time * rotation_.z);
  D3DXVec3TransformCoord(&position_, &position_, &rotation_matrix);
  SpotLight::pPos->SetFloatVectorArray(position_, instance_id_, 1);
}
コード例 #4
0
void Camera::CalculateViewMatrix(D3DXMATRIX transMatrix)
{
	D3DXVECTOR3 xaxis = D3DXVECTOR3(1,0,0);
	D3DXVECTOR3 yaxis = D3DXVECTOR3(0,1,0);

	D3DXVec3TransformCoord(&right, &xaxis, &transMatrix);
	D3DXVec3TransformCoord(&up, &yaxis, &transMatrix); 

	D3DXVECTOR3 newPos;
       
	D3DXMATRIX baseMatrix;										// position matrix
	D3DXMatrixTranslation(&baseMatrix, 0, 0, zoom);				// inital position
	baseMatrix = baseMatrix * transMatrix;						// translated

	look = D3DXVECTOR3(transMatrix._41, transMatrix._42, transMatrix._43);
	newPos = D3DXVECTOR3(baseMatrix._41, baseMatrix._42, baseMatrix._43);
	
	D3DXMatrixLookAtLH(&viewMatrix, &newPos, &look, &up);
}
コード例 #5
0
	//================================================================================
	//!	メソッド名	CSKIN_MESH::getWorldCenter
	//
	//	機能		ワールド座標系中心点を受け取る
	//	戻り値		ワールド座標系中心点
	//	更新		2007/12/08		<新規>
	//================================================================================
	VEC3
	CSKIN_MESH::getWorldCenter(void)
	{
	//	ワールド座標系中心点
		VEC3	aCenter;
	//	ワールド座標系の演算
		D3DXVec3TransformCoord(&aCenter, &sd_ptr->mesh->localCenter, getWorldMatrix());
	//	ワールド座標系中心点を返す
		return	aCenter;
	}
コード例 #6
0
ファイル: ElCamera.cpp プロジェクト: chenbk85/3dlearn
bool ElCamera::isViewOutOfDate()
{
	// Overridden from Frustum to use local orientation / position offsets
	// Attached to node?
	if (mParentNode != 0)
	{
		if (mRecalcView ||
			mParentNode->getDerivedOrientation() != mLastParentOrientation ||
			mParentNode->getDerivedPosition() != mLastParentPosition)
		{
			// Ok, we're out of date with SceneNode we're attached to
			mLastParentOrientation = mParentNode->getDerivedOrientation();
			mLastParentPosition = mParentNode->getDerivedPosition();

			mRealOrientation = mLastParentOrientation * mOrientation;
			D3DXMATRIX m;
			D3DXMatrixRotationQuaternion(&m, &mLastParentOrientation);
			D3DXVec3TransformCoord(&mRealPosition, &mPosition, &m);
			mRealPosition += mLastParentPosition;
			
			mRecalcView = true;
		}
	}
	else
	{
		// Rely on own updates
		mRealOrientation = mOrientation;
		mRealPosition = mPosition;
	}

	// Deriving reflected orientation / position
	if (mRecalcView)
	{
		if (mReflect)
		{
			// Calculate reflected orientation, position
			D3DXMATRIX rot;
			D3DXMatrixRotationQuaternion(&rot, &mRealOrientation);
			D3DXMATRIX trans;
			D3DXMatrixTranslation(&trans, mRealPosition.x, mRealPosition.y, mRealPosition.z);
			
			D3DXMATRIX m = rot * trans * mReflectMatrix;

			D3DXVECTOR3 scale;
			D3DXMatrixDecompose(&scale, &mDerivedOrientation, &mDerivedPosition, &m);
		}
		else
		{
			mDerivedOrientation = mRealOrientation;
			mDerivedPosition = mRealPosition;
		}
	}

	return mRecalcView;
}
コード例 #7
0
ファイル: CubeBox.cpp プロジェクト: redclock/GIEngine
bool CCubeBox::Collision(D3DXVECTOR3& vGo, D3DXVECTOR3& vPos)
{
    FLOAT StdDist[3] = { m_wx/2, m_wy/2, m_wz/2 };
    //矩形中心
    D3DXVECTOR3 vCenter( m_x + StdDist[0], m_y + StdDist[1], m_z + StdDist[2]);
    //原位置指向中心
    D3DXVECTOR3 D = vCenter - vPos; 
    //若方向相反
    //if (D3DXVec3Dot(&vGo, &D) <= 0) return false;
    //长宽高单位向量
    D3DXVECTOR3 vSub[3];
    vSub[0] = D3DXVECTOR3( 1, 0, 0 );
    vSub[1] = D3DXVECTOR3( 0, 1, 0 );
    vSub[2] = D3DXVECTOR3( 0, 0, 1 );
    //前进方向分量
    FLOAT vGoSub[3];
    //距中心分量
    FLOAT vDSub[3];
    for (int i = 0; i < 3; i++)
    {
        D3DXVec3TransformCoord(&vSub[i], &vSub[i], &m_matRot);
        vGoSub[i] = D3DXVec3Dot(&vGo, &vSub[i]);
        vDSub[i] = D3DXVec3Dot(&D, &vSub[i]);
    }
    //二者的差距
    FLOAT inner[3];
    for (int i = 0; i<3; i++)
    {
        inner[i] = StdDist[i] - abs(vDSub[i] - vGoSub[i])+0.5f;
        //有一个<0,就没碰
        if (inner[i] < 0) return false;
    }
    //三个都大于0
    int Min = 0;
    FLOAT s = 100000.0f;
    for (int i =0; i < 3; i++)
    {
        if (inner[i] / abs(vGoSub[i]) < s)
        {
            s = inner[i] / abs(vGoSub[i]);
            Min = i;
        }
    }
    //只修正最小一个分量
    if (vGoSub[Min] > 0)
    {
        vGoSub[Min] = vGoSub[Min] - inner[Min];
    }else{
        vGoSub[Min] = vGoSub[Min] + inner[Min];
    }
    //最后生成修正值
    vGo = vGoSub[0] * vSub[0] + vGoSub[1] * vSub[1] + vGoSub[2] * vSub[2];
    return true;

}
コード例 #8
0
ファイル: cCamera.cpp プロジェクト: NeuroWhAI/WhatBox
void cCamera::Rotation(float speed/* 음수이냐 양수냐로 방향 설정 */)
{
    D3DXVECTOR3 vcEps = cCore::Input.GetMouseEps()/2.f;

    FLOAT   fYaw    ;
    FLOAT   fPitch  ;

    D3DXVECTOR3 vcZ;
    D3DXVECTOR3 vcY;
    D3DXVECTOR3 vcX;

    D3DXMATRIX rtY;
    D3DXMATRIX rtX;

    // 월드 좌표 y 축에 대한 회전
    fYaw    = D3DXToRadian(vcEps.x * speed);
    D3DXMatrixRotationY(&rtY, fYaw);

    vcZ = m_vLookAt-m_vEyePt;
    vcY = D3DXVECTOR3(m_mtView._12, m_mtView._22, m_mtView._32);

    D3DXVec3TransformCoord(&vcZ, &vcZ, &rtY);
    D3DXVec3TransformCoord(&vcY, &vcY, &rtY);

    m_vLookAt= vcZ + m_vEyePt;
    m_vUpVec  = vcY;
    D3DXMatrixLookAtLH(&m_mtView, &m_vEyePt, &m_vLookAt, &m_vUpVec);

    // 카메라의 x 축에 대한 회전
    fPitch  = D3DXToRadian(vcEps.y * speed);
    vcX = D3DXVECTOR3(m_mtView._11, m_mtView._21, m_mtView._31);
    vcY = D3DXVECTOR3(m_mtView._12, m_mtView._22, m_mtView._32);
    vcZ = m_vLookAt-m_vEyePt;

    D3DXMatrixRotationAxis(&rtX, &vcX, fPitch);
    D3DXVec3TransformCoord(&vcZ, &vcZ, &rtX);
    D3DXVec3TransformCoord(&vcY, &vcY, &rtX);

    m_vLookAt= vcZ + m_vEyePt;
    m_vUpVec  = vcY;
    D3DXMatrixLookAtLH(&m_mtView, &m_vEyePt, &m_vLookAt, &m_vUpVec);
}
コード例 #9
0
ファイル: DXCamera.cpp プロジェクト: popoory67/NinetailEngine
void DXCamera::SetRotate( const D3DXVECTOR3* deltaVec, float speed )
{
	D3DXVECTOR3 epsilonVec = *deltaVec;

	float yaw;
	float pitch;

	D3DXVECTOR3 xVec;
	D3DXVECTOR3 yVec;
	D3DXVECTOR3 zVec;

	D3DXMATRIX rtY;
	D3DXMATRIX rtX;

	// 월드 좌표 y 축에 대한 회전
	yaw = D3DXToRadian( epsilonVec.x * speed );
	D3DXMatrixRotationY( &rtY, yaw );

	zVec = _lookVec - _eyeVec;
	yVec = D3DXVECTOR3( _view._12, _view._22, _view._32 );

	D3DXVec3TransformCoord( &zVec, &zVec, &rtY );
	D3DXVec3TransformCoord( &yVec, &yVec, &rtY );

	_lookVec = zVec + _eyeVec;
	_upVec = yVec;
	D3DXMatrixLookAtLH( &_view, &_eyeVec, &_lookVec, &_upVec );

	// 카메라의 x 축에 대한 회전
	pitch = D3DXToRadian( epsilonVec.y * speed );
	xVec = D3DXVECTOR3( _view._11, _view._21, _view._31 );
	yVec = D3DXVECTOR3( _view._12, _view._22, _view._32 );
	zVec = _lookVec - _eyeVec;

	D3DXMatrixRotationAxis( &rtX, &xVec, pitch );
	D3DXVec3TransformCoord( &zVec, &zVec, &rtX );
	D3DXVec3TransformCoord( &yVec, &yVec, &rtX );

	_lookVec = zVec + _eyeVec;
	_upVec = yVec;
	D3DXMatrixLookAtLH( &_view, &_eyeVec, &_lookVec, &_upVec );
}
コード例 #10
0
ファイル: Camera.cpp プロジェクト: as2120/ZNginx
void Camera::update(float dt)
{
	// Find the net direction the camera is traveling in (since the
	// camera could be running and strafing).
	D3DXVECTOR3 dir(0.0f, 0.0f, 0.0f);
	if( gDInput->keyDown(DIK_W) )
		dir += mLookW;
	if( gDInput->keyDown(DIK_S) )
		dir -= mLookW;
	if( gDInput->keyDown(DIK_D) )
		dir += mRightW;
	if( gDInput->keyDown(DIK_A) )
		dir -= mRightW;

	// Move at mSpeed along net direction.
	D3DXVec3Normalize(&dir, &dir);
	mPosW += dir*mSpeed*dt;


	// We rotate at a fixed speed.
	float pitch  = gDInput->mouseDY() / 150.0f;
	float yAngle = gDInput->mouseDX() / 150.0f;


	// Rotate camera's look and up vectors around the camera's right vector.
	D3DXMATRIX R;
	D3DXMatrixRotationAxis(&R, &mRightW, pitch);
	D3DXVec3TransformCoord(&mLookW, &mLookW, &R);
	D3DXVec3TransformCoord(&mUpW, &mUpW, &R);


	// Rotate camera axes about the world's y-axis.
	D3DXMatrixRotationY(&R, yAngle);
	D3DXVec3TransformCoord(&mRightW, &mRightW, &R);
	D3DXVec3TransformCoord(&mUpW, &mUpW, &R);
	D3DXVec3TransformCoord(&mLookW, &mLookW, &R);


	// Rebuild the view matrix to reflect changes.
	buildView();
	mViewProj = mView * mProj;
}
コード例 #11
0
void CameraClass::RenderForText()
{
	D3DXVECTOR3 up, position, lookAt;
	float yaw, pitch, roll;
	D3DXMATRIX rotationMatrix;


	// Setup the vector that points upwards.
	up.x = 0.0f;
	up.y = 1.0f;
	up.z = 0.0f;

	// Setup the position of the camera in the world.
	position.x = m_positionX;
	position.y = m_positionY;
	position.z = m_positionZ;

	// Setup where the camera is looking by default.
	lookAt.x = 0.0f;
	lookAt.y = 0.0f;
	lookAt.z = 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.
	D3DXMatrixRotationYawPitchRoll(&rotationMatrix, yaw, pitch, roll);

	// Transform the lookAt and up vector by the rotation matrix so the view is correctly rotated at the origin.
	D3DXVec3TransformCoord(&lookAt, &lookAt, &rotationMatrix);
	D3DXVec3TransformCoord(&up, &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.
	D3DXMatrixLookAtLH(&m_viewMatrix, &position, &lookAt, &up);

	return;
}
コード例 #12
0
ファイル: _collision.cpp プロジェクト: Github-J/WinGames
/*------------------------------------------------------------------------------*
| <<< メッシュが視錐台の中にあるかチェック >>>
|	入力	pHit   = メッシュのヒットワーク
|			mWorld = メッシュのワールド座標
|	戻り値	0 :	視錐台の中
|			1 :	一部分が切れている
|			2 :	視錐台の外
*------------------------------------------------------------------------------*/
int		d3_frustum_hit_check(D3_HIT *pHit, MTX *mWorld)
{

	for(int	i =	0; i < 8; i++) D3DXVec3TransformCoord(&pHit->vecWorld[i], &pHit->vecLocal[i], mWorld);
	pHit->vecWorld[8].x	= mWorld->_41;		// バウンディングボックスの中心点
	pHit->vecWorld[8].y	= mWorld->_42;
	pHit->vecWorld[8].z	= mWorld->_43;
	
	//--- 面の作成 --------------------------------------------------
	D3DXPlaneFromPoints(&pHit->planeWorld[0], &pHit->vecWorld[0], &pHit->vecWorld[1], &pHit->vecWorld[2]);	// Near
	D3DXPlaneFromPoints(&pHit->planeWorld[1], &pHit->vecWorld[6], &pHit->vecWorld[7], &pHit->vecWorld[5]);	// Far
	D3DXPlaneFromPoints(&pHit->planeWorld[2], &pHit->vecWorld[2], &pHit->vecWorld[6], &pHit->vecWorld[4]);	// Left
	D3DXPlaneFromPoints(&pHit->planeWorld[3], &pHit->vecWorld[7], &pHit->vecWorld[3], &pHit->vecWorld[5]);	// Right
	D3DXPlaneFromPoints(&pHit->planeWorld[4], &pHit->vecWorld[2], &pHit->vecWorld[3], &pHit->vecWorld[6]);	// Top
	D3DXPlaneFromPoints(&pHit->planeWorld[5], &pHit->vecWorld[1], &pHit->vecWorld[0], &pHit->vecWorld[4]);	// Bottom

	//---------------------------------------------------------------
	WORD	bOutside[8];
	int		out	= 0;

	ZeroMemory(&bOutside, sizeof(bOutside));
	// bitfieldの中の6つの円錐台平面、および結果(1の場合、外部)
	// すべてに対するチェック境界頂点
	float	aa[8];

	for(int	iPoint = 0;	iPoint < 8;	iPoint++)
	{
		for(int	iPlane = 0;	iPlane < 6;	iPlane++)
		{
			aa[iPoint] = 
			   d3.planeFrustum[iPlane].a * pHit->vecWorld[iPoint].x
			+  d3.planeFrustum[iPlane].b * pHit->vecWorld[iPoint].y
			+  d3.planeFrustum[iPlane].c * pHit->vecWorld[iPoint].z
			+  d3.planeFrustum[iPlane].d;

			if(d3.planeFrustum[iPlane].a * pHit->vecWorld[iPoint].x
			+  d3.planeFrustum[iPlane].b * pHit->vecWorld[iPoint].y
			+  d3.planeFrustum[iPlane].c * pHit->vecWorld[iPoint].z
			+  d3.planeFrustum[iPlane].d < 0)
			{
				bOutside[iPoint] |=	(1 << iPlane);
				out++;
			}
		}
	}
	if(out == 0){ return 0;}

	if((bOutside[0]	& bOutside[1] &	bOutside[2]	& bOutside[3]
	&	bOutside[4]	& bOutside[5] &	bOutside[6]	& bOutside[7]) != 0)
	{
		return 2;
	}
	return 1;
}
コード例 #13
0
ファイル: Mesh.cpp プロジェクト: Muret/Zephyr
void Mesh::validate_bounding_box()
{
	bb.reset();
	for (int i = 0; i < vertices_.size(); i++)
	{
		D3DXVECTOR3 world_position, local_position = D3DXVECTOR3(vertices_[i].position);
		D3DXVec3TransformCoord(&world_position, &local_position, &frame_);

		bb.enlarge_bb_with_point(D3DXVECTOR4(world_position, 1));
	}
}
コード例 #14
0
/// 카메라 좌표계의 Y축으로 angle만큼 회전한다.
D3DXMATRIXA16* ZCamera::RotateLocalY( float angle )
{
    D3DXMATRIXA16 matRot;
    D3DXMatrixRotationAxis( &matRot, &m_vUp, angle );

    D3DXVECTOR3 vNewDst;
    D3DXVec3TransformCoord( &vNewDst, &m_vView, &matRot );	// view * rot로 새로운 dst vector를 구한다.
    vNewDst += m_vEye;										// 실제 dst position =  eye Position + dst vector

    return SetView( &m_vEye, &vNewDst, &m_vUp );
}
コード例 #15
0
ファイル: Picking.cpp プロジェクト: puppetmasterzj/DXDemo
void Picking::TransformRay(Ray* ray, D3DXMATRIX* matrix)
{
	//转化射线的起始点, w = 1.
	D3DXVec3TransformCoord(&ray->m_vOrigin, &ray->m_vOrigin, matrix);

	//转化射线的方向向量, w = 0.
	D3DXVec3TransformNormal(&ray->m_vDirection, &ray->m_vDirection, matrix);

	//单位化方向向量
	D3DXVec3Normalize(&ray->m_vDirection, &ray->m_vDirection);
}
コード例 #16
0
void setCameraMatrix(IDirect3DDevice9 * device)
{
	D3DXMATRIX cameraMatrix;
	D3DXMatrixRotationYawPitchRoll(&cameraMatrix, cameraYaw, 0, 0);
	D3DXVECTOR3 transTemp;
	D3DXVec3TransformCoord(&transTemp, &move, &cameraMatrix);
	cameraPos += transTemp;

	D3DXMatrixRotationYawPitchRoll(&cameraMatrix, cameraYaw, cameraPitch, cameraRoll);

	D3DXVec3TransformCoord(&cameraTarget, &D3DXVECTOR3(0, 0, -1), &cameraMatrix);
	D3DXVec3TransformCoord(&cameraUpVector, &D3DXVECTOR3(0, 1, 0), &cameraMatrix);

	D3DXVECTOR3 targetTemp = cameraTarget + cameraPos;

	D3DXMatrixLookAtLH(&cameraMatrix, &cameraPos, &targetTemp, &cameraUpVector);
	device->SetTransform(D3DTS_VIEW, &cameraMatrix);

	move = D3DXVECTOR3(0, 0, 0);
}
コード例 #17
0
ファイル: Camera.cpp プロジェクト: SeraphXIV/Engine
//////////////////////////////////////////////////////////////////////////////////////////
//			Mise a jour																	//
//////////////////////////////////////////////////////////////////////////////////////////
void CCamera::Update()
{
	D3DXVECTOR3 up, position, lookAt;
	float yaw, pitch, roll;
	D3DXMATRIX rotationMatrix;

	// Defini l'axe qui symbolise la verticalite, Y
	up.x = 0.0f;
	up.y = 1.0f;
	up.z = 0.0f;

	// Position de la cam
	position.x = m_positionX;
	position.y = m_positionY;
	position.z = m_positionZ;

	// Endroit ou la cam regarde
	lookAt.x = 0.0f;
	lookAt.y = 0.0f;
	lookAt.z = 1.0f;

	// Yaw (Y axis), pitch (X axis), et roll (Z axis) en radians
	pitch = m_rotationX * 0.0174532925f;
	yaw   = m_rotationY * 0.0174532925f;
	roll  = m_rotationZ * 0.0174532925f;

	// Cree la matrice de rotation pour les yaw/pitch/roll
	D3DXMatrixRotationYawPitchRoll(&rotationMatrix, yaw, pitch, roll);

	// Transferme les vecteurs lookAt et Up via la matrice de rotation pour que l'angle de vue soit correcte
	D3DXVec3TransformCoord(&lookAt, &lookAt, &rotationMatrix);
	D3DXVec3TransformCoord(&up, &up, &rotationMatrix);

	// Relativise la direction de vue par rapport a la position de la cam
	lookAt = position + lookAt;

	// Cree la matrice a partir des trois vecteurs
	D3DXMatrixLookAtLH(&m_viewMatrix, &position, &lookAt, &up);

	return;
}
コード例 #18
0
void c_Camera::UpdateCameraNormal(void)
{
	//位置情報マトリックス生成
	D3DXMATRIX matrix;
	D3DM_INIT(matrix);
	D3DXMatrixTranslation(&matrix,m_vRecPos.x,m_vRecPos.y,m_vRecPos.z);
	
	//現在マトリックスからのズレを計算
	D3DXVec3TransformCoord(&m_vCameraIdentity,&m_vRangeFromRecPos,&matrix);
	
	//目標までのVec3生成
	D3DXVECTOR3 vLook;
	if(m_pmTargetMatrix)
	D3DXVec3TransformCoord(&vLook,&m_vRangeFromTarget,m_pmTargetMatrix);
	else
	D3DXVec3TransformCoord(&vLook,&m_vRangeFromTarget,&matrix);
	//vUp生成
	D3DXVECTOR3 vUP;
	D3DXVec3TransformCoord(&vUP,&D3DXVECTOR3(0.0f,1.0f,0.0f),&matrix);

	//最終合算
	D3DXMatrixLookAtLH(&m_matView,&m_vCameraIdentity,&vLook,&vUP);
	//D3DXVec3TransformCoord(&m_vRecPos,
	//	&D3DXVECTOR3(0.0f,150.0f,-300.0f),
	//	&GetModelMatrix());

	//D3DXVECTOR3 vLook;
	//D3DXVec3TransformCoord(&vLook,
	//	&D3DXVECTOR3(0.0f,100.0f,0.0f),
	//	&GetModelMatrix());

	//D3DXVECTOR3 vUP;
	//D3DXVec3TransformNormal(&vUP,
	//	&D3DXVECTOR3(0.0f,1.0f,0.0f),
	//	&GetModelMatrix());

	//D3DXMatrixLookAtLH(&m_matView,
	//	&m_vRecPos,&vLook,&vUP);
	//D3DM_INIT(m_matView);
	//D3DXMatrixTranslation(&m_matView,m_vRecPos.x,m_vRecPos.y,m_vRecPos.z);
}
コード例 #19
0
ファイル: Camera.cpp プロジェクト: sywor/GameEngine
/*******************************************************************
* update view from Camera heading and pitch
********************************************************************/
void Camera::updateView()
{	
	//create rotation matrix
	D3DXMatrixRotationYawPitchRoll( &rotationMatrix, heading, pitch, 0 );

	//create new view and up vectors
	D3DXVec3TransformCoord( &view, &dV, &rotationMatrix );
	D3DXVec3TransformCoord( &up, &dU, &rotationMatrix );

	//create new forward and strafe vectors
	D3DXVec3Normalize( &forward, &view );	
	D3DXVec3Cross( &strafeRight, &up, &view );
	D3DXVec3Normalize( &strafeRight, &strafeRight );

	//take into account eye position
	view = eye + view;
	
	//update view matrix
	D3DXMatrixLookAtLH( &viewMatrix, &eye, &view, &up );

}
コード例 #20
0
ファイル: ElCamera.cpp プロジェクト: chenbk85/3dlearn
void ElCamera::yaw(float angle)
{
	D3DXMATRIX m;

	// rotate around world y-axis (0, 1, 0) if yaw-axis fixed
	if (mYawFixed)
	{
		D3DXMatrixRotationY(&m, angle);
	}
	else	// else rotate around own up vector
	{
		D3DXMatrixRotationAxis(&m, &mUp, angle);
	}

	// rotate right and look around up or y-axis
	D3DXVec3TransformCoord(&mRight, &mRight, &m);
	D3DXVec3TransformCoord(&mLook, &mLook,  &m);

	calcViewOrientation();
	invalidateView();
}
コード例 #21
0
// This function adds a light in the Dynamic Lights List
void	CDXEngine::AddDynamicLight(D3DLIGHT7 *Light, D3DXMATRIX *RotMatrix, D3DVECTOR *Pos)
{
	// Only if space available in the list
	if(LightsNumber<MAX_DYNAMIC_LIGHTS){
		// copy the light features
		DXLightsList[LightsNumber]=*Light;
		// transform the Direction
		D3DXVec3TransformCoord((D3DXVECTOR3*)&DXLightsList[LightsNumber].dvDirection, (D3DXVECTOR3*)&DXLightsList[LightsNumber].dvDirection, RotMatrix);
		// transform the Position
		D3DXVec3TransformCoord((D3DXVECTOR3*)&DXLightsList[LightsNumber].dvPosition, (D3DXVECTOR3*)&DXLightsList[LightsNumber].dvPosition, RotMatrix);
		// and translate it
		DXLightsList[LightsNumber].dvPosition.x+=Pos->x;
		DXLightsList[LightsNumber].dvPosition.y+=Pos->y;
		DXLightsList[LightsNumber].dvPosition.z+=Pos->z;
		// Enable the light + 1 ( light #0 is the Sun )
		m_pD3DD->SetLight(LightsNumber+1, &DXLightsList[LightsNumber]);
		m_pD3DD->LightEnable(LightsNumber+1, true);
		// a New light in list
		LightsNumber++;
	}
}
コード例 #22
0
ファイル: Camera.cpp プロジェクト: BillyKim/directxcode
// Update the scene for every frame
void Camera::OnFrameMove()
{
	// No need to handle if no drag since last frame move
	if(!m_bDragSinceLastUpdate)
		return ;

	m_bDragSinceLastUpdate = false ;

	if(m_nMouseWheelDelta)
	{
		m_fRadius -= m_nMouseWheelDelta * m_fRadius * 0.1f / 120.0f;

		// Make the radius in range of [m_fMinRadius, m_fMaxRadius]
		// This can Prevent the cube became too big or too small
		m_fRadius = max(m_fRadius, m_fMinRadius) ;
		m_fRadius = min(m_fRadius, m_fMaxRadius) ;
	}

	// The mouse delta is retrieved IN every WM_MOUSE message and do not accumulate, so clear it after one frame
	m_nMouseWheelDelta = 0 ;

	// Get the inverse of the view Arcball's rotation matrix
	D3DXMATRIX mCameraRot ;
	D3DXMatrixInverse( &mCameraRot, NULL, m_ViewArcBall.GetRotationMatrix() );

	// Transform vectors based on camera's rotation matrix
	D3DXVECTOR3 vWorldUp;
	D3DXVECTOR3 vLocalUp = D3DXVECTOR3( 0, 1, 0 );
	D3DXVec3TransformCoord( &vWorldUp, &vLocalUp, &mCameraRot );

	D3DXVECTOR3 vWorldAhead;
	D3DXVECTOR3 vLocalAhead = D3DXVECTOR3( 0, 0, 1 );
	D3DXVec3TransformCoord( &vWorldAhead, &vLocalAhead, &mCameraRot );

	// Update the eye point based on a radius away from the lookAt position
	m_vEyePt = m_vLookatPt - vWorldAhead * m_fRadius;

	// Update the view matrix
	D3DXMatrixLookAtLH( &m_matView, &m_vEyePt, &m_vLookatPt, &vWorldUp );
}
コード例 #23
0
/**
 ****************************************************************************************************
	\fn			void RotateEnemyView( GameEngine::Entity &i_entity, const float &i_yaw, const float &i_pitch )
	\brief		Rotate Enemy view direction
	\param		i_entity the entity to be controlled
	\param		i_yaw yaw angle
	\param		i_pitch pitch angle
	\return		NONE
 ****************************************************************************************************
*/
void EnemyController::RotateEnemyView( GameEngine::Entity &i_entity, const float &i_yaw, const float &i_pitch )
{
	D3DXMATRIX rotationMatrix;
	D3DXMATRIX yawMatrix, pitchMatrix, rollMatrix;
	D3DXVECTOR3 rightVector;
	D3DXVECTOR3 position;
	D3DXVECTOR3 upDirection = GameEngine::D3DXVECTOR3_UP;

	FUNCTION_START;

	position.x = i_entity.m_v3ProjectedPosition.X();
	position.y = i_entity.m_v3ProjectedPosition.Y();
	position.z = i_entity.m_v3ProjectedPosition.Z();

	D3DXVec3Cross( &rightVector, &GameEngine::D3DXVECTOR3_UP, &i_entity.m_vLookAt );
	rightVector.y = 0.0f;
	D3DXVec3Normalize( &rightVector, &rightVector );

	D3DXMatrixRotationAxis( &pitchMatrix, &rightVector, D3DXToRadian(i_pitch) );
	D3DXMatrixRotationAxis( &yawMatrix, &upDirection, D3DXToRadian(i_yaw) );
	D3DXMatrixRotationAxis( &rollMatrix, &i_entity.m_vLookAt, D3DXToRadian(0.0f) );

	D3DXMatrixMultiply( &rotationMatrix, &yawMatrix, &pitchMatrix );
	D3DXMatrixMultiply( &rotationMatrix, &rollMatrix, &rotationMatrix );

	D3DXVec3TransformCoord( &rightVector, &rightVector, &rotationMatrix );
	D3DXVec3TransformCoord( &upDirection, &upDirection, &rotationMatrix );
	D3DXVec3Cross( &i_entity.m_vLookAt, &rightVector, &upDirection );

	if( fabs(D3DXVec3Dot(&upDirection, &rightVector)) > 0.01f )
	{
		D3DXVec3Cross( &upDirection, &i_entity.m_vLookAt, &rightVector );
	}

	D3DXVec3Normalize( &rightVector, &rightVector );
	D3DXVec3Normalize( &upDirection, &upDirection );
	D3DXVec3Normalize( &i_entity.m_vLookAt, &i_entity.m_vLookAt );

	FUNCTION_FINISH;
}
コード例 #24
0
ファイル: Cube.cpp プロジェクト: BillyKim/directxcode
void Cube::UpdateMinMaxPoints(D3DXVECTOR3& rotate_axis, int num_half_PI)
{
	// Build up the rotation matrix with the overall angle
	// This angle is times of D3DX_PI / 2.
	D3DXMATRIX rotate_matrix;
	D3DXMatrixIdentity(&rotate_matrix);
	
	if (num_half_PI == 0)
	{
		D3DXMatrixRotationAxis(&rotate_matrix, &rotate_axis, 0);
	}
	else if (num_half_PI == 1)
	{
		D3DXMatrixRotationAxis(&rotate_matrix, &rotate_axis, D3DX_PI / 2);
	}
	else if (num_half_PI == 2)
	{
		D3DXMatrixRotationAxis(&rotate_matrix, &rotate_axis, D3DX_PI);
	}
	else // (num_half_PI == 3)
	{
		D3DXMatrixRotationAxis(&rotate_matrix, &rotate_axis, 1.5f * D3DX_PI);
	}

	// Translate the min_point_ and max_point_ of the cube, after rotation, the two points 
	// was changed, need to recalculate them with the rotation matrix.
	D3DXVECTOR3 min_point;
	D3DXVECTOR3 max_point;
	D3DXVec3TransformCoord(&min_point, &min_point_, &rotate_matrix);
	D3DXVec3TransformCoord(&max_point, &max_point_, &rotate_matrix);

	// After translate by the world matrix, the min/max point need recalculate
	min_point_.x = min(min_point.x, max_point.x);
	min_point_.y = min(min_point.y, max_point.y);
	min_point_.z = min(min_point.z, max_point.z);

	max_point_.x = max(min_point.x, max_point.x);
	max_point_.y = max(min_point.y, max_point.y);
	max_point_.z = max(min_point.z, max_point.z);
}
コード例 #25
0
ファイル: bbox.cpp プロジェクト: toughie88/Easy3D-1
int CBBox::TransformOnlyWorld( CBBox* srcbbx, D3DXMATRIX* matWorld )
{
	D3DXVECTOR3 befvert[8];

	befvert[0] = D3DXVECTOR3( srcbbx->maxx, srcbbx->maxy, srcbbx->maxz );
	befvert[1] = D3DXVECTOR3( srcbbx->maxx, srcbbx->miny, srcbbx->maxz );
	befvert[2] = D3DXVECTOR3( srcbbx->minx, srcbbx->miny, srcbbx->maxz );
	befvert[3] = D3DXVECTOR3( srcbbx->minx, srcbbx->maxy, srcbbx->maxz );

	befvert[4] = D3DXVECTOR3( srcbbx->maxx, srcbbx->maxy, srcbbx->minz );
	befvert[5] = D3DXVECTOR3( srcbbx->maxx, srcbbx->miny, srcbbx->minz );
	befvert[6] = D3DXVECTOR3( srcbbx->minx, srcbbx->miny, srcbbx->minz );
	befvert[7] = D3DXVECTOR3( srcbbx->minx, srcbbx->maxy, srcbbx->minz );

	D3DXVECTOR3 aftvert[8];

	InitParams();//!!!!!!!!!

	int vno;
	float x, y, z;
	for( vno = 0; vno < 8; vno++ ){
		D3DXVec3TransformCoord( aftvert + vno, befvert + vno, matWorld );
		x = aftvert[vno].x;
		y = aftvert[vno].y;
		z = aftvert[vno].z;

		if( x < minx ){
			minx = x;
		}
		if( x > maxx ){
			maxx = x;
		}

		if( y < miny ){
			miny = y;
		}
		if( y > maxy ){
			maxy = y;
		}

		if( z < minz ){
			minz = z;
		}
		if( z > maxz ){
			maxz = z;
		}
	}
	setflag = 1;


	return 0;
}
コード例 #26
0
ファイル: Object.cpp プロジェクト: Mootie/ATools
void CObject::_updateMatrix()
{
	D3DXMATRIX mat;
	D3DXMatrixIdentity(&m_TM);
	D3DXMatrixScaling(&mat, m_scale.x, m_scale.y, m_scale.z);
	D3DXMatrixMultiply(&m_TM, &m_TM, &mat);
	D3DXMatrixRotationYawPitchRoll(&mat, D3DXToRadian(-m_rot.y), D3DXToRadian(-m_rot.x), D3DXToRadian(m_rot.z));
	D3DXMatrixMultiply(&m_TM, &m_TM, &mat);
	D3DXMatrixTranslation(&mat, m_pos.x, m_pos.y, m_pos.z);
	D3DXMatrixMultiply(&m_TM, &m_TM, &mat);

	if (m_model)
	{
		const Bounds& bounds = m_model->GetBounds();
		m_bounds[0].x = bounds.Min.x;
		m_bounds[0].y = bounds.Max.y;
		m_bounds[0].z = bounds.Min.z;

		m_bounds[1].x = bounds.Max.x;
		m_bounds[1].y = bounds.Max.y;
		m_bounds[1].z = bounds.Min.z;

		m_bounds[2].x = bounds.Max.x;
		m_bounds[2].y = bounds.Max.y;
		m_bounds[2].z = bounds.Max.z;

		m_bounds[3].x = bounds.Min.x;
		m_bounds[3].y = bounds.Max.y;
		m_bounds[3].z = bounds.Max.z;

		m_bounds[4].x = bounds.Min.x;
		m_bounds[4].y = bounds.Min.y;
		m_bounds[4].z = bounds.Min.z;

		m_bounds[5].x = bounds.Max.x;
		m_bounds[5].y = bounds.Min.y;
		m_bounds[5].z = bounds.Min.z;

		m_bounds[6].x = bounds.Max.x;
		m_bounds[6].y = bounds.Min.y;
		m_bounds[6].z = bounds.Max.z;

		m_bounds[7].x = bounds.Min.x;
		m_bounds[7].y = bounds.Min.y;
		m_bounds[7].z = bounds.Max.z;

		for (int i = 0; i < 8; i++)
			D3DXVec3TransformCoord(&m_bounds[i], &m_bounds[i], &m_TM);
	}

	m_updateMatrix = false;
}
コード例 #27
0
void DX10_Camera_FirstPerson::Process(float _dt)
{
	// Get mouse input
	//m_pDirectInput->DetectMouseInput(&m_yawChange, &m_pitchChange);
	m_yaw += m_yawChange * _dt;
	m_pitch += m_pitchChange * _dt;

	// Prevent Gimbal Lock
	if (m_pitch > m_maxRotation)
	{
		m_pitch = m_maxRotation;
	}
	if (m_pitch < m_minRotation)
	{
		m_pitch = m_minRotation;
	}

	// Create a full rotation matrix
	D3DXMatrixRotationYawPitchRoll(&m_rotationMatrix, m_yaw, m_pitch, 0);
	D3DXVec3TransformCoord(&m_target, &m_defaultForward, &m_rotationMatrix);
	D3DXVec3Normalize(&m_target, &m_target);

	// Calculate a Yaw rotation matrix
	D3DXMATRIX RotateYTempMatrix;
	D3DXMatrixRotationY(&RotateYTempMatrix, m_yaw);

	// Update the Local camera Axis around the Y axis
	D3DXVec3TransformNormal(&m_right, &m_defaultRight, &RotateYTempMatrix);
	D3DXVec3TransformNormal(&m_up, &m_up, &RotateYTempMatrix);
	D3DXVec3TransformNormal(&m_forward, &m_defaultForward, &RotateYTempMatrix);

	// Adjust the position
	m_position += m_moveStrafe * m_right * _dt;
	m_position += m_moveForwards * m_forward * _dt;
	m_position += m_moveFly * m_up * _dt;

	// reset the the movement values
	m_moveStrafe = 0.0f;
	m_moveForwards = 0.0f;
	m_moveFly = 0.0f;
	m_yawChange = 0.0f;
	m_pitchChange = 0.0f;

	// Pick a target in front of the camera
	m_target = m_position + m_target;

	// Create the View matrix
	D3DXMatrixLookAtLH(&m_matView, &m_position, &m_target, &m_up);

	m_pRenderer->SetViewMatrix(m_matView);
	m_pRenderer->SetEyePosition(m_position);
}
コード例 #28
0
ファイル: FlyGeometry.cpp プロジェクト: Engman/fly
Entity* FLYCALL FlyEngine_Core::Geometry_Pick(const vector<Entity*>& obj, int posX, int posY)
{
	D3DXMATRIX inverseWorldMatrix;
	D3DXMATRIX InvView = this->activeCamera->GetViewMatrix();
	D3DXVECTOR3 origin = this->activeCamera->GetPosition();
	D3DXVECTOR3 direction;
	D3DXVECTOR3 rayOrigin;
	D3DXVECTOR3 rayDirection;
	float length = 1000000.0f;
	Entity* picked = NULL;
	

	D3DXMatrixInverse(&InvView, 0, &InvView);

	// Move the mouse coordinates into the -1 to +1 range.
	float pointX = ((2.0f * (float)posX) / D3DShell::self()->getWidth()) - 1.0f;
	float pointY = (((2.0f * (float)posY) / D3DShell::self()->getHeight()) - 1.0f) * -1.0f;
		
	// Adjust the points using the projection matrix to account for the aspect ratio of the viewport.
	pointX = pointX / this->activeCamera->GetProjectionMatrix()._11;
	pointY = pointY / this->activeCamera->GetProjectionMatrix()._22;

	// Calculate the direction of the picking ray in view space.
	direction.x = (pointX * InvView._11) + (pointY * InvView._21) + InvView._31;
	direction.y = (pointX * InvView._12) + (pointY * InvView._22) + InvView._32;
	direction.z = (pointX * InvView._13) + (pointY * InvView._23) + InvView._33;

	for (int i = 0; i < (int)obj.size(); i++)
	{
		//// Get the inverse of the translated world matrix.
		D3DXMatrixInverse(&inverseWorldMatrix, NULL, &obj[i]->getWorld());
		//
		//// Transform the ray origin and the ray direction from view space to world space.
		D3DXVec3TransformCoord(&rayOrigin, &origin, &inverseWorldMatrix);
		D3DXVec3TransformNormal(&rayDirection, &direction, &inverseWorldMatrix);


		// Normalize the ray direction.
		D3DXVec3Normalize(&rayDirection, &rayDirection);
		
		float len = RayVSSphereLength(rayDirection, rayOrigin, obj[i]->getBoundingSphere()->center, obj[i]->getBoundingSphere()->radius);
		// Now perform the ray-sphere intersection test.
		if(len != -1 && len <= length)
		{
			length = len;
			picked = obj[i];
		}
		
	}

	return picked;
}
コード例 #29
0
ファイル: Math.cpp プロジェクト: kansifang/LevelUp
FCE_AxisAlignedBoundingBox FCE_AxisAlignedBoundingBox::Transform( const D3DXMATRIX* pMat ){
	D3DXVECTOR3 pCorners[8];
	Corners(pCorners);
	FCE_AxisAlignedBoundingBox ret;

	for( int iCorner = 0; iCorner < 8; ++iCorner ){
		D3DXVECTOR3 transformed;
		D3DXVec3TransformCoord( &transformed, &(pCorners[iCorner]), pMat );
		ret.AddPoints(1, &transformed );
	}

	return ret;
}
コード例 #30
0
/// 카메라 좌표계의 X축으로 angle만큼 회전한다.
D3DXMATRIXA16* ZCamera::RotateLocalX( float angle )
{
    D3DXMATRIXA16 matRot;
    D3DXMatrixRotationAxis( &matRot, &m_vCross, angle );

    D3DXVECTOR3 vNewDst,vNewUp;
    D3DXVec3TransformCoord( &vNewDst, &m_vView, &matRot );	// view * rot로 새로운 dst vector를 구한다.
//	D3DXVec3Cross( &vNewUp, &vNewDst, &m_vCross );			// cross( dst, x축)으로 up vector를 구한다.
//	D3DXVec3Normalize( &vNewUp, &vNewUp );					// up vector를 unit vector로...
    vNewDst += m_vEye;										// 실제 dst position =  eye Position + dst vector

    return SetView( &m_vEye, &vNewDst, &m_vUp );
}