Esempio n. 1
0
void ElCamera::calcViewOrientation()
{
	D3DXVec3Normalize(&mLook, &mLook);

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

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

	D3DXMATRIX rot;
	D3DXMatrixIdentity(&rot);

	rot._11 = mRight.x;
	rot._12 = mRight.y;
	rot._13 = mRight.z;

	rot._21 = mUp.x;
	rot._22 = mUp.y;
	rot._23 = mUp.z;

	rot._31 = mLook.x;
	rot._32 = mLook.y;
	rot._33 = mLook.z;

	D3DXQuaternionRotationMatrix(&mOrientation, &rot);

	// transform to parent space
	if (mParentNode)
	{
		D3DXQUATERNION parentOrientation = mParentNode->getDerivedOrientation();
		D3DXQuaternionInverse(&parentOrientation, &parentOrientation);
		mOrientation = parentOrientation * mOrientation;
	}
}
Esempio n. 2
0
void AnimationNode::set_transform(const D3DXMATRIX& transform)
{
  transform_ = transform;
  pos_ = get_translation(transform);
  D3DXQuaternionRotationMatrix(&rot_, &transform);
  scale_ = get_scale(transform);
}
Esempio n. 3
0
void	IObj::DirectionRotation( bool IsSmooth )
{
//	D3DXVec3Normalize( &m_vDirection, &m_vDirection );

	D3DXVECTOR3	vCoord;
	D3DXVECTOR3	vCross;
	
	D3DXMATRIXA16	matRotY;
	D3DXMatrixRotationY( &matRotY, -D3DX_PI * 0.5f );

	D3DXVec3TransformCoord( &vCoord, &m_vDirection, &matRotY );
	D3DXVec3Normalize( &vCoord, &vCoord );


	D3DXMatrixRotationX( &matRotY, D3DX_PI );

	D3DXVec3Cross( &vCross, &vCoord, &m_vDirection );
	D3DXVec3TransformCoord( &vCross, &vCross, &matRotY );
	D3DXVec3Normalize( &vCross, &vCross );

	memcpy( &m_matLookAt._11, &vCoord, sizeof( D3DXVECTOR3 ) );
	memcpy( &m_matLookAt._21, &vCross, sizeof( D3DXVECTOR3 ) );
	memcpy( &m_matLookAt._31, &m_vDirection, sizeof( D3DXVECTOR3 ) );
	memcpy( &m_matLookAt._41, &D3DXVECTOR3( 0.0f, 0.0f, 0.0f ), sizeof( D3DXVECTOR3 ) );

	D3DXQUATERNION q;
	D3DXQuaternionRotationMatrix( &q, &m_matLookAt );

	D3DXQuaternionSlerp( &m_quatLookAt, &m_quatLookAt, &q, 0.1f );
	
}
Esempio n. 4
0
int CMotionPoint::MakeWorldMat( D3DXMATRIX* wmat )
{
	m_worldmat = m_totalmat * *wmat;
	

	D3DXQUATERNION tmpxq;
	D3DXQuaternionRotationMatrix( &tmpxq, wmat );
	CQuaternion wq;
	wq.SetParams( tmpxq );
	m_worldq = wq * m_totalq;

	return 0;
}
/*****************************************************************
* D3DXMATRIX Interpolate(D3DXMATRIX _d3dPrevFrame, D3DXMATRIX _d3dNextFrame, float _fLambda): 
* Interpolates between two Matrices based on Lambda time
*
* Ins:			    D3DXMATRIX _d3dPrevFrame
*					D3DXMATRIX _d3dNextFrame
*					float _fLambda
*
* Outs:				void
*
* Returns:		    D3DXMATRIX
*
* Mod. Date:		02/20/2013
* Mod. Initials:	SD
*****************************************************************/
D3DXMATRIX Interpolate(D3DXMATRIX& d3dMatrixA, D3DXMATRIX& d3dMatrixB, float fLambda)
{
	D3DXQUATERNION quatA, quatB, tempQuat;
	D3DXQuaternionRotationMatrix(&quatA, &d3dMatrixA);
	D3DXQuaternionRotationMatrix(&quatB, &d3dMatrixB);

	tempQuat = quatA;
	D3DXQuaternionNormalize(&quatA, &tempQuat);
	tempQuat = quatB;
	D3DXQuaternionNormalize(&quatB, &tempQuat);
	D3DXQuaternionSlerp(&tempQuat, &quatA, &quatB, fLambda);
	D3DXMATRIX result;
	D3DXMatrixRotationQuaternion(&result, &tempQuat);
	D3DXVec3Lerp((D3DXVECTOR3*)&result[12], (D3DXVECTOR3*)&d3dMatrixA[12], (D3DXVECTOR3*)&d3dMatrixB[12], fLambda);
	D3DXVECTOR3 scaleA = D3DXVECTOR3(d3dMatrixA[0],d3dMatrixA[5],d3dMatrixA[10]);
	D3DXVECTOR3 scaleB = D3DXVECTOR3(d3dMatrixB[0],d3dMatrixB[5],d3dMatrixB[10]);
	D3DXVECTOR3 finalScale;
	D3DXVec3Lerp(&finalScale, &scaleA, &scaleB, fLambda);
	result[0] = finalScale[0];
	result[5] = finalScale[1];
	result[10] = finalScale[2];
	return result;
}
Esempio n. 6
0
OvTransform ExtractTransformFromMatrix( const OvMatrix& mat )
{
	OvTransform outPut;
	outPut.Position.x = mat._41;
	outPut.Position.y = mat._42;
	outPut.Position.z = mat._43;

	OvMatrix kExtractMat;
	D3DXQuaternionRotationMatrix((D3DXQUATERNION*)&outPut.Quaternion,(D3DXMATRIX*)&mat);
	kExtractMat = mat*OvMatrix().Rotate(outPut.Quaternion.Inverse());

	outPut.Scale.x = kExtractMat._11;
	outPut.Scale.y = kExtractMat._22;
	outPut.Scale.z = kExtractMat._33;
	return outPut;
}
Esempio n. 7
0
void quater::setRotation(const matrix4& m)
{
#ifdef USE_D3DFUNC
	D3DXMATRIX dxmat;
	m.toDXmat(dxmat);
	D3DXQuaternionRotationMatrix(*this,&dxmat);	
#else
	
	// jehee lee implementation
	quater &q=*this;

    double tr, s;
    int    i, j, k;
    static int next[3] = { 1, 2, 0 };

    tr = m.m[0][0] + m.m[1][1] + m.m[2][2];
    if ( tr > 0.0 )
    {
        s = sqrt( tr + 1.0 );
        q[0] = ( s * 0.5 );
        s = 0.5 / s;
        q.x = ( m.m[2][1] - m.m[1][2] ) * s;
        q.y = ( m.m[0][2] - m.m[2][0] ) * s;
        q.z = ( m.m[1][0] - m.m[0][1] ) * s;
    }
    else
    {
        i = 0;
        if ( m.m[1][1] > m.m[0][0] ) i = 1;
        if ( m.m[2][2] > m.m[i][i] ) i = 2;

        j = next[i];
        k = next[j];

        s = sqrt( (m.m[i][i]
					- (m.m[j][j] + m.m[k][k])) + 1.0 );
        q[i+1] = s * 0.5;
        s = 0.5 / s;
        q.w   = ( m.m[k][j] - m.m[j][k] ) * s;
        q[j+1] = ( m.m[j][i] + m.m[i][j] ) * s;
        q[k+1] = ( m.m[k][i] + m.m[i][k] ) * s;
    }


#endif
}
Esempio n. 8
0
//--------------------------------------------------------------------------------------
// Override for setting the view parameters
//--------------------------------------------------------------------------------------
void CModelViewerCamera::SetViewParams( D3DXVECTOR3* pvEyePt, D3DXVECTOR3* pvLookatPt )
{
    CBaseCamera::SetViewParams( pvEyePt, pvLookatPt );

    // Propogate changes to the member arcball
    D3DXQUATERNION quat;
    D3DXMATRIXA16 mRotation;
    D3DXVECTOR3 vUp(0,1,0);
    D3DXMatrixLookAtLH( &mRotation, pvEyePt, pvLookatPt, &vUp );
    D3DXQuaternionRotationMatrix( &quat, &mRotation );
    m_ViewArcBall.SetQuatNow( quat );

    // Set the radius according to the distance
    D3DXVECTOR3 vEyeToPoint;
    D3DXVec3Subtract( &vEyeToPoint, pvLookatPt, pvEyePt );
    SetRadius( D3DXVec3Length( &vEyeToPoint ) );
}
Esempio n. 9
0
File: math.c Progetto: devyn/wine
/*************************************************************************
 * D3DXMatrixDecompose
 */
