Vector3 FPMovement::movementFP(Vector3 dir)
{
	Vector3 direction = Vector3(0,0,0);
	//D3DXVec3Transform(&start,&lightSource.dir,&rotateX)
	if(GetAsyncKeyState('W') & 0x8000)
		direction = Vector3(dir.x,0,dir.z);
	if(GetAsyncKeyState('A') & 0x8000)
	{
		Matrix r;
		RotateY(&r,ToRadian(-90.0f));
		Vector4 d;
		D3DXVec3Transform(&d,&dir,&r);
		direction = Vector3(d.x,0,d.z);
	}
	if(GetAsyncKeyState('S') & 0x8000)
		direction = Vector3(dir.x,0,dir.z)*-1;
	if(GetAsyncKeyState('D') & 0x8000)
	{
		Matrix r;
		RotateY(&r,ToRadian(90.0f));
		Vector4 d;
		D3DXVec3Transform(&d,&dir,&r);
		direction = Vector3(d.x,0,d.z);
	}
	
	if(direction != VectorZero)
		Normalize(&direction, &direction);

	return direction;
}
示例#2
0
void RotateCameraHorizontally(float radian)
{
    /*
        常规变换
    */
    //将eyePoint绕lookAt点旋转
    D3DXMATRIX rotation;
    //D3DXMatrixRotationAxis:
    // D3DXMATRIX * D3DXMatrixRotationAxis(
    //__inout  D3DXMATRIX *pOut,
    //    __in     const D3DXVECTOR3 *pV,
    //    __in     FLOAT Angle
    //    );
    //其功能是生成绕原点处的方向向量为pV的轴旋转角度Angle的旋转变换矩阵
    //所以在绕非原点旋转时需要先将目标点的旋转变换为绕原点旋转
    D3DXMatrixRotationAxis(&rotation, &up, radian);
    D3DXVECTOR4 tmp;
    D3DXVec3Transform(&tmp, &(eyePoint-lookAt), &rotation);
    eyePoint = lookAt + D3DXVECTOR3(tmp.x, tmp.y, tmp.z);

    /*
        fixed 变换
    */
    {
        //将eyePoint绕lookAt点旋转
        D3DXMATRIX rotation;
        D3DXMatrixRotationAxis(&rotation, &fixedUp, radian);
        D3DXVECTOR4 tmp;
        D3DXVec3Transform(&tmp, &(fixedEyePoint-fixedLookAt), &rotation);
        fixedEyePoint = fixedLookAt + D3DXVECTOR3(tmp.x, tmp.y, tmp.z);
    }
}
示例#3
0
void Storm3D_SpotlightShared::setClipPlanes(const float *cameraView)
{

	D3DXMATRIX m(cameraView);
	float determinant = D3DXMatrixDeterminant(&m);
	D3DXMatrixInverse(&m, &determinant, &m);
	D3DXMatrixTranspose(&m, &m);

	D3DXVECTOR3 d(direction.x, direction.y, direction.z);
	VC2 bd(d.x, d.z);
	bd.Normalize();		
	D3DXVECTOR3 p1(position.x - 8*bd.x, position.y, position.z - 8*bd.y);
	//D3DXVECTOR3 p1(position.x - 1*bd.x, position.y, position.z - 1*bd.y);
	D3DXVECTOR3 p2(p1.x, p1.y + 5.f, p1.z);

	float angle = D3DXToRadian(fov) * .55f;

	D3DXPLANE leftPlane;
	D3DXMATRIX leftTransform;
	D3DXMatrixRotationY(&leftTransform, -angle);
	D3DXVECTOR3 leftPoint(direction.x, 0, direction.z);
	D3DXVECTOR4 leftPoint2;
	D3DXVec3Transform(&leftPoint2, &leftPoint, &leftTransform);
	leftPoint = p1;
	leftPoint.x += leftPoint2.x;
	leftPoint.z += leftPoint2.z;
	D3DXPlaneFromPoints(&leftPlane, &p1, &p2, &leftPoint);
	D3DXPlaneNormalize(&leftPlane, &leftPlane);
	D3DXPlaneTransform(&leftPlane, &leftPlane, &m);

	D3DXPLANE rightPlane;
	D3DXMATRIX rightTransform;
	D3DXMatrixRotationY(&rightTransform, angle);
	D3DXVECTOR3 rightPoint(direction.x, 0, direction.z);
	D3DXVECTOR4 rightPoint2;
	D3DXVec3Transform(&rightPoint2, &rightPoint, &rightTransform);
	rightPoint = p1;
	rightPoint.x += rightPoint2.x;
	rightPoint.z += rightPoint2.z;
	D3DXPlaneFromPoints(&rightPlane, &rightPoint, &p2, &p1);
	D3DXPlaneNormalize(&rightPlane, &rightPlane);
	D3DXPlaneTransform(&rightPlane, &rightPlane, &m);

	D3DXPLANE backPlane;
	D3DXVECTOR3 pb(p1.x, p1.y, p1.z);
	D3DXPlaneFromPointNormal(&backPlane, &pb, &d);
	D3DXPlaneNormalize(&backPlane, &backPlane);
	D3DXPlaneTransform(&backPlane, &backPlane, &m);

	device.SetClipPlane(0, leftPlane);
	device.SetClipPlane(1, rightPlane);
	device.SetClipPlane(2, backPlane);
	device.SetRenderState(D3DRS_CLIPPLANEENABLE, D3DCLIPPLANE0 | D3DCLIPPLANE1 | D3DCLIPPLANE2);
}
示例#4
0
void RotateCameraVertically(float radian)
{
    /*
        常规变换
    */
    {
        D3DXVECTOR3 vForward = lookAt - eyePoint;
        D3DXVec3Normalize(&vForward, &vForward);

        D3DXVECTOR3 vLeft;
        D3DXVec3Cross(&vLeft, &up, &vForward);
        D3DXVec3Normalize(&vLeft, &vLeft);

        D3DXMATRIX rotation;
        D3DXMatrixRotationAxis(&rotation, &vLeft, radian);
        D3DXVECTOR4 tmp;
        D3DXVec3Transform(&tmp, &(eyePoint-lookAt), &rotation);
        eyePoint = lookAt + D3DXVECTOR3(tmp.x, tmp.y, tmp.z);

        //竖直方向旋转时,up方向随之变化,需要更新
        vForward = lookAt - eyePoint;
        D3DXVec3Normalize(&vForward, &vForward);
        D3DXVec3Cross(&up, &vForward, &vLeft);
        D3DXVec3Normalize(&up, &up);
    }
    
    /*
        fixed 变换
    */
    {
        D3DXVECTOR3 vForward = fixedLookAt - fixedEyePoint;
        D3DXVec3Normalize(&vForward, &vForward);

        D3DXVECTOR3 vLeft;
        D3DXVec3Cross(&vLeft, &fixedUp, &vForward);
        D3DXVec3Normalize(&vLeft, &vLeft);

        D3DXMATRIX rotation;
        D3DXMatrixRotationAxis(&rotation, &vLeft, radian);
        D3DXVECTOR4 tmp;
        D3DXVec3Transform(&tmp, &(fixedEyePoint-fixedLookAt), &rotation);
        fixedEyePoint = fixedLookAt + D3DXVECTOR3(tmp.x, tmp.y, tmp.z);

        //竖直方向旋转时,up方向随之变化,需要更新
        vForward = fixedLookAt - fixedEyePoint;
        D3DXVec3Normalize(&vForward, &vForward);
        D3DXVec3Cross(&fixedUp, &vForward, &vLeft);
        D3DXVec3Normalize(&fixedUp, &fixedUp);
    }
}
示例#5
0
void CameraManager::Update( float fpsMod )
{
	if ( m_pCam == NULL )
		return;

	bool W = (GetAsyncKeyState(0x0057) & 0x8000) ? true : false;
	bool S = (GetAsyncKeyState(0x0053) & 0x8000) ? true : false;
	bool A = (GetAsyncKeyState(0x0041) & 0x8000) ? true : false;
	bool D = (GetAsyncKeyState(0x0044) & 0x8000) ? true : false;

	POINT Mouse;
	GetCursorPos(&Mouse);

	SetCursorPos(600, 600);

	Vec3 cAxis;
	D3DXVec3Cross(&cAxis, &m_pCam->Up, &m_pCam->Direction);

	float Speed = 1.0f;
	fpsMod = 0.01f;
	if(W) m_pCam->Position += m_pCam->Direction * (Speed * fpsMod);
	if(S) m_pCam->Position -= m_pCam->Direction * (Speed * fpsMod);
	if(A) m_pCam->Position -= cAxis * (Speed * fpsMod);
	if(D) m_pCam->Position +=  cAxis * (Speed * fpsMod);

	Vec4 TransformTemp;

	Quat RXq;
	D3DXQuaternionRotationAxis(&RXq, &m_pCam->Up, ( (D3DX_PI / 4.0f) / 150) * (Mouse.x - 600));

	Matrix44 RX;
	D3DXMatrixRotationQuaternion(&RX, &RXq);

	D3DXVec3Transform(&TransformTemp, &m_pCam->Direction, &RX);
	m_pCam->Direction.x = TransformTemp.x; m_pCam->Direction.y = TransformTemp.y; m_pCam->Direction.z = TransformTemp.z;

	Quat RYq;
	D3DXVec3Cross(&cAxis, &m_pCam->Up, &m_pCam->Direction);
	D3DXQuaternionRotationAxis(&RYq, &cAxis, ( (D3DX_PI / 4.0f) / 150) * (Mouse.y - 600));

	Matrix44 RY;
	D3DXMatrixRotationQuaternion(&RY, &RYq);

	D3DXVec3Transform(&TransformTemp, &m_pCam->Direction, &RY);
	m_pCam->Direction.x = TransformTemp.x; m_pCam->Direction.y = TransformTemp.y; m_pCam->Direction.z = TransformTemp.z;

	Vec3 Target = m_pCam->Position + m_pCam->Direction;
	D3DXMatrixLookAtLH(&m_pCam->View, &m_pCam->Position, &Target, &m_pCam->Up);
}
示例#6
0
void Sprite::RenderFirstFrame(float x, float y, float priority) const
{
	RECT srect;

	srect.left = 0;
	srect.top = 0;
	srect.right = srect.left + _Width;
	srect.bottom = srect.top + _Height;

	D3DXVECTOR3 position(x, y, 0);

	//
	// WORLD TO VIEWPORT TRANSFORM USING MATRIX
	//
	D3DXMATRIX mt;
	D3DXMatrixIdentity(&mt);
	mt._22 = -1.0f;
	mt._41 = -Camera::GetInstance()->GetViewPort().x;
	mt._42 = Camera::GetInstance()->GetViewPort().y;
	D3DXVECTOR4 vp_pos;
	D3DXVec3Transform(&vp_pos, &position, &mt);

	D3DXVECTOR3 p(vp_pos.x, vp_pos.y, priority);
	D3DXVECTOR3 center(float(_Width) / 2, float(_Height) / 2, 0);

	_SpriteHandler->Draw(
		_Image,
		&srect,
		&center,
		&p,
		D3DCOLOR_XRGB(255, 255, 255)
		);
}
示例#7
0
文件: OBB.cpp 项目: 7zhang/studies
vector<D3DXVECTOR3> OBB::GetCorners() {
    D3DXMATRIX pos, rot, world;
    D3DXMatrixTranslation(&pos, m_pos.x, m_pos.y, m_pos.z);
    D3DXMatrixRotationQuaternion(&rot, &m_rot);
    D3DXMatrixMultiply(&world, &rot, &pos);

    vector<D3DXVECTOR3> p;
    p.push_back(D3DXVECTOR3(m_size.x, m_size.y, m_size.z));
    p.push_back(D3DXVECTOR3(m_size.x, m_size.y, -m_size.z));
    p.push_back(D3DXVECTOR3(m_size.x, -m_size.y, m_size.z));
    p.push_back(D3DXVECTOR3(m_size.x, -m_size.y, -m_size.z));
    p.push_back(D3DXVECTOR3(-m_size.x, m_size.y, m_size.z));
    p.push_back(D3DXVECTOR3(-m_size.x, m_size.y, -m_size.z));
    p.push_back(D3DXVECTOR3(-m_size.x, -m_size.y, m_size.z));
    p.push_back(D3DXVECTOR3(-m_size.x, -m_size.y, -m_size.z));

    int numCorners = (int)p.size();
    for (int i=0; i<numCorners; i++) {
        D3DXVECTOR4 v4;
        D3DXVec3Transform(&v4, &p[i], &world);
        p[i] = D3DXVECTOR3(v4.x, v4.y, v4.z);
    }

    return p;
}
示例#8
0
vector3d	CCamera::setPositionEntity(vector3d	&pos)
{
	if (!m_Instance)
		m_Instance = new CCamera();
	D3DXVec3Transform(&m_Viewport, &pos, &m_MatrixTransform);
	return D3DXVECTOR3(m_Viewport.x, m_Viewport.y, 0);
}
///////////////////////////////////////////////////////////////
//
// CVertexStreamBoundingBoxManager::CalcDistanceSq
//
// Calculate distance squared from the camera to the bounding box
//
///////////////////////////////////////////////////////////////
float CVertexStreamBoundingBoxManager::CalcDistanceSq ( const SCurrentStateInfo2& state, const CBox& boundingBox )
{
    // Get camera pos
    const D3DXMATRIX& matWorld = g_pDeviceState->TransformState.WORLD;
    const D3DXMATRIX& matView = g_pDeviceState->TransformState.VIEW;

    D3DXMATRIX matViewInv;
    D3DXMatrixInverse ( &matViewInv, NULL, &matView );
    const CVector& vecCamPos = (CVector&)matViewInv.m[3][0];

    // Get object rotation
    const CVector& vecObjRight = (CVector&)matWorld.m[0][0];
    const CVector& vecObjFwd   = (CVector&)matWorld.m[1][0];
    const CVector& vecObjUp    = (CVector&)matWorld.m[2][0];
    const CVector* vecBoxAxes[3] = { &vecObjRight, &vecObjFwd, &vecObjUp };

    // Adjust for off-center bounding box
    const CVector boxExtents = ( boundingBox.vecMax - boundingBox.vecMin ) * 0.5f;
    const CVector boxOrigin  = ( boundingBox.vecMax + boundingBox.vecMin ) * 0.5f;

    D3DXVECTOR4 vecResult;
    D3DXVec3Transform ( &vecResult, (D3DXVECTOR3*)&boxOrigin, &matWorld );

    // World position of the bounding box center
    const CVector& vecObjPos = (CVector&)vecResult;

    return GetBoxDistanceSq ( vecObjPos, vecCamPos, &boxExtents.fX, vecBoxAxes );
}
示例#10
0
D3DXVECTOR2 CViewport::TransformMatrix(D3DXVECTOR2 pos) {
	D3DXVECTOR4 result;

	D3DXVECTOR2 x = m_ViewportPos;
	D3DXVec3Transform(&result, &D3DXVECTOR3(pos.x, pos.y, 0), &m_MatrixTransform);
	return D3DXVECTOR2(static_cast<int>(result.x), static_cast<int>(result.y));
}
示例#11
0
void GameObject::updateAABBBox()
{
	D3DXVECTOR3 modifiedVertex;
	D3DXVECTOR4 tempMat;

	float minX, minY, minZ;
	float maxX, maxY, maxZ;

	minX = minY = minZ = HUGE;
	maxX = maxY = maxZ = -HUGE;

	D3DXVECTOR3* pVertex;
	if ( SUCCEEDED( m_pMesh->LockVertexBuffer( D3DLOCK_READONLY, (VOID**)&pVertex ) ) )
	{
		for ( DWORD i = 0; i < m_pMesh->GetNumVertices(); ++i )
		{
			D3DXVec3Transform( &tempMat, &pVertex[i], &m_Matrix );
			modifiedVertex = D3DXVECTOR3( tempMat.x, tempMat.y, tempMat.z );

			maxX = ( maxX < modifiedVertex.x ? modifiedVertex.x : maxX );
			maxY = ( maxY < modifiedVertex.y ? modifiedVertex.y : maxY );
			maxZ = ( maxZ < modifiedVertex.z ? modifiedVertex.z : maxZ );

			minX = ( minX < modifiedVertex.x ? minX : modifiedVertex.x );
			minY = ( minY < modifiedVertex.y ? minY : modifiedVertex.y );
			minZ = ( minZ < modifiedVertex.z ? minZ : modifiedVertex.z );
		}
	}

	m_AABBBox.m_min = D3DXVECTOR3( minX, minY, minZ );
	m_AABBBox.m_max = D3DXVECTOR3( maxX, maxY, maxZ );
}
示例#12
0
void Mesh::surfRev(int numSlices, Vector3 linePoints[], int numPoints)
{
	float angleBetween = ToRadian(360 / numSlices);
	Matrix rotate;
	Identity(&rotate);
	RotateY(&rotate,angleBetween);
	Vector3* originalPoints = linePoints;
	//arrays of the points for the caps if they are necessary
	//in the event the shap has a hole in one of the ends
	Vector3* topCap = new Vector3[numSlices];
	Vector3* bottomCap = new Vector3[numSlices];

	for(int i = 0; i < numSlices; i++)
	{
		topCap[i] = originalPoints[numPoints-1];
		bottomCap[i] = originalPoints[0];
		Vector3* newPoints = new Vector3[numPoints];
		for(int k = 0; k < numPoints; k++)
		{
			Vector4 point = Vector4(originalPoints[k].x,originalPoints[k].y,originalPoints[k].z,1);
			D3DXVec3Transform(&point,&originalPoints[k],&rotate);
			newPoints[k] = Vector3(point.x,point.y,point.z);
		}
		for(int j = 0; j < numPoints; j++)
		{
			Vector3* side = new Vector3[4];
			side[0] = originalPoints[j];
			if((j+1)<numPoints)
			{
				side[1] = originalPoints[j+1];
				side[2] = newPoints[j+1];
			}
			else
			{
				side[1] = originalPoints[0];
				side[2] = newPoints[0];
			}
			side[3] = newPoints[j];
			makePolygon(side,4,j);
			//set the texture coordinates
			vertices[vertices.size()-4].texC = Vector2((i*numSlices*(1/360)),0);
			vertices[vertices.size()-3].texC = Vector2((i*numSlices*2*(1/360)),0);
			vertices[vertices.size()-2].texC = Vector2((i*numSlices*2*(1/260)),1);
			vertices[vertices.size()-1].texC = Vector2((i*numSlices*(1/360)),1);
		}
		originalPoints = newPoints;
		//delete[] newPoints;
	}

	//add end cap if necessary
	if(linePoints[numPoints-1].x!=0)
	{
		makePolygon(topCap,numSlices,0);
	}
	if(linePoints[0].x!=0)
	{
		makePolygon(bottomCap,numSlices,0);
	}
	delete[] topCap;
}
示例#13
0
Vect3f CParticleEmitterBox::CalculateParticlePosition()
{
	Vect3f l_Point;

	l_Point.x = BoostRandomHelper::GetFloat(m_BoxMin.x, m_BoxMax.x);
	l_Point.y = BoostRandomHelper::GetFloat(m_BoxMin.y, m_BoxMax.y);
	l_Point.z = BoostRandomHelper::GetFloat(m_BoxMin.z, m_BoxMax.z);

	if(m_UseRotation)
	{
		D3DXMATRIX matRotX, matRotY, matRotZ, matRes;
		
		D3DXMatrixRotationX(&matRotX, mathUtils::Deg2Rad(m_Pitch));
		D3DXMatrixRotationZ(&matRotZ, mathUtils::Deg2Rad(m_Roll));
		D3DXMatrixRotationY(&matRotY, mathUtils::Deg2Rad(m_Yaw));

		D3DXMatrixMultiply(&matRes, &matRotY, &matRotX);
		D3DXMatrixMultiply(&matRes, &matRes, &matRotZ);

		D3DXVECTOR3 pos(l_Point.x, l_Point.y, l_Point.z);
		D3DXVECTOR4 posTrans(0.0f, 0.0f, 0.0f, 0.0f);

		D3DXVec3Transform(&posTrans, &pos, &matRes);

		l_Point.x = posTrans.x;
		l_Point.y = posTrans.y;
		l_Point.z = posTrans.z;
	}

	return l_Point;
}
示例#14
0
文件: Main.cpp 项目: Odinra/DirectX
//
// Framework Functions
//
void UpdateCameraThirdPerson()
{
	D3DXMATRIX rotationMatrix;
	D3DXMatrixRotationY(&rotationMatrix, -avatarYaw);
	D3DXVECTOR3 transformedReference;
	D3DXVECTOR4 vec4;
	D3DXVec3Transform(&vec4, &thirdPersonReference, &rotationMatrix);
	transformedReference.x = vec4.x;
	transformedReference.y = vec4.y;
	transformedReference.z = vec4.z;

	D3DXVECTOR3 cameraPosition(transformedReference.z + AvatarPosition.x, transformedReference.y + transformedReference.y, transformedReference.x + transformedReference.z);

	D3DXVECTOR3 up(0,1,0);
	D3DXMatrixLookAtLH(&mview, &cameraPosition, &AvatarPosition, &up);


	//Device->SetTransform(D3DTS_VIEW, &mview);

	D3DXMatrixPerspectiveFovLH(&mprojection, D3DX_PI / 4, aspectRatio, 0.1f, 5001.0f);

	D3DXMATRIX myaw, mpos;
	D3DXMatrixRotationY(&mpos, avatarYaw);
	D3DXMatrixTranslation(&mpos, AvatarPosition.x, AvatarPosition.y, AvatarPosition.z);
	D3DXMatrixMultiply(&mworld, &myaw, &mpos);

	//Device->SetTransform(D3DTS_WORLD, &mworld);
}
示例#15
0
void SimplexSphereGenerator::spawnPopup()
{
	srand(time(NULL));
	uniform_int_distribution<int> rand2(0, spherePoints.size() - 1);
	static default_random_engine e_rand;
	int iterCount = 1000;

	while (iterCount-- > 0)
	{
		int ind = rand2(e_rand);
		D3DXVECTOR3 p = spherePoints[ind];
		p.y = 0;
		D3DXVec3Normalize(&p, &p);
		D3DXVECTOR4 t;
		D3DXVec3Transform(&t, &p, &matWorld);

		if (t.z > .5f && t.x < -0.2f)
		{
			popupsMutex.lock();
			for (int i = 0; i < POPUPS_COUNT; i++)
				if (!popups[i])
				{
					int x, y;
					while (true)
					{
						windowGenStart:
						x = (int)Window::GetWidth() / 6;
						x = rand() % (x * 2) - x;
						if (abs(x) < 40)
							x = 40 * sign(x);
						if (x < 0)
							x += Window::GetWidth() - 192;
						y = rand() % ((int)Window::GetHeight() - 80 - 128) + 40;
						for (int i = 0; i < POPUPS_COUNT; i++)
							if (popups[i])
								if (popups[i]->IsIn(x, y) || popups[i]->IsIn(x + 192, y) || popups[i]->IsIn(x, y + 128) || popups[i]->IsIn(x + 192, y + 128))
									goto windowGenStart;
						break;
					}
					auto p = new SpherePopup();
					try
					{
						p->SetVars(D3DXVECTOR2(x, y), parrtriangle[ind], ind);
					}
					catch (...)
					{
						delete p;
						popupsMutex.unlock();
						return;
					}
					p->Initialize();
					popups[i] = p;
					break;
				}
			popupsMutex.unlock();
			break;
		}
	}
}
示例#16
0
 static vector_type transform_vector(
     const matrix_type& m,
     const vector_type& v )
 {
     D3DXVECTOR4 t;
     D3DXVec3Transform( &t, &v, &m );
     return (D3DXVECTOR3&)t;
 }
