Ejemplo n.º 1
0
// get joint descriptors for this block
void VDSWheelBrick::CreateJoints( VDSSceneEntity* _pVDSEntity )
{
    TSRMatrix4 HingeLoc;
    m_BoundBox.GetWorldMatrix( HingeLoc );
    // here we have just one hinge
	TSRRigidBody* pBodyA = _pVDSEntity->GetRigidBody( m_BoundBox.GetRigidBodyIndex() );
	TSRRigidBody* pBodyB = _pVDSEntity->GetRigidBody( m_WheelBox.GetRigidBodyIndex() );
	TSRVector3 vAnchor = HingeLoc.GetLoc();
	TSRVector3 vAxis( HingeLoc._31, HingeLoc._32, HingeLoc._33 );
    m_pHinge = GetVDSSubSystem()->CreateHinge( _pVDSEntity->GetJointGroup(), pBodyA, pBodyB, vAnchor, vAxis );
}
Ejemplo n.º 2
0
//-----------------------------------------------------------------------
bool gkObjectManager::checkSelected( uint8 type, f32 size, bool draging )
{
	// first of all, get the 3 axis end point at screenspace [8/25/2011 Kaiming-Desktop]
	Vec2 vCursor = GetIEditor()->getMainViewport()->getCursorOnClientScreen();
	Vec3 vAxis3D;
	Vec3 vCenter3D;

	Vec3 vCenterReal = ms_pCurrentPick->getWorldPosition();
	Vec3 vDirReal(0,0,0);

	vCenter3D = gEnv->pRenderer->ProjectScreenPos( vCenterReal );

	switch(type)
	{
	case GKSTUDIO_AXIS_X:
		vDirReal = ms_pCurrentPick->getOrientation().GetColumn0();
		break;
	case GKSTUDIO_AXIS_Y:
		vDirReal = ms_pCurrentPick->getOrientation().GetColumn1();
		break;
	case GKSTUDIO_AXIS_Z:
		vDirReal = ms_pCurrentPick->getOrientation().GetColumn2();
		break;
	}

	vAxis3D = gEnv->pRenderer->ProjectScreenPos( ms_pCurrentPick->getWorldPosition() + size * vDirReal );

	// make two 2D vector
	Vec2 vCenter(vCenter3D.x, vCenter3D.y);
	Vec2 vAxis(vAxis3D.x, vAxis3D.y);

	Vec2 vPoint = vCursor - vCenter;
	Vec2 vAxisPoint = vAxis - vCenter;

	ms_dragInvertX = vAxisPoint.x > 0 ? 1 : -1;
	ms_dragInvertY = vAxisPoint.y > 0 ? 1 : -1;

	// judge this
	if (vPoint.GetLength() - vAxisPoint.GetLength() < size + 2.0f)
	{
		vPoint.Normalize();
		vAxisPoint.Normalize();

		if (vPoint.Dot(vAxisPoint) > 0.95f)
			return true;
	}

	return false;
}
Ejemplo n.º 3
0
void Camera::Update()
{
	glm::vec3 vAxis(0.0f, 1.0f, 0.0f);

	//Rotate the view vector by the horizontal angle around the vertical axis
	glm::vec3 vView(1.0f, 0.0f, 0.0f);
	vView = glm::rotate(vView, Theta, vAxis);
	vView = glm::normalize(vView);

	//Rotate the view vector by the vertical angle around the horizontal axis
	glm::vec3 hAxis = glm::cross(vAxis, vView);
	hAxis = glm::normalize(hAxis);
	vView = glm::rotate(vView, Phi, hAxis);

	target = vView;
	target = glm::normalize(target);

	up = glm::cross(target, hAxis);
	up = glm::normalize(up);

}
Ejemplo n.º 4
0
void CNodeController::UpdateLipSyncControl(NCSTRUCT *pNodeControl)
{
	// Make sure the sound handle is valid and check to see if the sound is done...
    if(!pNodeControl->hLipSyncSound || g_pLTClient->IsDone(pNodeControl->hLipSyncSound))
	{
		g_pLTClient->KillSound(pNodeControl->hLipSyncSound);
        pNodeControl->hLipSyncSound = LTNULL;

		if (pNodeControl->bShowingSubtitles)
		{
 			g_pInterfaceMgr->ClearSubtitle();
		}

        pNodeControl->pSixteenBitBuffer = LTNULL;
        pNodeControl->pEightBitBuffer = LTNULL;
        pNodeControl->bValid = LTFALSE;
		return;
	}


	//
	// Process the current sound data (average over sound amplitude).
	//

    LTFLOAT fAverage = 0.0f;  // this will hold the average, normalized from 0.0f to 1.0f.

	// Get the sound buffer.
	if( !pNodeControl->pSixteenBitBuffer && !pNodeControl->pEightBitBuffer )
	{
        uint32 dwChannels = 0;

        g_pLTClient->GetSoundData(pNodeControl->hLipSyncSound,
							pNodeControl->pSixteenBitBuffer,
							pNodeControl->pEightBitBuffer,
							&pNodeControl->dwSamplesPerSecond,
							&dwChannels);
		ASSERT( dwChannels == 1);
		// If you want to use multi-channel sounds (why would you?), you'll need to
		//  to account for the interleaving of channels in the following code.
	}

	ASSERT( pNodeControl->pSixteenBitBuffer || pNodeControl->pEightBitBuffer );


	// Average over the data.  We do an average of the data from the current point
	// being played to 1/g_vtLipSyncFreq.GetFloat() seconds ahead of that point.
    uint32 dwOffset = 0;
    uint32 dwSize   = 0;

    if( LT_OK == g_pLTClient->GetSoundOffset(pNodeControl->hLipSyncSound, &dwOffset, &dwSize) )
	{
		// Determine the end of the data we wish to average over.
        const uint32 dwDivisor = uint32(g_vtLipSyncFreq.GetFloat());
        uint32 dwOffsetEnd = dwOffset + pNodeControl->dwSamplesPerSecond/dwDivisor;
		if( dwOffsetEnd > dwSize )
			dwOffsetEnd = dwSize;


		// Accumulate the the amplitudes for the average.
        uint32 dwMaxAmplitude = 0;

        uint32 dwNumSamples = 0;
        uint32 dwAccum = 0;

		if( pNodeControl->pSixteenBitBuffer )
		{
			for( int16 * pIterator = pNodeControl->pSixteenBitBuffer + dwOffset;
			     pIterator < pNodeControl->pSixteenBitBuffer + dwOffsetEnd;
				 ++pIterator)
			{
				dwAccum += abs(*pIterator);
				++dwNumSamples;
			}

			dwMaxAmplitude = 65536/2;

			#ifdef GRAPH_LIPSYNC_SOUND
				g_GraphPoints.RecordData(pNodeControl->pSixteenBitBuffer,dwSize,dwOffset);
			#endif

		}
		else if( pNodeControl->pEightBitBuffer )
		{
			for( int8 * pIterator = pNodeControl->pEightBitBuffer + dwOffset;
			     pIterator < pNodeControl->pEightBitBuffer + dwOffsetEnd;
				 ++pIterator)
			{
				dwAccum += abs(*pIterator);
				++dwNumSamples;
			}

			dwMaxAmplitude = 256/2;

			#ifdef GRAPH_LIPSYNC_SOUND
				g_GraphPoints.RecordData(pNodeControl->pEightBitBuffer,dwSize,dwOffset);
			#endif
		}

		// And find the average!
		if( dwNumSamples > 0 )
            fAverage = LTFLOAT(dwAccum) / LTFLOAT(dwNumSamples) / LTFLOAT(dwMaxAmplitude);

    } //if( LT_OK == g_pLTClient->GetSoundOffset(pNodeControl->hLipSyncSound, &dwOffset, &dwSize) )

	//
	// Do the rotation.
	//
    ILTMath *pMathLT = g_pLTClient->GetMathLT();

    LTRotation rRot;
    rRot.Init();
    LTVector vAxis(0.0f, 0.0f, 1.0f);
    LTFLOAT fMaxRot = MATH_DEGREES_TO_RADIANS(g_vtLipSyncMaxRot.GetFloat());

	// Calculate the rotation.
	m_fCurLipSyncRot =  fAverage*fMaxRot;
	pMathLT->RotateAroundAxis(rRot, vAxis, -m_fCurLipSyncRot);

	// Create a rotation matrix and apply it to the current offset matrix
    LTMatrix m1;
	pMathLT->SetupRotationMatrix(m1, rRot);
	m_aNodes[pNodeControl->eModelNode].matTransform = m_aNodes[pNodeControl->eModelNode].matTransform * m1;
}
Ejemplo n.º 5
0
void CGameEng::Tick(const D3DCOLOR* crDiffuses,			// Diffuse 라이트 색깔.. 3 개 쓴다.
					const D3DCOLOR* crAmbients,			// Ambient 라이트 색깔.. 3 개 쓴다.
					const D3DCOLOR crFog,				// 안개 색깔..
					const __Vector3& vPosPlayer,		// 플레이어 위치
					const __Quaternion& qtPlayer,		// 회전 쿼터니언
					float fHeightPlayer,				// 키를 인수로 넣으면 카메라와 라이트 처리..
					float fSunRadianZ)					// 해의 Z 각도..
{
	if(NULL == m_pActiveCam) return;

	float fRadius = fHeightPlayer * 2.0f;
	float fYaw = 0;
	__Quaternion qtRot = qtPlayer;
	__Vector3 vAxis(0,1,0);
	qtRot.AxisAngle(vAxis, fYaw);
	
	if(vAxis.y < 0) // 회전축이 음수이면.
	{
		vAxis.y *= -1.0f;
		fYaw *= -1.0f;
	}

	switch(m_eViewPoint)
	{
		case VP_BACKWARD:
		{
			::D3DXQuaternionRotationYawPitchRoll(&qtRot, fYaw, m_fRotPitchBackward, 0);
			__Matrix44 mtxRot = qtRot;

			m_vEyeToReach.Set(0, 0, -(fRadius / s_CameraData.fFOV) * m_fZoomBackwardOrFoward);
			m_vAtToReach = vPosPlayer; m_vAtToReach.y += fHeightPlayer * 0.8f;
			m_vEyeToReach = m_vAtToReach + (m_vEyeToReach * mtxRot);
		}
		break;
		case VP_FIRST_PERSON:
		{
			::D3DXQuaternionRotationYawPitchRoll(&qtRot, fYaw, m_fRotPitchFirstPerson, 0);
			__Matrix44 mtxRot = qtRot;

			m_vEyeToReach = vPosPlayer; m_vEyeToReach.y += fHeightPlayer - 0.1f;
			m_vAtToReach.Set(0,0,1);
			m_vAtToReach = m_vEyeToReach + (m_vAtToReach * mtxRot);
		}
		break;
		case VP_FOWARD:
		{
			::D3DXQuaternionRotationYawPitchRoll(&qtRot, fYaw, -m_fRotPitchFoward, 0);
			__Matrix44 mtxRot = qtRot;

			m_vEyeToReach.Set(0, 0, fRadius * m_fZoomBackwardOrFoward);
			m_vAtToReach = vPosPlayer; m_vAtToReach.y += fHeightPlayer * 0.8f;
			m_vEyeToReach = m_vAtToReach + (m_vEyeToReach * mtxRot);
		}
		break;
		case VP_THIRD_PERSON:
		{
			::D3DXQuaternionRotationYawPitchRoll(&qtRot, m_fRotYawVPGod, m_fRotPitchThirdFirson, 0);
			__Matrix44 mtxRot = qtRot;

			m_vAtToReach = vPosPlayer; m_vAtToReach.y += fHeightPlayer * 0.8f;
			m_vEyeToReach.Set(0,0,-m_fOffsetVPGod);
			m_vEyeToReach = m_vAtToReach + (m_vEyeToReach * mtxRot);
		}
		break;
	}

	////////////////////////////////////////////////////////////////////////////////////
	// 카메라 충돌 체크...
	if(VP_FIRST_PERSON == m_eViewPoint) // 일인칭때는 충돌체크 안한다.
	{
		m_pActiveCam->LookAt(m_vEyeToReach, m_vAtToReach, __Vector3(0,1,0)); // 처다본다..
	}
	else
	{
		__Vector3 vEyeResult = m_vEyeToReach;
		float fNP = m_pActiveCam->m_Data.fNP;
		CGameBase::ACT_WORLD->CheckCollisionCameraWithTerrain(vEyeResult, m_vAtToReach, fNP); // 지형과 충돌체크
		CGameBase::ACT_WORLD->CheckCollisionCameraWithShape(vEyeResult, m_vAtToReach, fNP); // 오브젝트와 충돌체크..
		m_pActiveCam->LookAt(vEyeResult, m_vAtToReach, __Vector3(0,1,0)); // 처다본다..
	}
	// 카메라 충돌 체크...
	////////////////////////////////////////////////////////////////////////////////////


	// 파 플레인 값을 조정..
	// ApplyCameraAndLight 에서 실제로 안개등의 값을 조절한다.
	if(m_fFPDeltaCur != m_fFPDeltaToReach)
	{
		float fFPChange = (m_fFPDeltaToReach - m_fFPDeltaCur) * s_fSecPerFrm / 5.0f; // 5초동안 변하게 한다.
		m_fFPDeltaCur += fFPChange;

		if(fFPChange < 0 && m_fFPDeltaCur < m_fFPDeltaToReach) m_fFPDeltaCur = m_fFPDeltaToReach;
		if(fFPChange > 0 && m_fFPDeltaCur > m_fFPDeltaToReach) m_fFPDeltaCur = m_fFPDeltaToReach;
	}
	float fFPToRestore = m_pActiveCam->m_Data.fFP;
	m_pActiveCam->m_Data.fFP = s_Options.iViewDist * m_fFPDeltaCur;
	
	m_pActiveCam->m_FogColor = crFog; // 안개색을 맞춘다..
	m_pActiveCam->Tick(); // 적용및 사면체등등의 값들을 계산..

	__Matrix44 mtxRotSun;
	mtxRotSun.RotationZ(fSunRadianZ); // 해의 각도에 맞춘다..

	/*
	it_Light itLgt = m_Lights.begin();
	int iSize = m_Lights.size();
	for(int i = 0; i < iSize; i++, itLgt++)
	{
		CN3Light* pLight = *itLgt;
		__ASSERT(pLight, "Light pointer is NULL!!!");
		
		if(0 == pLight->m_Data.nNumber) // 기본 디렉셔널 라이트
		{
			// View Matrix 각도와 방향을 맞춘다..
//			__Vector3 vDir(0.0f,-1.5f,1.0f);
//			vDir.Normalize();
//			__Matrix44 mtxVI = s_CameraData.mtxViewInverse;
//			mtxVI.PosSet(0,0,0);
//			pLight->m_Data.Direction = vDir * mtxVI;

			// 해와 방향을 맞춘다..
			__Matrix44 mtxRot; mtxRot.RotationZ(fSunRadianZ);
			__Vector3 vDir(-1,0,1);
			vDir *= mtxRot;
			vDir.Normalize();
			pLight->m_Data.Direction = vDir;
			
			// 라이트 컬러 적용..
			pLight->m_Data.Diffuse = ::_D3DCOLOR_To_D3DCOLORVALUE(crDiffuses[0]);
			pLight->m_Data.Ambient = ::_D3DCOLOR_To_D3DCOLORVALUE(crAmbients[0]);
		}
		else if(1 == pLight->m_Data.nNumber)
		{
			__Vector3 vDir(2,-3, 2); // 위에서 아래로 ...
			vDir.Normalize();
			pLight->m_Data.Direction = vDir;
			
			// 라이트 컬러 적용..
			pLight->m_Data.Diffuse = ::_D3DCOLOR_To_D3DCOLORVALUE(crDiffuses[1]);
			pLight->m_Data.Ambient = ::_D3DCOLOR_To_D3DCOLORVALUE(crAmbients[1]);
		}
		else if(2 == pLight->m_Data.nNumber)
		{
			__Vector3 vPos = s_CameraData.vEye;
			vPos.y += 16.0f;
			pLight->PosSet(vPos); // 카메라 위에 가게 한다..
			
			// 라이트 컬러 적용..
			pLight->m_Data.Diffuse = ::_D3DCOLOR_To_D3DCOLORVALUE(crDiffuses[2]);
			pLight->m_Data.Ambient = ::_D3DCOLOR_To_D3DCOLORVALUE(crAmbients[2]);
		}


		// 번개 처리..
		if(m_fLightningTimeRemain > 0)
		{
			float fLightningDelta = 0;

			if(m_fLightningTimeRemain > LIGHTNING_DURATION * 0.8f)
				fLightningDelta = (m_fLightningTimeRemain - LIGHTNING_DURATION * 0.8f) / (LIGHTNING_DURATION * 0.2f);
			else
				fLightningDelta = m_fLightningTimeRemain / (LIGHTNING_DURATION * 0.8f);

			pLight->m_Data.Diffuse.r += (1.0f - pLight->m_Data.Diffuse.r) * fLightningDelta * 0.4f;
			pLight->m_Data.Diffuse.g += (1.0f - pLight->m_Data.Diffuse.g) * fLightningDelta * 0.5f;
			pLight->m_Data.Diffuse.b += (1.0f - pLight->m_Data.Diffuse.b) * fLightningDelta;

			m_fLightningTimeRemain -= CN3Base::s_fSecPerFrm;
			if(m_fLightningTimeRemain < 0) m_fLightningTimeRemain = 0;
		}

		pLight->Tick();
	}
	*/
	if(m_pRefLightSun)
	{
		// 해와 방향을 맞춘다..
		__Matrix44 mtxRot; mtxRot.RotationZ(fSunRadianZ);
		__Vector3 vDir(-1,0,1);
		vDir *= mtxRot;
		vDir.Normalize();
		m_pRefLightSun->m_Data.Direction = vDir;
		
		// 라이트 컬러 적용..
		m_pRefLightSun->m_Data.Diffuse = ::_D3DCOLOR_To_D3DCOLORVALUE(crDiffuses[0]);
		m_pRefLightSun->m_Data.Ambient = ::_D3DCOLOR_To_D3DCOLORVALUE(crAmbients[0]);

		// 번개 처리..
		if(m_fLightningTimeRemain > 0)
		{
			float fLightningDelta = 0;

			if(m_fLightningTimeRemain > LIGHTNING_DURATION * 0.8f)
				fLightningDelta = (m_fLightningTimeRemain - LIGHTNING_DURATION * 0.8f) / (LIGHTNING_DURATION * 0.2f);
			else
				fLightningDelta = m_fLightningTimeRemain / (LIGHTNING_DURATION * 0.8f);

			m_pRefLightSun->m_Data.Diffuse.r += (1.0f - m_pRefLightSun->m_Data.Diffuse.r) * fLightningDelta * 0.4f;
			m_pRefLightSun->m_Data.Diffuse.g += (1.0f - m_pRefLightSun->m_Data.Diffuse.g) * fLightningDelta * 0.5f;
			m_pRefLightSun->m_Data.Diffuse.b += (1.0f - m_pRefLightSun->m_Data.Diffuse.b) * fLightningDelta;

			m_fLightningTimeRemain -= CN3Base::s_fSecPerFrm;
			if(m_fLightningTimeRemain < 0) m_fLightningTimeRemain = 0;
		}
	}
	if(m_pRefLightSupport)
	{
		__Vector3 vDir(2,-3, 2); // 위에서 아래로 ...
		vDir.Normalize();
		m_pRefLightSupport->m_Data.Direction = vDir;
		
		// 라이트 컬러 적용..
		m_pRefLightSupport->m_Data.Diffuse = ::_D3DCOLOR_To_D3DCOLORVALUE(crDiffuses[1]);
		m_pRefLightSupport->m_Data.Ambient = ::_D3DCOLOR_To_D3DCOLORVALUE(crAmbients[1]);

		// 번개 처리..
		if(m_fLightningTimeRemain > 0)
		{
			float fLightningDelta = 0;

			if(m_fLightningTimeRemain > LIGHTNING_DURATION * 0.8f)
				fLightningDelta = (m_fLightningTimeRemain - LIGHTNING_DURATION * 0.8f) / (LIGHTNING_DURATION * 0.2f);
			else
				fLightningDelta = m_fLightningTimeRemain / (LIGHTNING_DURATION * 0.8f);

			m_pRefLightSupport->m_Data.Diffuse.r += (1.0f - m_pRefLightSupport->m_Data.Diffuse.r) * fLightningDelta * 0.4f;
			m_pRefLightSupport->m_Data.Diffuse.g += (1.0f - m_pRefLightSupport->m_Data.Diffuse.g) * fLightningDelta * 0.5f;
			m_pRefLightSupport->m_Data.Diffuse.b += (1.0f - m_pRefLightSupport->m_Data.Diffuse.b) * fLightningDelta;

			m_fLightningTimeRemain -= CN3Base::s_fSecPerFrm;
			if(m_fLightningTimeRemain < 0) m_fLightningTimeRemain = 0;
		}
	}
	if(m_pRefLightCam)
	{
		__Vector3 vPos = s_CameraData.vEye;
		vPos.y += 16.0f;
		m_pRefLightCam->PosSet(vPos); // 카메라 위에 가게 한다..
		
		// 라이트 컬러 적용..
		m_pRefLightCam->m_Data.Diffuse = ::_D3DCOLOR_To_D3DCOLORVALUE(crDiffuses[2]);
		m_pRefLightCam->m_Data.Ambient = ::_D3DCOLOR_To_D3DCOLORVALUE(crAmbients[2]);

		// 번개 처리..
		if(m_fLightningTimeRemain > 0)
		{
			float fLightningDelta = 0;

			if(m_fLightningTimeRemain > LIGHTNING_DURATION * 0.8f)
				fLightningDelta = (m_fLightningTimeRemain - LIGHTNING_DURATION * 0.8f) / (LIGHTNING_DURATION * 0.2f);
			else
				fLightningDelta = m_fLightningTimeRemain / (LIGHTNING_DURATION * 0.8f);

			m_pRefLightCam->m_Data.Diffuse.r += (1.0f - m_pRefLightCam->m_Data.Diffuse.r) * fLightningDelta * 0.4f;
			m_pRefLightCam->m_Data.Diffuse.g += (1.0f - m_pRefLightCam->m_Data.Diffuse.g) * fLightningDelta * 0.5f;
			m_pRefLightCam->m_Data.Diffuse.b += (1.0f - m_pRefLightCam->m_Data.Diffuse.b) * fLightningDelta;

			m_fLightningTimeRemain -= CN3Base::s_fSecPerFrm;
			if(m_fLightningTimeRemain < 0) m_fLightningTimeRemain = 0;
		}
	}
}