HRESULT WINAPI D3DXMatrixDecompose(D3DXVECTOR3 *poutscale, D3DXQUATERNION *poutrotation, D3DXVECTOR3 *pouttranslation, D3DXMATRIX *pm)
{
    D3DXMATRIX normalized;
    D3DXVECTOR3 vec;

    /*Compute the scaling part.*/
    vec.x=pm->u.m[0][0];
    vec.y=pm->u.m[0][1];
    vec.z=pm->u.m[0][2];
    poutscale->x=D3DXVec3Length(&vec);

    vec.x=pm->u.m[1][0];
    vec.y=pm->u.m[1][1];
    vec.z=pm->u.m[1][2];
    poutscale->y=D3DXVec3Length(&vec);

    vec.x=pm->u.m[2][0];
    vec.y=pm->u.m[2][1];
    vec.z=pm->u.m[2][2];
    poutscale->z=D3DXVec3Length(&vec);

    /*Compute the translation part.*/
    pouttranslation->x=pm->u.m[3][0];
    pouttranslation->y=pm->u.m[3][1];
    pouttranslation->z=pm->u.m[3][2];

    /*Let's calculate the rotation now*/
    if ( (poutscale->x == 0.0f) || (poutscale->y == 0.0f) || (poutscale->z == 0.0f) )
    {
     return D3DERR_INVALIDCALL;
    }

    normalized.u.m[0][0]=pm->u.m[0][0]/poutscale->x;
    normalized.u.m[0][1]=pm->u.m[0][1]/poutscale->x;
    normalized.u.m[0][2]=pm->u.m[0][2]/poutscale->x;
    normalized.u.m[1][0]=pm->u.m[1][0]/poutscale->y;
    normalized.u.m[1][1]=pm->u.m[1][1]/poutscale->y;
    normalized.u.m[1][2]=pm->u.m[1][2]/poutscale->y;
    normalized.u.m[2][0]=pm->u.m[2][0]/poutscale->z;
    normalized.u.m[2][1]=pm->u.m[2][1]/poutscale->z;
    normalized.u.m[2][2]=pm->u.m[2][2]/poutscale->z;

    D3DXQuaternionRotationMatrix(poutrotation,&normalized);
    return S_OK;
}
Esempio n. 10
0
void Camera::Place( D3DXVECTOR3& eye)
{
    __super::Reset();

    D3DXVECTOR3 center = STATE_GET(Render)->GetModelCenter();
    float radius = STATE_GET(Render)->GetModelRadius();

    __super::SetViewParams( &eye, &center );
    __super::SetModelCenter( center );
    __super::SetRadius( radius*2.5f, 0.0f/*radius*/, radius*10.0f );

    D3DXQUATERNION quat;
    D3DXMATRIXA16 mIdentity;
    D3DXMatrixIdentity( &mIdentity );
    D3DXQuaternionRotationMatrix( &quat, &mIdentity );
    __super::SetWorldQuat( quat );
    __super::SetWorldMatrix( mIdentity );

    Resize();
}
Esempio n. 11
0
int CMotionPoint::CalcQandTra( D3DXMATRIX srcmat, CBone* boneptr )
{
	D3DXVECTOR3 aftpos;
	D3DXVec3TransformCoord( &aftpos, &boneptr->m_jointfpos, &srcmat );
	m_tra = aftpos - boneptr->m_jointfpos;


	D3DXMATRIX tmpmat = srcmat;
	tmpmat._41 = 0.0f;
	tmpmat._42 = 0.0f;
	tmpmat._43 = 0.0f;
	D3DXQUATERNION rotqx;
	D3DXQuaternionRotationMatrix( &rotqx, &tmpmat );
	m_q.x = rotqx.x;
	m_q.y = rotqx.y;
	m_q.z = rotqx.z;
	m_q.w = rotqx.w;

/***
	D3DXMATRIX beftra, afttra;
	D3DXMatrixIdentity( &beftra );
	D3DXMatrixTranslation( &beftra, -boneptr->m_jointfpos.x, -boneptr->m_jointfpos.y, -boneptr->m_jointfpos.z );
	D3DXMatrixIdentity( &afttra );
	D3DXMatrixTranslation( &afttra, -boneptr->m_jointfpos.x, -boneptr->m_jointfpos.y, -boneptr->m_jointfpos.z );

	D3DXMATRIX lbase;
	lbase = beftra * tmpmat * afttra;

	D3DXMATRIX invlbase;
	D3DXMatrixInverse( &invlbase, NULL, &lbase );

	D3DXVECTOR3 zeropos( 0.0f, 0.0f, 0.0f );
	D3DXMATRIX xmat;
	xmat = invlbase * srcmat;

	D3DXVec3TransformCoord( &m_tra, &zeropos, &xmat );
***/
	return 0;
}
Esempio n. 12
0
bool ActionBox::isPointInside(Vec3 *point)
{
	/*if(!(point->y < m_currentMax.y && point->y > m_currentMin.y))
		return false;*/

	/*point->y = 100.0f;
	Vec3 p0 = m_min;
	Vec3 p1 = m_max;
	Vec3 p2 = Vec3(m_max.x, 0, m_min.z);
	Vec3 p2_2 = Vec3(m_min.x, 0, m_max.z);

	D3DXVec3TransformCoord(&p0, &p0, &m_world);
	D3DXVec3TransformCoord(&p1, &p1, &m_world);
	D3DXVec3TransformCoord(&p2, &p2, &m_world);
	D3DXVec3TransformCoord(&p2_2, &p2_2, &m_world);

	return D3DXIntersectTri(&p0, &p1, &p2, point, &Vec3(0, -1, 0), 0, 0, 0) || D3DXIntersectTri(&p0, &p1, &p2_2, point, &Vec3(0, -1, 0), 0, 0, 0);*/
	Vec3 checkPoint = *point;
	checkPoint = (*point) - m_position;
	Mat temp;
	temp = m_world;
	D3DXQUATERNION quat;
	D3DXQuaternionRotationMatrix(&quat, &temp);
	D3DXQuaternionNormalize(&quat, &quat);
	D3DXQuaternionInverse(&quat, &quat);
	temp._41 = 0;
	temp._42 = 0;
	temp._43 = 0;
	
	D3DXMatrixRotationQuaternion(&temp, &quat);
	D3DXVec3TransformCoord(&checkPoint, &checkPoint, &temp);
	if(checkPoint.x > m_min.x && checkPoint.x < m_max.x &&
		//checkPoint.y > m_min.y && checkPoint.y < m_max.y &&
		checkPoint.z > m_min.z && checkPoint.z < m_max.z)
		return true;

	return false;
}
Esempio n. 13
0
int CMotionPoint::MakeDispMat()
{
	m_disptra.x = m_worldmat._41;
	m_disptra.y = m_worldmat._42;
	m_disptra.z = m_worldmat._43;

	D3DXMATRIX tmpwmat = m_worldmat;
	tmpwmat._41 = 0.0f;
	tmpwmat._42 = 0.0f;
	tmpwmat._43 = 0.0f;

	D3DXQUATERNION xtmpq;
	D3DXQuaternionRotationMatrix( &xtmpq, &tmpwmat );

	m_dispq.SetParams( xtmpq );
	m_orderdispq = m_dispq;

	m_dispmat = m_dispq.MakeRotMatX();
	m_dispmat._41 = m_disptra.x;
	m_dispmat._42 = m_disptra.y;
	m_dispmat._43 = m_disptra.z;

	return 0;
}
Esempio n. 14
0
void CCameraReplay::processFrame( float frame, SMatrix4x4& viewerMat, float& zoom, float& tilt, bool& follow )
{
	if( mMode == REC_NONE )
		return;

	frame *= RECORDS_PER_TURN;

	int iframe0 = (int)frame;
	int iframe1 = iframe0 + 1;
	float alpha = frame - iframe0;

	if( mMode == REC_READ )
	{
		if( iframe0 >= mData.size() ) iframe0 = mData.size()-1;
		if( iframe1 >= mData.size() ) iframe1 = mData.size()-1;

		SFrameData fd;
		fd.lerp( mData[iframe0], mData[iframe1], alpha );

		viewerMat = SMatrix4x4( fd.pos, fd.rot );
		zoom = fd.megaZoom;
		tilt = fd.megaTilt;
		follow = fd.followMode;
	}
	else
	{
		SFrameData fd;
		fd.pos = viewerMat.getOrigin();
		D3DXQuaternionRotationMatrix( &fd.rot, &viewerMat );
		fd.megaZoom = zoom;
		fd.megaTilt = tilt;
		fd.followMode = follow;

		writeFrameDataToFile( mFile, iframe0, fd );
	}
}
Esempio n. 15
0
bool GBoneObj::Load(ID3D11Device* pDevice,const TCHAR* szLoadName,const TCHAR* pLoadShaderFile,bool bThread)
{
	FILE	*fp;
	fp = _tfopen(szLoadName, _T("rb"));
	if (!fp) return false;

	char szBuffer[MAX_PATH] = { 0, };
	size_t convertedChars = 0;

	tm newtime;
	fread(&newtime, sizeof(tm), 1, fp);
	T_STR today = _tasctime(&newtime);	// The date string has a \n appended.
	today[today.size() - 1] = 0;
	fread(&m_Scene, sizeof(TScene), 1, fp);

	// 시작 프레임이 0일 아닐 경우가 있기 때문에 무조건 
	// 시작 프레임을 0으로 맞춘다.( 해당 프레임 만큼만 배열 할당 된다.)
	m_iStartFrame = 0;//m_Scene.iFirstFrame;
	m_iLastFrame = m_Scene.iLastFrame - m_Scene.iFirstFrame;
	m_fElapseTime = (float)m_iStartFrame;
	m_Scene.iFirstFrame = 0;
	m_Scene.iLastFrame = m_iLastFrame;

	SAFE_NEW_ARRAY_CLEAR(m_pMatrix, D3DXMATRIX, m_Scene.iNumMesh);
	SAFE_NEW_ARRAY_CLEAR(m_ppAniMatrix, LPD3DXMATRIX, m_Scene.iNumMesh);
	SAFE_NEW_ARRAY_CLEAR(m_ppAniQuater, LPD3DXQUATERNION, m_Scene.iNumMesh);
	SAFE_NEW_ARRAY_CLEAR(m_ppScaleVector, LPD3DXVECTOR3, m_Scene.iNumMesh);
	SAFE_NEW_ARRAY_CLEAR(m_ppTransVector, LPD3DXVECTOR3, m_Scene.iNumMesh);

	int iNumFrame = m_iLastFrame - m_iStartFrame;
	for (int i = 0; i < m_Scene.iNumMesh; i++)
	{
		SAFE_NEW_ARRAY(m_ppAniMatrix[i], D3DXMATRIX, iNumFrame);
		SAFE_NEW_ARRAY(m_ppAniQuater[i], D3DXQUATERNION, iNumFrame);
		SAFE_NEW_ARRAY(m_ppScaleVector[i], D3DXVECTOR3, iNumFrame);
		SAFE_NEW_ARRAY(m_ppTransVector[i], D3DXVECTOR3, iNumFrame);
	}

	D3DXQUATERNION qRotate;
	D3DXVECTOR3 vScale, vTrans;
	D3DXMATRIX matFrameWorld;

	for (int ibip = 0; ibip < m_Scene.iNumMesh; ibip++)
	{
		for (int iFrame = 0; iFrame < iNumFrame; iFrame++)
		{
			fread(&m_ppAniMatrix[ibip][iFrame], sizeof(D3DXMATRIX), 1, fp);
		}
	}

	for (int ibip = 0; ibip < m_Scene.iNumMesh; ibip++)
	{
		shared_ptr<tMatMesh> pData = make_shared<tMatMesh>();
		shared_ptr<GMesh> pMesh = make_shared<GMesh>();
		int iCount;

		TCHAR szBuffer[256] = { 0, };
		TCHAR szName[256] = { 0, };
		fread(&pMesh->m_ClassType, sizeof(int), 1, fp);
		fread(&iCount, sizeof(int), 1, fp);
		fread(szName, sizeof(TCHAR) * iCount, 1, fp);

		pMesh->m_strNodeName = szName;
		fread(&pMesh->m_matWorld, sizeof(D3DXMATRIX), 1, fp);
		D3DXMatrixInverse(&pData->m_matInverse, 0, &pMesh->m_matWorld);

		fread(&iCount, sizeof(int), 1, fp);
		// 메쉬 버텍스 리스트
		if (iCount == 2)
		{
			pData->m_VertexArray.resize(36);
			m_iMaxVertex += 36;
		}
		else
		{
			pData->m_VertexArray.resize(iCount);
			m_iMaxVertex += iCount;
		}

		for (int iVertex = 0; iVertex < iCount; iVertex++)
		{
			fread(&pData->m_VertexArray[iVertex], sizeof(PNC_VERTEX), 1, fp);
			if (m_Scene.iBindPose)
			{
				D3DXVec3TransformCoord(&pData->m_VertexArray[iVertex].p,
					&pData->m_VertexArray[iVertex].p,
					&pData->m_matInverse);
			}
		}

		// 본과 더미 오브젝트( 최대 및 최소값 2개 출력되어 있음 )
		if (iCount == 2)
		{
			D3DXVECTOR3 Quad[8];
			D3DXVECTOR3 vMax = pData->m_VertexArray[0].p;
			D3DXVECTOR3 vMin = pData->m_VertexArray[1].p;

			Quad[0] = D3DXVECTOR3(vMin.x, vMin.y, vMin.z);
			Quad[1] = D3DXVECTOR3(vMin.x, vMax.y, vMin.z);
			Quad[2] = D3DXVECTOR3(vMax.x, vMax.y, vMin.z);
			Quad[3] = D3DXVECTOR3(vMax.x, vMin.y, vMin.z);

			Quad[4] = D3DXVECTOR3(vMin.x, vMin.y, vMax.z);
			Quad[5] = D3DXVECTOR3(vMin.x, vMax.y, vMax.z);
			Quad[6] = D3DXVECTOR3(vMax.x, vMax.y, vMax.z);
			Quad[7] = D3DXVECTOR3(vMax.x, vMin.y, vMax.z);
			SetBoundBox(Quad, pData.get());
		}
		pMesh->m_iNumFace = pData->m_VertexArray.size() / 3;
		m_pMesh.push_back(pMesh);
		m_pData.push_back(pData);
	}

	for (int ibip = 0; ibip < m_Scene.iNumMesh; ibip++)
	{
		for (int jFrame = 0; jFrame < m_iLastFrame - m_iStartFrame; jFrame++)
		{
			if (m_Scene.iBindPose)
			{
				//m_ppAniMatrix[ibip][jFrame] = m_pData[ibip]->m_matWorld * m_ppAniMatrix[ibip][jFrame];
			}
			if (SUCCEEDED(D3DXMatrixDecompose(&vScale, &qRotate, &vTrans, &m_ppAniMatrix[ibip][jFrame])))
			{
				m_ppAniQuater[ibip][jFrame] = qRotate;
				m_ppScaleVector[ibip][jFrame] = vScale;
				m_ppTransVector[ibip][jFrame] = vTrans;
			}
			else
			{
				D3DXQuaternionRotationMatrix(&m_ppAniQuater[ibip][jFrame], &m_ppAniMatrix[ibip][jFrame]);
			}
		}
	}

	fclose(fp);

	m_dxobj.m_iNumVertex = m_iMaxVertex;
	m_dxobj.m_iNumIndex = m_iMaxIndex;
	m_dxobj.m_iVertexSize = sizeof(PNC_VERTEX);

	if (!bThread && !Create(pDevice, pLoadShaderFile))
	{
		return false;
	}
	return true;
}
Esempio n. 16
0
	/*!
	*@brief	行列からクォータニオンを作成。
	*/
	void CQuaternion::SetRotation(const CMatrix& m)
	{
		D3DXQuaternionRotationMatrix((D3DXQUATERNION*)this, (D3DXMATRIX*)&m);
	}