示例#17
0
文件: camera.cpp 项目: aisi/Camera
void Camera::rotateFirstPerson(float headingDegrees, float pitchDegrees)
{
    m_accumPitchDegrees += pitchDegrees;

    if (m_accumPitchDegrees > 90.0f)
    {
        pitchDegrees = 90.0f - (m_accumPitchDegrees - pitchDegrees);
        m_accumPitchDegrees = 90.0f;
    }

    if (m_accumPitchDegrees < -90.0f)
    {
        pitchDegrees = -90.0f - (m_accumPitchDegrees - pitchDegrees);
        m_accumPitchDegrees = -90.0f;
    }

    float heading = D3DXToRadian(headingDegrees);
    float pitch = D3DXToRadian(pitchDegrees);
    
    D3DXMATRIX rotMtx;
    D3DXVECTOR4 result;

    // Rotate camera's existing x and z axes about the world y axis.
    if (heading != 0.0f)
    {
        D3DXMatrixRotationY(&rotMtx, heading);
        
        D3DXVec3Transform(&result, &m_xAxis, &rotMtx);
        m_xAxis = D3DXVECTOR3(result.x, result.y, result.z);

        D3DXVec3Transform(&result, &m_zAxis, &rotMtx);
        m_zAxis = D3DXVECTOR3(result.x, result.y, result.z);
    }

    // Rotate camera's existing y and z axes about its existing x axis.
    if (pitch != 0.0f)
    {
        D3DXMatrixRotationAxis(&rotMtx, &m_xAxis, pitch);
        
        D3DXVec3Transform(&result, &m_yAxis, &rotMtx);
        m_yAxis = D3DXVECTOR3(result.x, result.y, result.z);
        
        D3DXVec3Transform(&result, &m_zAxis, &rotMtx);
        m_zAxis = D3DXVECTOR3(result.x, result.y, result.z);
    }
}
示例#18
0
//-----------------------------------------------------------------------------
// Name: ApplyEnvironmentMap()
// Desc: Performs a calculation on each of the vertices' normals to determine
//       what the texture coordinates should be for the environment map (in this 
//       case the bump map).
//-----------------------------------------------------------------------------
VOID CMyD3DApplication::ApplyEnvironmentMap()
{
    EMBOSSVERTEX* pv;
    DWORD         dwNumVertices;
    dwNumVertices = m_pObject->GetLocalMesh()->GetNumVertices();

    LPDIRECT3DVERTEXBUFFER8 pVB;
    m_pObject->GetLocalMesh()->GetVertexBuffer( &pVB );
    pVB->Lock( 0, 0, (BYTE**)&pv, 0 );

    // Get the World matrix
    D3DXMATRIX  WV,InvWV;
    m_pd3dDevice->GetTransform( D3DTS_WORLD, &WV );
    D3DXMatrixInverse( &InvWV, NULL, &WV );
    
    // Get the current light position in object space
    D3DXVECTOR4 vTransformed;
    D3DXVec3Transform( &vTransformed, (D3DXVECTOR3*)&m_Light.Position, &InvWV );
    m_vBumpLightPos.x = vTransformed.x;
    m_vBumpLightPos.y = vTransformed.y;
    m_vBumpLightPos.z = vTransformed.z;

    // Dimensions of texture needed for shifting tex coords
    D3DSURFACE_DESC d3dsd;
    m_pEmbossTexture->GetLevelDesc( 0, &d3dsd );
    
    // Loop through the vertices, transforming each one and calculating
    // the correct texture coordinates.
    for( WORD i = 0; i < dwNumVertices; i++ )
    {
        // Find light vector in tangent space
        D3DXVECTOR3 vLightToVertex;
        D3DXVec3Normalize( &vLightToVertex, &(m_vBumpLightPos - pv[i].p) );
        
        // Create rotation matrix (rotate into tangent space)
        FLOAT r = D3DXVec3Dot( &vLightToVertex, &pv[i].n );

        if( r < 0.f ) 
        {
            // Don't shift coordinates when light below surface
            pv[i].tu2 = pv[i].tu;
            pv[i].tv2 = pv[i].tv;
        }
        else
        {
            // Shift coordinates for the emboss effect
            D3DXVECTOR2 vEmbossShift;
            vEmbossShift.x = D3DXVec3Dot( &vLightToVertex, &m_pTangents[i] );
            vEmbossShift.y = D3DXVec3Dot( &vLightToVertex, &m_pBinormals[i] );
            D3DXVec2Normalize( &vEmbossShift, &vEmbossShift );
            pv[i].tu2 = pv[i].tu + vEmbossShift.x/d3dsd.Width;
            pv[i].tv2 = pv[i].tv - vEmbossShift.y/d3dsd.Height;
        }
    }

    pVB->Unlock();
    pVB->Release();
}
bool SpaceMine::React()
{
	bool reactFlag = false;
	std::map<int, D3DXVECTOR3> targetList;

	for ( int i = 0; i < REAL_PLAYER_NUM; ++i )
	{
		Character* targetCharacter = GObjectTable->GetCharacter( i );
		if ( !targetCharacter )
			continue;

		// 범위 및 현재 거리 계산
		D3DXVECTOR4 tempMat;
		D3DXVECTOR3 minePosition = GetTransform()->GetPosition();	// ISS 좌표계 기준 좌표

		// 현재 위치
		D3DXVec3Transform( &tempMat, &minePosition, &m_Matrix );
		minePosition = D3DXVECTOR3( tempMat.x, tempMat.y, tempMat.z );

		// 일단 각 플레이어와의 거리 확인
		D3DXVECTOR3 relativeDirection = minePosition - targetCharacter->GetTransform()->GetPosition();
		float distance = D3DXVec3Length( &relativeDirection );
		
		if ( distance <= SPACE_MINE_RANGE )
		{
			// 범위 안이면 일단 추가
			targetList.insert( std::map<int, D3DXVECTOR3>::value_type( i, relativeDirection ) );

			// 만약 다른 팀원이면 발동!
			if ( m_Team != targetCharacter->GetTeam() )
				reactFlag = true;
		}
	}

	// 발동되었다!
	// 발동 조건은 상대방 팀에 한정이지만 발동 후 효과 적용은 전체
	if ( reactFlag )
	{
		printf_s( "react!!\n" );
		for ( std::map<int, D3DXVECTOR3>::const_iterator it = targetList.begin(); it != targetList.end(); ++it )
		{
			// 밀려나는 방향 및 세기 결정
			D3DXVECTOR3 force;
			D3DXVec3Normalize( &force, &it->second );
			force *= -SPACE_MINE_FORCE;

			// 적용 및 방송
			Character* targetCharacter = GObjectTable->GetCharacter( it->first );
			assert( targetCharacter );

			targetCharacter->Move( force );
			targetCharacter->GetClassComponent()->SetMovementControlCooldown( COOLDOWN_STUN );
			GObjectTable->GetActorManager()->BroadcastCharacterChange( it->first, ChangeType::KINETIC_STATE );
		}
	}

	return reactFlag;
}
示例#20
0
static void _updateVoicePos(IDirectSoundBuffer* voice, D3DXVECTOR3* pos,
	QALState::ListenerInfo* listener)
{
	// get source pos in listener space
	D3DXVECTOR4 lpos;
	D3DXVec3Transform(&lpos, pos, &listener->m_LTM);

	voice->SetPosition(lpos.x, lpos.y, lpos.z, DS3D_DEFERRED);
}
示例#21
0
D3DXVECTOR3 CCamera::GetPointTransform(float x, float y)
{
	m_matrixTransform._41 = -m_pos.x;
	m_matrixTransform._42 = m_pos.y;
	D3DXVECTOR3 posCurr(x,y,0);
	D3DXVECTOR4 posResult;
	D3DXVec3Transform(&posResult, &posCurr, &m_matrixTransform);
	return D3DXVECTOR3(posResult.x, posResult.y, posResult.z);
}
示例#22
0
void CCamera::Transform(Vector2* position)
{
	Vector4 outTransform;

	D3DXVec3Transform(&outTransform, &Vector3(position->x, position->y, 0.0f), &_transformMatrix);

	position->x = floor(outTransform.x);
	position->y = floor(outTransform.y);

}
示例#23
0
void CCamera::InTransform(Vector2* inPosition)
{
	Vector4 outInTransform;

	D3DXVec3Transform(&outInTransform, &Vector3(inPosition->x, inPosition->y, 0.0f), &_inTransformMatrix);

	inPosition->x = floor(outInTransform.x);
	inPosition->y = floor(outInTransform.y);

}
示例#24
0
D3DXVECTOR3 cprimitive::GetTranslationVector(D3DXMATRIX matRot)
{
	D3DXMATRIX matTrans;

	D3DXVECTOR4 vec4res;
	D3DXVECTOR3 vec3init = D3DXVECTOR3(0.f, fLength, 0.f);
	D3DXVec3Transform(&vec4res, &vec3init, &matRot); 
	//HTMLLog("%d > %d %d %d > %d\n", (int)fLength, (int)vec4res.x, (int)vec4res.y, (int)vec4res.z, (int)(sqrt(vec4res.x*vec4res.x + vec4res.y*vec4res.y + vec4res.z*vec4res.z))); 

	return D3DXVECTOR3(vec4res.x, vec4res.y, vec4res.z);
}
示例#25
0
void Camera::Transform(D3DXVECTOR2* position)
{
	D3DXVECTOR4 outTransform;

	// Transform theo ma trận tranform
	D3DXVec3Transform(&outTransform, &D3DXVECTOR3(position->x, position->y, 0), &_MatrixTransform);

	position->x = floor( outTransform.x);
	position->y =floor( outTransform.y);

}
示例#26
0
文件: Mesh.cpp 项目: Malow/NDYGFX
void Mesh::RotateVectorByMeshesRotation( Vector3& vec )
{
	D3DXMATRIX QuatMat;
	D3DXMatrixRotationQuaternion(&QuatMat, &this->rotQuat); 
	D3DXVECTOR4 o;
	D3DXVECTOR3 i = D3DXVECTOR3(vec.x, vec.y, vec.z);
	D3DXVec3Transform(&o, &i, &QuatMat);
	vec.x = o.x;
	vec.y = o.y;
	vec.z = o.z;
}
示例#27
0
void Camera::Resize()
{
    RECT rect = DXUTGetWindowClientRect();
    
    float fAspectRatio = (FLOAT)rect.right / (FLOAT)rect.bottom;

    D3DXVECTOR4 modelInView;
    D3DXVec3Transform(&modelInView, &m_vModelCenter, &m_mView);

    SetProjParams( D3DX_PI/4, fAspectRatio, max(0.1f, modelInView.z-(m_fMaxRadius*2)) , modelInView.z+(m_fMaxRadius*2) );
    SetWindow( rect.right, rect.bottom );
}
示例#28
0
D3DXVECTOR3 Camera::GetPointTransform(int x, int y)
{
	_MatrixTransform._41 = -_pos.x;
	_MatrixTransform._42 = _pos.y;

	D3DXVECTOR3 pos(x, y, 0);
	D3DXVECTOR4 v_result;

	D3DXVec3Transform(&v_result, &pos, &_MatrixTransform);

	return D3DXVECTOR3(v_result.x, v_result.y, 0);
}
示例#29
0
void PointLight::SetLight(X3DDrawContext* pDC)
{
//	m_radius->m_value;

	D3DXMATRIX modelView = pDC->m_renderContext->modelViewMatrix();

	D3DXVECTOR3 location(m_location->getValue());
	D3DXVECTOR4 v;

	D3DXVec3Transform(&v, &location, &modelView);

	float ambientIntensity = getAmbientIntensity();
	float intensity = getIntensity();
	Vec3f color = getColor();
	Vec3f attenuation = getAttenuation();

	Graphics::Light light;
	light.m_type = 2;
	light.m_ambient = Vec4f(ambientIntensity, ambientIntensity, ambientIntensity, 1.0f);
	light.m_diffuse = Vec4f(color[0]*intensity, color[1]*intensity, color[2]*intensity, 1.0f);
	light.m_position = Vec4f(v.x, v.y, v.z, 1/*positional*/);
	light.m_constant_attenuation = attenuation[0];
	light.m_linear_attenuation = attenuation[1];
	light.m_quadratic_attenuation = attenuation[2];

	pDC->m_renderContext->m_lights.push_back(light);

	++pDC->m_renderContext->m_nLight;

#if 0
	pDC->m_pGraphics3D->PushMatrix();
//	glTranslated(0, 0, 100);

	float light_position[4];
	m_location->getValue(light_position);
	light_position[3] = 1;	// positional
	float ambient[4] = {m_ambientIntensity->m_value, m_ambientIntensity->m_value, m_ambientIntensity->m_value, 1.0};
	float diffuse_specular[4] = {m_color->m_value[0], m_color->m_value[1], m_color->m_value[2], m_intensity->m_value};

	pDC->m_pGraphics3D->Enable(GL_LIGHT0+pDC->m_nLight);
	pDC->m_pGraphics3D->Lightfv(GL_LIGHT0+pDC->m_nLight, GL_POSITION, light_position);
	pDC->m_pGraphics3D->Lightfv(GL_LIGHT0+pDC->m_nLight, GL_AMBIENT, ambient);
	pDC->m_pGraphics3D->Lightfv(GL_LIGHT0+pDC->m_nLight, GL_DIFFUSE, diffuse_specular);
//	pDC->m_pGraphics3D->glLightfv(GL_LIGHT0+pDC->m_nLight, GL_SPECULAR , diffuse_specular);

	pDC->m_pGraphics3D->Lightf(GL_LIGHT0+pDC->m_nLight, GL_CONSTANT_ATTENUATION, m_attenuation->m_value[0]);
	pDC->m_pGraphics3D->Lightf(GL_LIGHT0+pDC->m_nLight, GL_LINEAR_ATTENUATION, m_attenuation->m_value[1]);
	pDC->m_pGraphics3D->Lightf(GL_LIGHT0+pDC->m_nLight, GL_QUADRATIC_ATTENUATION, m_attenuation->m_value[2]);

	pDC->m_pGraphics3D->PopMatrix();
#endif
}
示例#30
0
文件: math.c 项目: devyn/wine
/*************************************************************************
 * D3DXVec3TransformArray
 */
D3DXVECTOR4* WINAPI D3DXVec3TransformArray(
    D3DXVECTOR4* out, UINT outstride, CONST D3DXVECTOR3* in, UINT instride,
    CONST D3DXMATRIX* matrix, UINT elements)
{
    UINT i;
    TRACE("\n");
    for (i = 0; i < elements; ++i) {
        D3DXVec3Transform(
            (D3DXVECTOR4*)((char*)out + outstride * i),
            (CONST D3DXVECTOR3*)((const char*)in + instride * i),
            matrix);
    }
    return out;
}