void Quaternion::Build(const Mat4x4& mat)
{
	D3DXQuaternionRotationMatrix(this, &mat);
}
Esempio n. 18
0
void		GGbsModel::MultiAniFrame(){

	D3DXMATRIX matWldTrans;
	D3DXMATRIX matWldRotate;
	D3DXMATRIX matWldScale;
	D3DXMatrixIdentity(&matWldTrans);
	D3DXMatrixIdentity(&matWldRotate);
	D3DXMatrixIdentity(&matWldScale);
	

	D3DXQUATERNION qR, qS;

	D3DXMATRIX matCalc;
	D3DXMatrixIdentity(&matCalc);


	//m_fTickFrame = 6400.0f;
	m_fTickFrame += g_fSecPerFrame * m_fFrameSpeed *m_fTickPerFrame;
	if (m_fTickFrame >= m_fLastFrame * m_fTickPerFrame /*마지막 프레임 틱수*/)
	{
		m_fTickFrame = 0.0f;
	}

	//m_fTickFrame += 1000.0f;
	//if (m_fTickFrame >= 8000.0f /*마지막 프레임 틱수*/)
	//{
	//	m_fTickFrame = 0.0f;
	//}

	for (int i = 0; i < m_vGeomObj.size() ; i++) {

		if (m_vGeomObj[i]->m_bUsed == false)
			continue;

		D3DXMatrixIdentity(&m_vGeomObj[i]->m_matCalculation);

		matWldRotate = m_vGeomObj[i]->m_matWldRotate;
		matWldTrans = m_vGeomObj[i]->m_matWldTrans;
		matWldScale = m_vGeomObj[i]->m_matWldScale;

		D3DXQuaternionRotationMatrix(&qR, &matWldRotate);
		D3DXQuaternionRotationMatrix(&qS, &matWldScale);
		//for (int j = 0; j < m_vGeomObj[i]->m_vObj.size(); j++) {

			//if (m_vGeomObj[i].get()->m_bHasAniTrack) {






		//Translation
		if (m_vGeomObj[i].get()->m_vPosTrack.size() != 0) {

			GAnimTrack* pStartTrack = NULL;
			GAnimTrack* pEndTrack = NULL;

			//현재 Tick이 어디인지 찾자.
			GetAnimationTrack(m_fTickFrame, &pStartTrack, &pEndTrack, ANITRACK_TYPE_POS, i);

			//애니메이션 보간.
			D3DXVECTOR3 vResultVector;
			D3DXVECTOR3 vP1 = pStartTrack->vecVector;
			D3DXVECTOR3 vP2 = pEndTrack->vecVector;

			float fTValue = (m_fTickFrame - pStartTrack->iTick) / (pEndTrack->iTick - pStartTrack->iTick);

			if(pStartTrack != pEndTrack){
				D3DXVec3Lerp(&vResultVector, &vP1, &vP2, fTValue);

				//T행렬 값 대입
				matWldTrans._41 = vResultVector.x;
				matWldTrans._42 = vResultVector.y;
				matWldTrans._43 = vResultVector.z;
			}
			else {
				//T행렬 값 대입
				matWldTrans._41 = pStartTrack->vecVector.x;
				matWldTrans._42 = pStartTrack->vecVector.y;
				matWldTrans._43 = pStartTrack->vecVector.z;
			}
		}

		//Rotation
		if (m_vGeomObj[i].get()->m_vRotTrack.size() != 0) {
			GAnimTrack* pStartTrack = NULL;
			GAnimTrack* pEndTrack = NULL;
			//D3DXQUATERNION qR;

			//현재 Tick이 어디인지 찾자.
			GetAnimationTrack(m_fTickFrame, &pStartTrack, &pEndTrack, ANITRACK_TYPE_ROT, i);


			//사원수간의 보간..
			if (pStartTrack == NULL && pEndTrack == NULL) {
				qR = m_vGeomObj[i].get()->m_vRotTrack[0]->qRotate;// = m_vGeomObj[i].get()->m_qRotation;
			}
			else if (pStartTrack == NULL) {
				qR;// = m_vGeomObj[i].get()->m_qRotation;
				float fTValue = (m_fTickFrame - 0) / (pEndTrack->iTick - 0);
				D3DXQuaternionSlerp(&qR, &qR, &pEndTrack->qRotate, fTValue);
			}
			else if (pEndTrack == NULL) {
				qR = m_vGeomObj[i].get()->m_vRotTrack[m_vGeomObj[i].get()->m_vRotTrack.size() - 1].get()->qRotate;
				float fTValue = ((m_fTickFrame - pStartTrack->iTick) / (m_fFrameSpeed*m_fTickPerFrame));
				D3DXQuaternionSlerp(&qR, &qR, &qR, fTValue);
			}
			else {
				qR = pStartTrack->qRotate;
				float fTValue = (m_fTickFrame - pStartTrack->iTick) / (pEndTrack->iTick - pStartTrack->iTick);
				D3DXQuaternionSlerp(&qR, &qR, &pEndTrack->qRotate, fTValue);
			}

			//사원수에서 행렬로 변환.
			D3DXMatrixRotationQuaternion(&matWldRotate, &qR);// 사원수에서 행렬로 변환
		}

		//Scale
		if (m_vGeomObj[i].get()->m_vSclTrack.size() != 0) {

			GAnimTrack* pStartTrack = NULL;
			GAnimTrack* pEndTrack = NULL;

			D3DXMATRIX matScaleRot, matInvScaleRot;
			D3DXMatrixIdentity(&matScaleRot);
			D3DXMatrixIdentity(&matInvScaleRot);

			//D3DXQUATERNION qS;
			float fStartTick = 0.0f, fEndTick = 0.0f;
			D3DXVECTOR3 vScale(m_vGeomObj[i].get()->m_matWldScale._11, m_vGeomObj[i].get()->m_matWldScale._22, m_vGeomObj[i].get()->m_matWldScale._33);

			//현재 Tick이 어디인지 찾자.
			GetAnimationTrack(m_fTickFrame, &pStartTrack, &pEndTrack, ANITRACK_TYPE_SCL, i);

			//신축트랙 보간
			if (pStartTrack == NULL) {
				//vScale = m_vGeomObj[i].get()->m_vecTM_SCALE;

				//D3DXQuaternionRotationAxis(&qS, &m_vGeomObj[i].get()->m_vecTM_SCALE_AXIS, m_vGeomObj[i].get()->m_fTM_SCALEAXISANG);

				fStartTick = 0.0f;
				fEndTick = pEndTrack->iTick;
			}
			else if (pEndTrack == NULL) {
				vScale = pStartTrack->vecVector;
				qS = pStartTrack->qRotate;

				fStartTick = pStartTrack->iTick;

				fEndTick = pStartTrack->iTick + (m_fFrameSpeed*m_fTickPerFrame);
			}
			else {
				vScale = pStartTrack->vecVector;
				qS = pStartTrack->qRotate;

				fStartTick = pStartTrack->iTick;
				fEndTick = pEndTrack->iTick;


			}
			float fTValue = (m_fTickFrame - fStartTick) / (fEndTick - fStartTick);

			D3DXVec3Lerp(&vScale, &vScale, &pEndTrack->vecVector, fTValue);
			D3DXQuaternionSlerp(&qS, &qS, &pEndTrack->qRotate, fTValue);

			//사원수 -> 행렬로 변환등...
			D3DXMatrixScaling(&matWldScale, vScale.x, vScale.y, vScale.z);
			D3DXMatrixRotationQuaternion(&matScaleRot, &qS);
			D3DXMatrixInverse(&matInvScaleRot, NULL, &matScaleRot);

			matWldScale = matInvScaleRot * matWldScale * matScaleRot;



		}

		if (m_vGeomObj[i].get()->m_pParentObj != NULL) {

			m_vGeomObj[i].get()->m_matCalculation  = matCalc = matWldScale * matWldRotate * matWldTrans
				* m_vGeomObj[i].get()->m_pParentObj->m_matCalculation;
			int iTest = 0;

			// 인버스 매트릭스 확인 코드.
			D3DXVECTOR3 v0, v1, v2, v3;
			v0 = m_vGeomObj[i].get()->m_matCalculation.m[0];
			v1 = m_vGeomObj[i].get()->m_matCalculation.m[1];
			v2 = m_vGeomObj[i].get()->m_matCalculation.m[2];
			D3DXVec3Cross(&v3, &v1, &v2);
			if (D3DXVec3Dot(&v3, &v0) < 0.0f)
			{
				D3DXMATRIX matW;
				D3DXMatrixScaling(&matW, -1.0f, -1.0f, -1.0f);
				D3DXMatrixMultiply(&m_vGeomObj[i].get()->m_matCalculation,
					&m_vGeomObj[i].get()->m_matCalculation, &matW);
			}
		}
		else {
			m_vGeomObj[i].get()->m_matCalculation = matCalc = matWldScale * matWldRotate * matWldTrans;
			int iTest = 0;

			// 인버스 매트릭스 확인 코드.
			D3DXVECTOR3 v0, v1, v2, v3;
			v0 = m_vGeomObj[i].get()->m_matCalculation.m[0];
			v1 = m_vGeomObj[i].get()->m_matCalculation.m[1];
			v2 = m_vGeomObj[i].get()->m_matCalculation.m[2];
			D3DXVec3Cross(&v3, &v1, &v2);
			if (D3DXVec3Dot(&v3, &v0) < 0.0f)
			{
				D3DXMATRIX matW;
				D3DXMatrixScaling(&matW, -1.0f, -1.0f, -1.0f);
				D3DXMatrixMultiply(&m_vGeomObj[i].get()->m_matCalculation,
					&m_vGeomObj[i].get()->m_matCalculation, &matW);
			}
		}
	}
			//}
			
		//}

		//최종행렬.


	
}
inline void __Quaternion::operator = (const D3DXMATRIX& mtx)
{
	D3DXQuaternionRotationMatrix(this, &mtx);
}
Esempio n. 20
0
void CKrakenLeg::SwingAttack(float fElapsed)
{
	float Distance = 0;
	D3DXVECTOR3 CharPos = m_pInplay->GetCharacter()->GetPosition();
	Distance = D3DXVec3Length( &D3DXVECTOR3(CharPos - m_vPos) );

	if(Distance < 2.0)
	{
		D3DXMATRIX Rot;
		D3DXQUATERNION QuaRot;
		D3DXQUATERNION QuaStart;
		D3DXQUATERNION QuaSlerp;

		D3DXVECTOR3 ZVector(0,0,1);
		m_vDirection = m_pInplay->GetCharacter()->GetPosition()- m_vPos;

		D3DXMatrixIdentity(&Rot);

		

		Rot._11 = m_pInplay->GetCamera()->GetViewMatrix()->_11;
		Rot._13 = m_pInplay->GetCamera()->GetViewMatrix()->_13;
		Rot._31 = m_pInplay->GetCamera()->GetViewMatrix()->_31;
		Rot._33 = m_pInplay->GetCamera()->GetViewMatrix()->_33;

		Rot._41 = m_vPos.x;
		Rot._42 = m_vPos.y;
		Rot._43 = m_vPos.z;


		D3DXMatrixInverse( &Rot, NULL, &Rot );
		D3DXQuaternionRotationMatrix( &QuaStart, &m_matRotate);
		D3DXQuaternionRotationMatrix( &QuaRot, &Rot);

		if( D3DXVec3Dot(&ZVector,&m_vDirection) < 0)
		{
			D3DXQuaternionSlerp(&QuaSlerp, &QuaRot, &QuaStart, fElapsed);
		}
		else
		{
			D3DXQuaternionSlerp(&QuaSlerp, &QuaStart, &QuaRot, fElapsed);
		}
		
		D3DXMatrixRotationQuaternion(&Rot,&QuaSlerp);
		m_matRotate =  Rot;
		m_fAttackTimer += fElapsed;

		
		
		if( m_fAttackTimer >4.0f )
		{
			ChangeAnimation(1);
			
		}

		if( m_fAttackTimer > 5.63f)
		{
			m_fAnimationTime = 0;
			m_pInplay->GetCharacter()->AddHp( -200 ) ;
			ChangeAnimation(2);
			m_fAttackTimer = 0;
		}
	}
	else
	{
		ChangeAnimation(2);
	}
}
inline __Quaternion::__Quaternion(const D3DXMATRIX& mtx)
{
	D3DXQuaternionRotationMatrix(this, &mtx);
}
Esempio n. 22
0
void _X3PCamera::Advance( void )
{
	BOOL changedcamerastatus = FALSE;

	FLOAT abscamvel_x = fabs(m_CameraVelocity.x);
	FLOAT abscamvel_y = fabs(m_CameraVelocity.y);
	FLOAT abscamvel_z = fabs(m_CameraVelocity.z);
	FLOAT abscamvel_dist = fabs(m_ZoominoutVelocity);

	if( abscamvel_x > EPSILON3 || abscamvel_y > EPSILON3 || abscamvel_z > EPSILON3 || abscamvel_dist > EPSILON3 )
	{
		if( abscamvel_x > EPSILON3 )
		{
			m_CameraVelocity.x *= _XDEF_CAMERADECREASERATE;
			
			// add yaw
			mp_fYaw += m_CameraVelocity.x;
			if( mp_fYaw > 360.0f ) mp_fYaw = (FLOAT)fmod(mp_fYaw, 360.0);
		}

		if( abscamvel_y > EPSILON3 )
		{
			m_CameraVelocity.y *= _XDEF_CAMERADECREASERATE;
			
			//add pitch
			mp_fPitch += m_CameraVelocity.y;			
			if(mp_fPitch < mp_fMinPitchLimit) mp_fPitch = mp_fMinPitchLimit;
			else if(mp_fPitch > mp_fMaxPitchLimit) mp_fPitch = mp_fMaxPitchLimit;
		}

		if( abscamvel_z > EPSILON3 )
		{
			m_CameraVelocity.z *= _XDEF_CAMERADECREASERATE;
			
			//add roll
			mp_fRoll += m_CameraVelocity.z;			
			if(mp_fRoll < mp_fMinRollLimit) mp_fRoll = mp_fMinRollLimit;
			else if(mp_fRoll > mp_fMaxRollLimit) mp_fRoll = mp_fMaxRollLimit;
		}

		if( abscamvel_dist > EPSILON3 )
		{

#ifdef _XDWDEBUG
			extern BOOL g_MouseLockFlag;
			if( !g_MouseLockFlag )
			{
#endif
			if( m_MinDistance + m_AdditionalHeightMinDistance < m_TargetDistance )
			{
				m_ZoominoutVelocity *= _XDEF_CAMERAZOOMDECREASERATE;
			}
			else
			{
				m_ZoominoutVelocity *= 0.3f;
			}
			
			m_TargetDistance += m_ZoominoutVelocity;
			if( m_MinDistance > m_TargetDistance )
			{
				m_TargetDistance = m_MinDistance; 
			}
			else if( m_MaxDistance < m_TargetDistance )
			{
				m_TargetDistance = m_MaxDistance;
			}
#ifdef _XDWDEBUG
			}
#endif			
		}

		changedcamerastatus = TRUE;
	}
	
	if( m_QuaterViewChanging )
	{
		D3DXQUATERNION	nextrotquat;
		D3DXQUATERNION	orgrotquat;
		D3DXQUATERNION	targetrotquat;
		
		D3DXQuaternionRotationYawPitchRoll( &orgrotquat, _X_RAD(mp_fYaw), _X_RAD(mp_fPitch), _X_RAD(mp_fRoll) );

		if( m_DefaultViewChanging )
		{
			D3DXQuaternionRotationYawPitchRoll( &targetrotquat, _X_RAD(-45.0f), _X_RAD(30.0f), 0.0f );
		}
		else
		{
			D3DXQuaternionRotationYawPitchRoll( &targetrotquat, _X_RAD(180.0f), _X_RAD(30.0f), 0.0f );
		}
		
		FLOAT fElapsedTime = g_fElapsedFrameMilisecondTime*3.0f;
		if( fElapsedTime > 1.0f ) fElapsedTime = 1.0f;
		D3DXQuaternionSlerp( &nextrotquat, &orgrotquat, &targetrotquat, fElapsedTime );
		
		FLOAT fyaw, fpitch, froll;
		_XMeshMath_QuaternionToEulerAngle( nextrotquat, fyaw, fpitch, froll );
		
		fyaw = _X_DEG(fyaw);
		if( fyaw > 360.0f ) fyaw = (FLOAT)fmod(fyaw, 360.0);	
		
		fpitch	= _X_DEG(fpitch); 
		if(fpitch < mp_fMinPitchLimit) fpitch = mp_fMinPitchLimit; 
		else if(fpitch > mp_fMaxPitchLimit) fpitch = mp_fMaxPitchLimit;
		
		froll	= _X_DEG(froll);
		if(froll < mp_fMinRollLimit) froll = mp_fMinRollLimit;
		else if(froll > mp_fMaxRollLimit) froll = mp_fMaxRollLimit;
		
		if( fabs( mp_fYaw   - fyaw   ) > EPSILON1 ||
			fabs( mp_fPitch - fpitch ) > EPSILON1 ||
			fabs( mp_fRoll  - froll  ) > EPSILON1 )
		{
			mp_fYaw   = fyaw;
			mp_fPitch = fpitch;
			mp_fRoll  = froll;			
			changedcamerastatus = TRUE;
		}
		else
		{
			m_QuaterViewChanging = FALSE;
			m_QuaterViewMode = TRUE;

			m_DefaultViewChanging = FALSE;			
		}

		_XWindow_WorldMinimap* pminimapwindow = (_XWindow_WorldMinimap*)g_MainWindowManager.FindWindow( _XDEF_WTITLE_MINIMAPWINDOW );
		if( pminimapwindow )
		{
			// Set direction to minimap arrow 
			pminimapwindow->SetRotateFrustum( _X_RAD( 180 - mp_fYaw ) );
		}
	}
	else if( m_DefaultViewChanging )
	{
		D3DXQUATERNION	nextrotquat;
		D3DXQUATERNION	orgrotquat;
		D3DXQUATERNION	targetrotquat;
		
		D3DXQuaternionRotationYawPitchRoll( &orgrotquat, _X_RAD(mp_fYaw), _X_RAD(mp_fPitch), _X_RAD(mp_fRoll) );
		D3DXQuaternionRotationYawPitchRoll( &targetrotquat, _X_RAD(180.0f), _X_RAD(mp_fPitch), 0.0f );
		
		FLOAT fElapsedTime = g_fElapsedFrameMilisecondTime*3.0f;
		if( fElapsedTime > 1.0f ) fElapsedTime = 1.0f;
		D3DXQuaternionSlerp( &nextrotquat, &orgrotquat, &targetrotquat, fElapsedTime );
		
		FLOAT fyaw, fpitch, froll;
		_XMeshMath_QuaternionToEulerAngle( nextrotquat, fyaw, fpitch, froll );
		
		fyaw = _X_DEG(fyaw);
		if( fyaw > 360.0f ) fyaw = (FLOAT)fmod(fyaw, 360.0);	
		
		fpitch	= _X_DEG(fpitch); 
		if(fpitch < mp_fMinPitchLimit) fpitch = mp_fMinPitchLimit; 
		else if(fpitch > mp_fMaxPitchLimit) fpitch = mp_fMaxPitchLimit;
		
		froll	= _X_DEG(froll);
		if(froll < mp_fMinRollLimit) froll = mp_fMinRollLimit;
		else if(froll > mp_fMaxRollLimit) froll = mp_fMaxRollLimit;
		
		if( fabs( mp_fYaw   - fyaw   ) > EPSILON1 ||
			fabs( mp_fPitch - fpitch ) > EPSILON1 ||
			fabs( mp_fRoll  - froll  ) > EPSILON1 )
		{
			mp_fYaw   = fyaw;
			mp_fPitch = fpitch;
			mp_fRoll  = froll;			
			changedcamerastatus = TRUE;
		}
		else
		{
			m_DefaultViewChanging = FALSE;
		}

		_XWindow_WorldMinimap* pminimapwindow = (_XWindow_WorldMinimap*)g_MainWindowManager.FindWindow( _XDEF_WTITLE_MINIMAPWINDOW );
		if( pminimapwindow )
		{
			// Set direction to minimap arrow 
			pminimapwindow->SetRotateFrustum( _X_RAD( 180 - mp_fYaw ) );
		}
	}
	else
	{
		if( !gpInput->GetMouseState()->bButton[1] && 
			( g_pLocalUser->GetMotionClass() == _XACTION_MOVE && 
			  ( g_pLocalUser->m_PathNodeCount >= 1 || g_pLocalUser->m_LeftFinalTargetLength > 64.0f ) ) &&
			  (fabs( g_pLocalUser->m_RotateAngle - g_pLocalUser->m_LastRotateAngle ) < EPSILON3) && m_AutoBackTrace )
		{
			D3DXQUATERNION	nextrotquat;	
			D3DXQUATERNION	orgrotquat;
			D3DXQUATERNION	targetrotquat;
					
			D3DXMATRIX  mtxRotate = g_pLocalUser->m_ModelDescriptor.m_Position;		
			mtxRotate._41 = mtxRotate._42 = mtxRotate._43 = 0.0f;
			
			D3DXQuaternionRotationYawPitchRoll( &orgrotquat, 0.0f, _X_RAD(mp_fPitch), 0.0f );

			D3DXQuaternionRotationMatrix( &targetrotquat, &mtxRotate );
			D3DXQuaternionMultiply( &targetrotquat, &orgrotquat, &targetrotquat );

			D3DXQuaternionRotationYawPitchRoll( &orgrotquat, _X_RAD(mp_fYaw), _X_RAD(mp_fPitch), _X_RAD(mp_fRoll) );

			FLOAT fElapsedTime = g_fElapsedFrameMilisecondTime;
			if( fElapsedTime > 1.0f ) fElapsedTime = 1.0f;
			D3DXQuaternionSlerp( &nextrotquat, &orgrotquat, &targetrotquat, fElapsedTime );

			FLOAT fyaw, fpitch, froll;
			_XMeshMath_QuaternionToEulerAngle( nextrotquat, fyaw, fpitch, froll );

			fyaw = _X_DEG(fyaw);
			if( fyaw > 360.0f ) fyaw = (FLOAT)fmod(fyaw, 360.0);	
			
			fpitch	= _X_DEG(fpitch); 
			if(fpitch < mp_fMinPitchLimit) fpitch = mp_fMinPitchLimit; 
			else if(fpitch > mp_fMaxPitchLimit) fpitch = mp_fMaxPitchLimit;
				
			froll	= _X_DEG(froll);
			if(froll < mp_fMinRollLimit) froll = mp_fMinRollLimit;
			else if(froll > mp_fMaxRollLimit) froll = mp_fMaxRollLimit;

			if( fabs( mp_fYaw   - fyaw   ) > EPSILON3 ||
				fabs( mp_fPitch - fpitch ) > EPSILON3 ||
				fabs( mp_fRoll  - froll  ) > EPSILON3 )
			{
				mp_fYaw   = fyaw;
				mp_fPitch = fpitch;
				mp_fRoll  = froll;			
				changedcamerastatus = TRUE;
			}
		}
	}

	if( m_CameraShakeMode )
	{
		if( !m_CameraShakeDelayMode )
		{
			const FLOAT shakeadditionalfactor = 10.0f;
			FLOAT fshakefactor = _XLinearGraph( 0.1f,0.05f,  0.5f,0.0f ).GetValueAt( g_fElapsedFrameMilisecondTime );
			m_CameraShakeFactor.x = fshakefactor * sinf(rand());
			m_CameraShakeFactor.y = fshakefactor * sinf(rand());
			m_CameraShakeFactor.z = fshakefactor * sinf(rand());
			
			D3DXMATRIX matOrientation;
			D3DXMatrixInverse( &matOrientation, NULL, &mp_view_matrix );
			D3DXVec3TransformNormal( &m_CameraShakeFactor, &m_CameraShakeFactor, &matOrientation );
			
			changedcamerastatus = TRUE;
			
			m_fCameraShakeTimer -= g_fElapsedFrameMilisecondTime;
			if( m_fCameraShakeTimer < 0.0f )
			{
				m_CameraShakeMode = FALSE; 
				m_CameraShakeFactor = D3DXVECTOR3( 0.0f,0.0f,0.0f );
			}
			
		}
		else
		{
			if( g_LocalSystemTime - m_fCameraShakeStartTimer < m_fCameraShakeTimer*1000 )
			{
				
				int temp = (int)(((g_LocalSystemTime - m_fCameraShakeStartTimer)/1000.0f)/5.0f)%2;
				if( temp == 0 )
				{					
					if( !m_ChangeCameraShakeAtDelayMode )
					{
						_XPlaySoundEffect(ID_SR_INTERFACE_EARTHQUAKE_WAV, g_pLocalUser->m_Position );
					}
					const FLOAT shakeadditionalfactor = 10.0f;
					FLOAT fshakefactor = _XLinearGraph( 0.05f,0.025f,  0.25f,0.0f ).GetValueAt( g_fElapsedFrameMilisecondTime );
					m_CameraShakeFactor.x = fshakefactor * sinf(rand());
					m_CameraShakeFactor.y = fshakefactor * sinf(rand());
					m_CameraShakeFactor.z = fshakefactor * sinf(rand());
					
					D3DXMATRIX matOrientation;
					D3DXMatrixInverse( &matOrientation, NULL, &mp_view_matrix );
					D3DXVec3TransformNormal( &m_CameraShakeFactor, &m_CameraShakeFactor, &matOrientation );
					
					changedcamerastatus = TRUE;
					m_ChangeCameraShakeAtDelayMode = TRUE;
				}
				else
				{
					if( m_ChangeCameraShakeAtDelayMode )
					{
						_XPlaySoundEffect(ID_SR_INTERFACE_EARTHQUAKE01_WAV, g_pLocalUser->m_Position );
					}
					m_ChangeCameraShakeAtDelayMode = FALSE;
				}
			}
			else
			{
				m_CameraShakeMode = FALSE; 
				m_CameraShakeFactor = D3DXVECTOR3( 0.0f,0.0f,0.0f );
			}
		}
		
	}

	if( changedcamerastatus )
	{
		UpdateViewMatrix( &g_LodTerrain, TRUE );
		g_LodTerrain.m_ObjectQuadTree.UpdateCamera(g_LodTerrain.m_3PCamera);
		g_LodTerrain.RebuildLevel();
	}
}
Esempio n. 23
0
void IK::solve()
{
	//don't solve anything if this chain is simulated
	if (checkSimulated())
		return;

	//set up local variables used in solving the IK chain
	AMBone* destBone = _info.DestinationBone;
	AMBone* endEffBone = _info.EndEffectorBone;
	AMBone* curBone = NULL;
	D3DXVECTOR3 dest = D3DXVECTOR3(destBone->getCombinedTrans()(3,0), destBone->getCombinedTrans()(3,1), destBone->getCombinedTrans()(3,2));
	
	//lol I still have no clue how this crazy shit works
	//algorithm is pretty much taken directly from MMD
	IKLink *cl;
	BoneInfo *ci;
	for (int i=0;i<(int)_info.IterationCount;i++)
	{
		for (int b=0;b<(int)_info.NumberOfLinks;b++)
		{
			cl = &_info.BoneLinkList[b];
			curBone = cl->LinkBone;
			ci = curBone->getInfo();

			D3DXVECTOR3 left = curBone->getPosWorld()-endEffBone->getPosWorld();
			D3DXVECTOR3 right = curBone->getPosWorld()-destBone->getPosWorld();
			D3DXVECTOR3 axis;

			D3DXVECTOR3 vec = left - right;
			if (D3DXVec3Length(&vec)*D3DXVec3Length(&vec) < 1E-04f)
			{
				i = _info.IterationCount;
				break;
			}
			D3DXVec3Normalize(&left, &left);
			D3DXVec3Normalize(&right, &right);

			D3DXVec3Cross(&axis, &left, &right);
			if (D3DXVec3Length(&axis)*D3DXVec3Length(&axis) < 1E-7 && i > 0)
				continue;
			D3DXVec3Normalize(&axis, &axis);

			/*if (cl->AngleLimit && i < _info.IterationCount/2)
			{
				if (cl->LowerLimit.y == 0.0f && cl->UpperLimit.y == 0.0f && cl->LowerLimit.z == 0.0f && cl->UpperLimit.z == 0.0f)
				{
					float n = (axis.x*ci->Parent->getCombinedTrans()._11) + (axis.y*ci->Parent->getCombinedTrans()._12) + (axis.z*ci->Parent->getCombinedTrans()._13);
					if (n >= 0.0f)
						axis.x = 1.0f;
					else
						axis.x = -1.0f;
					axis.y = 0.0f;
					axis.z = 0.0f;
				}
				else
				{
					if (cl->LowerLimit.x == 0.0f && cl->UpperLimit.x == 0.0f && cl->LowerLimit.z == 0.0f && cl->UpperLimit.z == 0.0f)
					{	
						float n = (axis.x*ci->Parent->getCombinedTrans()._21) + (axis.y*ci->Parent->getCombinedTrans()._22) + (axis.z*ci->Parent->getCombinedTrans()._23);
						if (n >= 0.0f)
							axis.y = 1.0f;
						else
							axis.y = -1.0f;
						axis.x = 0.0f;
						axis.z = 0.0f;
					}
					else
					{
						if (cl->LowerLimit.x == 0.0f && cl->UpperLimit.x == 0.0f && cl->LowerLimit.y == 0.0f && cl->UpperLimit.y == 0.0f)
						{
							float n = (axis.x*ci->Parent->getCombinedTrans()._31) + (axis.y*ci->Parent->getCombinedTrans()._32) + (axis.z*ci->Parent->getCombinedTrans()._33);
							if (n >= 0.0f)
								axis.z = 1.0f;
							else
								axis.z = -1.0f;
							axis.x = 0.0f;
							axis.y = 0.0f;
						}
						else
						{
							D3DXVECTOR3 v;
							v.x = (axis.x*curBone->getCombinedTrans()._11)+(axis.y*curBone->getCombinedTrans()._12)+(axis.z*curBone->getCombinedTrans()._13);
							v.y = (axis.x*curBone->getCombinedTrans()._21)+(axis.y*curBone->getCombinedTrans()._22)+(axis.z*curBone->getCombinedTrans()._23);
							v.z = (axis.x*curBone->getCombinedTrans()._31)+(axis.y*curBone->getCombinedTrans()._32)+(axis.z*curBone->getCombinedTrans()._33);
							D3DXVec3Normalize(&axis, &v);
						}
					}
				}
			}
			else*/
			{
				D3DXVECTOR3 v;
				v.x = (axis.x*curBone->getCombinedTrans()._11)+(axis.y*curBone->getCombinedTrans()._12)+(axis.z*curBone->getCombinedTrans()._13);
				v.y = (axis.x*curBone->getCombinedTrans()._21)+(axis.y*curBone->getCombinedTrans()._22)+(axis.z*curBone->getCombinedTrans()._23);
				v.z = (axis.x*curBone->getCombinedTrans()._31)+(axis.y*curBone->getCombinedTrans()._32)+(axis.z*curBone->getCombinedTrans()._33);
				D3DXVec3Normalize(&axis, &v);
			}
			float dot = D3DXVec3Dot(&left, &right);
			if (dot > 1.0f)
				dot = 1.0f;
			else if (dot < -1.0f)
				dot = -1.0f;
			float angle = acosf(dot);
			if (angle > (_info.AngleConstraint * (b+1)*2))
			{
				angle = (_info.AngleConstraint * (b+1)*2);
			}
			D3DXQUATERNION newIkRot;
			D3DXQuaternionRotationAxis(&newIkRot, &axis, angle);
			D3DXQuaternionMultiply(&cl->IKQuat, &newIkRot, &cl->IKQuat);
			if (i == 0) //on first loop, apply rotation taken from the motion data
				D3DXQuaternionMultiply(&cl->IKQuat, &cl->IKQuat, &curBone->getRot());

			D3DXMATRIX matrix;
			D3DXMatrixRotationQuaternion(&matrix, &cl->IKQuat);
			if (cl->AngleLimit)
			{
				if ((double)cl->LowerLimit.x > -1.5707963267948966 && (double)cl->UpperLimit.x < 1.5707963267948966)
				{
					float num5 = -matrix._32;
					float num6 = asinf(num5);
					if (abs(num6) > 1.535889f)
					{
						if (num6 < 0.0f)
							num6 = -1.535889f;
						else
							num6 = 1.535889f;
					}
					float num7 = cosf(num6);
					float num8 = matrix._31/num7;
					float num9 = matrix._33/num7;
					float num10 = atan2f(num8, num9);
					float num11 = matrix._12/num7;
					float num12 = matrix._22/num7;
					float num13 = atan2f(num11, num12);
					bool loopFlag = i<(int)_info.IterationCount/2;
					num6 = GetUpperLowerRadian(num6, cl->LowerLimit.x, cl->UpperLimit.x, loopFlag);
					num10 = GetUpperLowerRadian(num10, cl->LowerLimit.y, cl->UpperLimit.y, loopFlag);
					num13 = GetUpperLowerRadian(num13, cl->LowerLimit.z, cl->UpperLimit.z, loopFlag);
					D3DXMATRIX nx, ny, nz;
					D3DXMatrixRotationX(&nx, num6);
					D3DXMatrixRotationY(&ny, num10);
					D3DXMatrixRotationZ(&nz, num13);
					matrix = nz*nx*ny;
				}
				else
				{
					if ((double)cl->LowerLimit.y > -1.5707963267948966 && (double)cl->UpperLimit.y < 1.5707963267948966)
					{
						float num14 = -matrix._13;
						float num15 = asinf(num14);
						if (abs(num15) > 1.535889f)
						{
							if (num15 < 0.0f)
							{
								num15 = -1.535889f;
							}
							else
							{
								num15 = 1.535889f;
							}
						}
						float num16 = cosf(num15);
						float num17 = matrix._23 / num16;
						float num18 = matrix._33 / num16;
						float num19 = atan2f(num17, num18);
						float num20 = matrix._12 / num16;
						float num21 = matrix._11 / num16;
						float num22 = atan2f(num20, num21);
						bool loopFlag = i<(int)_info.IterationCount/2;
						num19 = GetUpperLowerRadian(num19, cl->LowerLimit.x, cl->UpperLimit.x, loopFlag);
						num15 = GetUpperLowerRadian(num15, cl->LowerLimit.y, cl->UpperLimit.y, loopFlag);
						num22 = GetUpperLowerRadian(num22, cl->LowerLimit.z, cl->UpperLimit.z, loopFlag);
						D3DXMATRIX nx, ny, nz;
						D3DXMatrixRotationX(&nx, num19);
						D3DXMatrixRotationY(&ny, num15);
						D3DXMatrixRotationZ(&nz, num22);
						matrix = nx*ny*nz;
					}
					else
					{
						float num23 = -matrix._21;
						float num24 = asinf(num23);
						if (abs(num24) > 1.535889f)
						{
							if (num24 < 0.0f)
							{
								num24 = -1.535889f;
							}
							else
							{
								num24 = 1.535889f;
							}
						}
						float num25 = cosf(num24);
						float num26 = matrix._23 / num25;
						float num27 = matrix._22 / num25;
						float num28 = atan2f(num26, num27);
						float num29 = matrix._31 / num25;
						float num30 = matrix._11 / num25;
						float num31 = atan2f(num29, num30);
						bool loopFlag = i<(int)_info.IterationCount/2;
						num28 = GetUpperLowerRadian(num28, cl->LowerLimit.x, cl->UpperLimit.x, loopFlag);
						num31 = GetUpperLowerRadian(num31, cl->LowerLimit.y, cl->UpperLimit.y, loopFlag);
						num24 = GetUpperLowerRadian(num24, cl->LowerLimit.z, cl->UpperLimit.z, loopFlag);
						D3DXMATRIX nx, ny, nz;
						D3DXMatrixRotationX(&nx, num28);
						D3DXMatrixRotationY(&ny, num31);
						D3DXMatrixRotationZ(&nz, num24);
						matrix = ny*nz*nx;
					}
				}
				D3DXQuaternionRotationMatrix(&cl->IKQuat, &matrix);
			}
			curBone->setRot(cl->IKQuat);
			//curBone->setCombTrans(matrix);

			for (int j=b;j>=0;j--)
			{
				_info.BoneLinkList[j].LinkBone->UpdateFromIK();
			}
			endEffBone->UpdateFromIK();
		}
	}

	for (int i=0;i<(int)_info.NumberOfLinks;i++)
	{
		_info.BoneLinkList[i].IKQuat = D3DXQUATERNION(0,0,0,1);
	}
}
Esempio n. 24
0
D3DXMATRIX GAnimation::Interpolate(GMesh* pMesh, D3DXMATRIX* matParents, float fFrameTick, TScene tScene)
{

	// TM		= AnimMat * ParentTM;
	// AaniMat	= TM * Inverse(ParentTM)
	D3DXQUATERNION qR, qS;
	D3DXMATRIX matAnim, matPos, matRotate, matScale, matCalculation;

	D3DXMatrixIdentity(&matCalculation);

	matRotate = pMesh->m_matWorldRotate;
	matPos = pMesh->m_matWorldTrans;
	matScale = pMesh->m_matWorldScale;

	D3DXQuaternionRotationMatrix(&qR, &matRotate);
	D3DXQuaternionRotationMatrix(&qS, &matScale);

	// fFrameTick = m_Scene.iFirstFrame * m_Scene.iTickPerFrame + CurFame;
	float fStartTick = tScene.iFirstFrame * tScene.iTickPerFrame;
	float fEndTick = 0.0f;

	TAnimTrack* pStartTrack = NULL;
	TAnimTrack* pEndTrack = NULL;
	if (pMesh->m_pRotTrack.size())
	{
		// pStartTrack를 찾을수 있으면
		if (GetAnimationTrack(fFrameTick, pMesh->m_pRotTrack, &pStartTrack, &pEndTrack))
		{
			qR = pStartTrack->qRotate;
			fStartTick = pStartTrack->iTick;
		}
		if (pEndTrack)
		{
			fEndTick = pEndTrack->iTick;
			D3DXQuaternionSlerp(&qR, &qR, &pEndTrack->qRotate, (fFrameTick - fStartTick) / (fEndTick - fStartTick));
		}
		D3DXMatrixRotationQuaternion(&matRotate, &qR);
	}

	pStartTrack = NULL;
	pEndTrack = NULL;

	D3DXVECTOR3 Trans(matPos._41, matPos._42, matPos._43);
	if (pMesh->m_pPosTrack.size())
	{
		// pStartTrack를 찾을수 있으면
		if (GetAnimationTrack(fFrameTick, pMesh->m_pPosTrack, &pStartTrack, &pEndTrack))
		{
			Trans = pStartTrack->vVector;
			fStartTick = pStartTrack->iTick;
		}
		if (pEndTrack)
		{
			fEndTick = pEndTrack->iTick;
			D3DXVec3Lerp(&Trans, &Trans, &pEndTrack->vVector, (fFrameTick - fStartTick) / (fEndTick - fStartTick));
		}

		D3DXMatrixTranslation(&matPos, Trans.x, Trans.y, Trans.z);
	}


	pStartTrack = NULL;
	pEndTrack = NULL;

	D3DXMATRIX matScaleRot, matInvScaleRot;
	D3DXVECTOR3 vScale(matScale._11, matScale._22, matScale._33);
	if (pMesh->m_pSclTrack.size())
	{
		// pStartTrack를 찾을수 있으면
		if (GetAnimationTrack(fFrameTick, pMesh->m_pSclTrack, &pStartTrack, &pEndTrack))
		{
			vScale = pStartTrack->vVector;
			qS = pStartTrack->qRotate;
			fStartTick = pStartTrack->iTick;
		}
		if (pEndTrack)
		{
			fEndTick = pEndTrack->iTick;
			D3DXVec3Lerp(&vScale, &vScale, &pEndTrack->vVector, (fFrameTick - fStartTick) / (fEndTick - fStartTick));
			D3DXQuaternionSlerp(&qS, &qS, &pEndTrack->qRotate, (fFrameTick - fStartTick) / (fEndTick - fStartTick));
		}
		D3DXMatrixScaling(&matScale, vScale.x, vScale.y, vScale.z);
		D3DXMatrixRotationQuaternion(&matScaleRot, &qS);
		D3DXMatrixInverse(&matInvScaleRot, NULL, &matScaleRot);
		matScale = matInvScaleRot  * matScale * matScaleRot;
	}

	pStartTrack = NULL;
	pEndTrack = NULL;

	float fCurAlpha, fNextAlpha, fOffSet;
	fCurAlpha = 0.0f;
	fNextAlpha = 0.0f;
	if (pMesh->m_pVisTrack.size())
	{
		// pStartTrack를 찾을수 있으면
		if (GetAnimationTrack(fFrameTick, pMesh->m_pVisTrack, &pStartTrack, &pEndTrack))
		{
			fCurAlpha = pStartTrack->vVector.x;
			fStartTick = pStartTrack->iTick;
		}
		if (pEndTrack)
		{
			fNextAlpha = pEndTrack->vVector.x;
			fEndTick = pEndTrack->iTick;

			fOffSet = (fFrameTick - fStartTick) / (fEndTick - fStartTick);
			fNextAlpha = (fNextAlpha - fCurAlpha)*fOffSet;
		}
		pMesh->m_fVisibility = (fCurAlpha + fNextAlpha);
	}
	else
	{
		pMesh->m_fVisibility = 1.0f;
	}

	D3DXMatrixMultiply(&matAnim, &matScale, &matRotate);
	matAnim._41 = matPos._41;
	matAnim._42 = matPos._42;
	matAnim._43 = matPos._43;
	// 최종 에미메이션 행렬을 완성한다.	
	D3DXMatrixMultiply(&matCalculation, &matAnim, matParents);

	// 인버스 매트릭스 확인 코드.
	D3DXVECTOR3 v0, v1, v2, v3;
	v0 = pMesh->m_matCalculation.m[0];
	v1 = pMesh->m_matCalculation.m[1];
	v2 = pMesh->m_matCalculation.m[2];
	D3DXVec3Cross(&v3, &v1, &v2);
	if (D3DXVec3Dot(&v3, &v0) < 0.0f)
	{
		D3DXMATRIX matW;
		D3DXMatrixScaling(&matW, -1.0f, -1.0f, -1.0f);
		D3DXMatrixMultiply(&matCalculation, &pMesh->m_matCalculation, &matW);
	}
	return matCalculation;
}
Esempio n. 25
0
void zz_bone::apply_channel_by_time (zz_time time, zz_motion * motion, int custum_fps, float blend_weight)
{
	assert(motion && "apply_channel_by_time");
	assert(blend_weight >= 0.0f && blend_weight <= 1.0f && "apply_channel_by_time");

	if (position_channel_index >= 0) {
		if (blend_weight < 1.0f) { // if use blend_weight
			vec3 last_position = position;
			motion->get_channel_data(position_channel_index, time, &position, custum_fps);
			position = znzin->motion_tool.blend_position(last_position, position, blend_weight);
		}
		else { // no blend
			motion->get_channel_data(position_channel_index, time, &position, custum_fps);
		}
	}

	if (rotation_channel_index >= 0) {
		if(!forced_rotation_onoff)
		{
			if (blend_weight < 1.0f) { // if use blend_weight
				quat last_rotation = rotation;
				motion->get_channel_data(rotation_channel_index, time, &rotation, custum_fps);
				rotation = znzin->motion_tool.blend_rotation(last_rotation, rotation, blend_weight);
			
			}
			else { // no blend
				motion->get_channel_data(rotation_channel_index, time, &rotation, custum_fps);
			}
		}
		else
		{			
			if(forced_rotation_calculate_onoff)
			{			
				float diff_time = znzin->get_diff_time();
				const float angle_per_time = 0.3f*3.141592f / ZZ_TICK_PER_SEC;  
				float new_angle_diff = angle_per_time * diff_time;	 
	            
				if( forced_rotation_angle_ + new_angle_diff > forced_rotation_angle)
				{
					forced_rotation_angle_ = forced_rotation_angle;
				    forced_rotation_calculate_onoff = false; 
				}
				else
				{
					forced_rotation_angle_ += new_angle_diff;

				}
			
			}
			
			D3DXQUATERNION dx_quat;
			D3DXMATRIX buffer_m;
			D3DXMATRIX buffer_m2, buffer_m3;
			dx_quat.x = forcde_rotation_quat.x; dx_quat.y = forcde_rotation_quat.y; dx_quat.z = forcde_rotation_quat.z; dx_quat.w = forcde_rotation_quat.w;
            D3DXMatrixRotationQuaternion(&buffer_m, &dx_quat);
            D3DXMatrixRotationAxis(&buffer_m2, &forced_rotation_axis, forced_rotation_angle_);
            buffer_m3 = buffer_m2 * buffer_m;
            
			D3DXQuaternionRotationMatrix(&dx_quat, &buffer_m3);
			rotation.x = dx_quat.x; rotation.y = dx_quat.y; rotation.z = dx_quat.z; rotation.w = dx_quat.w;
            
				
		}
	}
	//invalidate_transform();
}
Esempio n. 26
0
int CGPAnim::CalcFrameData( CShdHandler* lpsh, CMotHandler* lpmh, D3DXMATRIX* matWorld )
{
    int ret;
    int frameno;

    if( !m_firstkey ) {
        for( frameno = 0; frameno <= m_maxframe; frameno++ ) {
            ( m_framedata + frameno )->m_frameno = frameno;
            ( m_framedata + frameno )->m_gpe = *m_defgpeptr;
            ( m_framedata + frameno )->m_interp = *m_definterptr;
            ( m_framedata + frameno )->m_keyflag = 0;
        }
        return 0;//!!!!!!!
    }

    CGPKey* gpkptr = m_firstkey;

#ifdef INEASY3D
    while( gpkptr ) {
        CQuaternion orgq;
        CQuaternion qx, qy, qz;
        D3DXVECTOR3 axisX( 1.0f, 0.0f, 0.0f );
        D3DXVECTOR3 axisY( 0.0f, 1.0f, 0.0f );
        D3DXVECTOR3 axisZ( 0.0f, 0.0f, 1.0f );
        qx.SetAxisAndRot( axisX, gpkptr->m_gpe.rot.x * (float)DEG2PAI );
        qy.SetAxisAndRot( axisY, gpkptr->m_gpe.rot.y * (float)DEG2PAI );
        qz.SetAxisAndRot( axisZ, gpkptr->m_gpe.rot.z * (float)DEG2PAI );
        orgq = qy * qx * qz;

        D3DXMATRIX orgmat;
        orgmat = orgq.MakeRotMatX();
        orgmat._41 = gpkptr->m_gpe.pos.x;
        orgmat._42 = gpkptr->m_gpe.pos.y;
        orgmat._43 = gpkptr->m_gpe.pos.z;

        /////////
        D3DXMATRIX multmat;
        multmat = orgmat * *m_offmatptr;
        //multmat = *m_offmatptr * orgmat;

        gpkptr->m_gpe.e3dpos.x = multmat._41;
        gpkptr->m_gpe.e3dpos.y = multmat._42;
        gpkptr->m_gpe.e3dpos.z = multmat._43;

        //////////
        D3DXMATRIX rotmat;
        rotmat = multmat;
        rotmat._41 = 0.0f;
        rotmat._42 = 0.0f;
        rotmat._43 = 0.0f;

        D3DXQUATERNION mqx, invmqx;
        D3DXQuaternionRotationMatrix( &mqx, &rotmat );
        D3DXQuaternionInverse( &invmqx, &mqx );
        CQuaternion mq;
        mq.x = mqx.x;
        mq.y = mqx.y;
        mq.z = mqx.z;
        mq.w = mqx.w;

        D3DXVECTOR3 neweul;
        ret = qToEuler( 0, &mq, &neweul );
        ret = modifyEuler( &neweul, &gpkptr->m_gpe.e3drot );

        gpkptr->m_gpe.e3drot = neweul;


        gpkptr = gpkptr->next;
    }
#endif

//キーの接地計算
    //CGPKey* gpkptr = m_firstkey;
    gpkptr = m_firstkey;
    if( lpsh ) {
        while( gpkptr ) {
            if( gpkptr->m_gpe.ongmode != GROUND_NONE ) {
                //D3DXMATRIX inimat;
                //D3DXMatrixIdentity( &inimat );
                D3DXVECTOR3 befpos, newpos;
#ifdef INEASY3D
                befpos = gpkptr->m_gpe.e3dpos;
                befpos.y = gpkptr->m_gpe.rayy + m_offmatptr->_42;
                newpos = gpkptr->m_gpe.e3dpos;
                newpos.y = gpkptr->m_gpe.rayy - gpkptr->m_gpe.rayleng;
                int result = 0;
                D3DXVECTOR3 adjustv, nv;
                ret = lpsh->ChkConfGround( 0, 0, matWorld, befpos, newpos, lpmh, 0, 200.0f, newpos.y - 100.0f, &result, &adjustv, &nv );
                if( ret ) {
                    DbgOut( "GPAnim : CalcFrameData : sh ChkConfGround error !!!\n" );
                    _ASSERT( 0 );
                    return 1;
                }
                if( result ) {
                    gpkptr->m_gpe.e3dpos = adjustv;
                    gpkptr->m_gpe.e3dpos.y += gpkptr->m_gpe.offsety;
                }
#else
                befpos = gpkptr->m_gpe.pos;
                befpos.y = gpkptr->m_gpe.rayy;
                newpos = gpkptr->m_gpe.pos;
                newpos.y = gpkptr->m_gpe.rayy - gpkptr->m_gpe.rayleng;

                int result = 0;
                D3DXVECTOR3 adjustv, nv;
                ret = lpsh->ChkConfGround( 0, 0, matWorld, befpos, newpos, lpmh, 0, 200.0f, newpos.y - 100.0f, &result, &adjustv, &nv );
                if( ret ) {
                    DbgOut( "GPAnim : CalcFrameData : sh ChkConfGround error !!!\n" );
                    _ASSERT( 0 );
                    return 1;
                }
                if( result ) {
                    gpkptr->m_gpe.pos = adjustv;
                    gpkptr->m_gpe.pos.y += gpkptr->m_gpe.offsety;
                }
#endif
            }
            gpkptr = gpkptr->next;
        }
    }


    CGPKey* prevkey = 0;
    CGPKey* nextkey = 0;
    for( frameno = 0; frameno <= m_maxframe; frameno++ ) {
        CGPKey* dstkey = m_framedata + frameno;
        dstkey->m_frameno = frameno;

        int findkey = 0;
        CGPKey* tmpkey = 0;
        ExistGPKey( frameno, &tmpkey );
        if( tmpkey ) {
            findkey = 1;
            prevkey = tmpkey;
        }
        if( prevkey ) {
            nextkey = prevkey->next;
        }

        dstkey->m_keyflag = findkey;

        if( findkey ) {
            dstkey->m_gpe = prevkey->m_gpe;
            dstkey->m_interp = prevkey->m_interp;
        } else if( !prevkey ) {
            dstkey->m_gpe = *m_defgpeptr;
            dstkey->m_interp = *m_definterptr;
        } else if( !nextkey ) {
            dstkey->m_gpe = prevkey->m_gpe;
            dstkey->m_interp = prevkey->m_interp;
        } else {
            dstkey->m_interp = prevkey->m_interp;
            int framenum;
            framenum = nextkey->m_frameno - prevkey->m_frameno;
            int framecnt;
            framecnt = frameno - prevkey->m_frameno;

//DbgOut( "check!!! : GPAnim : CalcFrameData : frameno %d, maxframe %d, framenum %d, framecnt %d\r\n",
//	frameno, m_maxframe, framenum, framecnt );

            ret = FillUpGPElem( prevkey, nextkey, &dstkey->m_gpe, framenum, framecnt, prevkey->m_interp, lpsh, lpmh, matWorld );
            if( ret ) {
                DbgOut( "GPAnim : CalcFrameData : FillUpGPElem error !!!\n" );
                _ASSERT( 0 );
                return 1;
            }
        }
    }

    return 0;
}
Esempio n. 27
0
HRESULT GdsNode::Update( float fElapsedtime )
{	
	if ( m_bCull )
		return FALSE;

	D3DXMATRIX matTrans, matScale, matRot;
	D3DXMatrixIdentity( &matTrans );
	D3DXMatrixIdentity( &matScale );
	D3DXMatrixIdentity( &matRot );

	D3DXMatrixTranslation(&matTrans, m_vTranslate.x, m_vTranslate.y, m_vTranslate.z);
	D3DXMatrixScaling(&matScale, m_vScale.x, m_vScale.y, m_vScale.z);
	D3DXMatrixRotationQuaternion(&matRot, &m_qRotate);

	m_matLocal = matTrans * matRot * matScale;

	if( GetParent() )
	{
		D3DXMATRIX parTM;
		parTM = GetParent()->GetWorldMatrix();
		//m_matWorld = m_matLocal * m_matAni * m_pParent->GetWorldMatrix();
		m_matWorld = m_matLocal * parTM;
	}
	else
	{
		m_matWorld = m_matLocal;
	}

	m_vWorldTranslate = D3DXVECTOR3(m_matWorld._41, m_matWorld._42, m_matWorld._43 ) ;
	D3DXQuaternionRotationMatrix(&m_qWorldRotate, &m_matWorld);
	// 뷰 판정
	if ( CAMMGR.GetCurCam()->GetFrustum().VertexIsInFrustum( m_vWorldTranslate ) == false )	
	{
		return FALSE;
	}


	if ( m_bShowAxis )
	{
		D3DXVECTOR3 cenPos( 5.f , 5.f , 5.f );
		RENDERER.DrawAxis( m_matWorld , cenPos );
	}
	if ( m_bShowBox )
	{
		D3DXVECTOR3 minPos( -10.f , -10.f , -10.f );
		D3DXVECTOR3 maxPos( 10.f , 10.f , 10.f );
		RENDERER.DrawBox( m_matWorld , minPos , maxPos );
	}


	if ( m_bUseOctree )
	{
		GenOctreeFaceIndex();
	}

	if ( !m_list_RenderObject.empty() )
	{
		RENDER_OBJECT_CONTAINER::iterator it = m_list_RenderObject.begin();
		for ( ; it != m_list_RenderObject.end() ; ++it )
		{
			it->first->SetMatrix( m_matWorld );
			//RENDERER.GetRenderFrame()->AttachRenderObject( it->first , it->second );
		}			
	}		

	vUpdate( fElapsedtime );


	if ( !m_ChildNode.empty() )
	{
		for( CHILDNODE_CONTAINER::iterator it = m_ChildNode.begin() ; it != m_ChildNode.end() ; ++it )
		{
			(*it)->Update(fElapsedtime);
		}
	}		

	return TRUE;
}