Example #1
0
void cPVCamera::Update(float afFrameTime)
{
	if(mpGame->GetInput()->IsTriggerd("Escape"))
	{
		mpGame->Exit();
	}

	/*float fMul = mpGame->GetStepSize();

	if(mpGame->GetInput()->IsTriggerd("Forward")) mpCamera->MoveForward(mfSpeed * fMul);
	if(mpGame->GetInput()->IsTriggerd("Backward")) mpCamera->MoveForward(-mfSpeed* fMul);
	if(mpGame->GetInput()->IsTriggerd("Right")) mpCamera->MoveRight(mfSpeed * fMul);
	if(mpGame->GetInput()->IsTriggerd("Left")) mpCamera->MoveRight(-mfSpeed * fMul);

	cVector2f vRel = mpGame->GetInput()->GetMouse()->GetRelPosition();
	mpCamera->AddYaw(-vRel.x * 0.003f);
	mpCamera->AddPitch(-vRel.y * 0.003f);*/

	cVector2f vRel = mpGame->GetInput()->GetMouse()->GetRelPosition();

	if(mpGame->GetInput()->IsTriggerd("Rotate"))
	{
		mvAngle += cVector3f(-vRel.y*0.005f,-vRel.x*0.005f,0);

		float fMaxAngle = kPi2f - 0.01f;
		if(mvAngle.x> fMaxAngle  ) mvAngle.x=fMaxAngle;
		if(mvAngle.x< -fMaxAngle ) mvAngle.x=-fMaxAngle;
	}
	else if(mpGame->GetInput()->IsTriggerd("Zoom"))
	{
		mvStartPos.z += vRel.y*0.12f;
		if(mvStartPos.z<mfMinDist)mvStartPos.z=mfMinDist;
		if(mvStartPos.z>mfMaxDist)mvStartPos.z=mfMaxDist;
	}

	CalculateCameraPos();
}
Example #2
0
void cPreMenu::OnDraw()
{
	//////////////////////////////////
	// STATE 1 (TEXT)
	if(mlState == 0 || mlState == 3 || mlState == 5)
	{
		int lPrevStart=0;
		int lCharCount =0;
		for(size_t i=0; i < mvTextRows.size(); ++i)
		{
			lPrevStart = lCharCount;
			lCharCount += (int)mvTextRows[i].length();
			if(lCharCount >= mlCurrentTextChar)
			{
				tWString sText = mvTextRows[i].substr(0,mlCurrentTextChar - lPrevStart);
				mpTextFont->Draw(cVector3f(25,90+19*(float)i,10)+mvecLastTextPos,17+mfLastTextSize,cColor(mfLastTextColor,mfFontColor,mfFontColor,1),//cColor(0.7f,1,0.7f,1),
									eFontAlign_Left,sText.c_str());
				if (mlState == 5)
				{
					// First pair of shadow texts
					mpTextFont->Draw(cVector3f(25 + mfLastTextSpeed1,90+19*(float)i,0)+mvecLastTextPos,17+(mfLastTextSize),cColor(mfLastTextColor+0.5f,0,0,0.25f),//cColor(0.7f,1,0.7f,1),
									eFontAlign_Left,sText.c_str());
					mpTextFont->Draw(cVector3f(25 + 1.5f*mfLastTextSpeed1,90+19*(float)i,0)+mvecLastTextPos,17+(mfLastTextSize),cColor(mfLastTextColor+0.5f,0,0,0.20f),//cColor(0.7f,1,0.7f,1),
									eFontAlign_Left,sText.c_str());
					// Second pair
					mpTextFont->Draw(cVector3f(25 + 3*mfLastTextSpeed1,90+19*(float)i,0)+mvecLastTextPos,17+(mfLastTextSize),cColor(mfLastTextColor+0.25f,0,0,0.15f),//cColor(0.7f,1,0.7f,1),
									eFontAlign_Left,sText.c_str());
					mpTextFont->Draw(cVector3f(25 + 5*mfLastTextSpeed1,90+19*(float)i,0)+mvecLastTextPos,17+(mfLastTextSize),cColor(mfLastTextColor+0.25f,0,0,0.1f),//cColor(0.7f,1,0.7f,1),
									eFontAlign_Left,sText.c_str());
					
					//mpTextFont->Draw(cVector3f(25-mfLastTextPos,90+19*(float)i-mfLastTextPos,0),cVector2f(17,17+(mfLastTextSize)),cColor(mfLastTextColor,mfFontColor,mfFontColor,0.25f),//cColor(0.7f,1,0.7f,1),
					//				eFontAlign_Left,sText.c_str());
				}
								
				break;
			}
			else
			{
				mpTextFont->Draw(cVector3f(25,90+19*(float)i,10),17,cColor(mfFontColor,mfFontColor),//cColor(0.7f,1,0.7f,1),
								eFontAlign_Left,mvTextRows[i].c_str());
			}
		}
	}
}
void cGraphicsDrawer::DrawAll()
{
    //Set all states
    mpLowLevelGraphics->SetDepthTestActive(false);
    mpLowLevelGraphics->SetIdentityMatrix(eMatrix_ModelView);

    mpLowLevelGraphics->SetOrthoProjection(mpLowLevelGraphics->GetVirtualSize(),-1000,1000);

    int lIdxAdd=0;
    iMaterial *pPrevMat=NULL;
    iMaterial *pMat =NULL;
    const cGfxBufferObject* pObj=NULL;
    tGfxBufferSetIt ObjectIt = m_setGfxBuffer.begin();

    if(ObjectIt != m_setGfxBuffer.end())
        pMat = ObjectIt->GetMaterial();

    while(ObjectIt != m_setGfxBuffer.end())
        {
            if(pMat->StartRendering(eMaterialRenderType_Diffuse,NULL,NULL)==false)
                {
                    ObjectIt++;
                    if(ObjectIt != m_setGfxBuffer.end())pMat = ObjectIt->GetMaterial();

                    continue;
                }

            do
                {
                    pObj = &(*ObjectIt);
                    if(pObj->mbIsColorAndSize)
                        {
                            cVector3f vPos[4];
                            float fW = pObj->mvSize.x*0.5f;
                            float fH = pObj->mvSize.y*0.5f;
                            cMatrixf mtxTrans = cMath::MatrixTranslate(pObj->mvTransform + cVector3f(fW,fH,0));
                            vPos[0] = cVector3f(-fW,-fH,0);
                            vPos[1] = cVector3f(fW,-fH,0);
                            vPos[2] = cVector3f(fW,fH,0);
                            vPos[3] = cVector3f(-fW,fH,0);

                            if (pObj->mfAngle != 0)
                                {
                                    cMatrixf mtxRot = cMath::MatrixRotateZ(pObj->mfAngle);
                                    vPos[0] = cMath::MatrixMul(mtxRot,vPos[0]);
                                    vPos[1] = cMath::MatrixMul(mtxRot,vPos[1]);
                                    vPos[2] = cMath::MatrixMul(mtxRot,vPos[2]);
                                    vPos[3] = cMath::MatrixMul(mtxRot,vPos[3]);
                                }

                            vPos[0] = cMath::MatrixMul(mtxTrans,vPos[0]);
                            vPos[1] = cMath::MatrixMul(mtxTrans,vPos[1]);
                            vPos[2] = cMath::MatrixMul(mtxTrans,vPos[2]);
                            vPos[3] = cMath::MatrixMul(mtxTrans,vPos[3]);

                            if(pObj->mbFlipH)
                                {
                                    mpLowLevelGraphics->AddVertexToBatch_Size2D(pObj->mpObject->GetVtxPtr(0),
                                            &vPos[0],
                                            &pObj->mColor,
                                            0,0);
                                    mpLowLevelGraphics->AddVertexToBatch_Size2D(pObj->mpObject->GetVtxPtr(1),
                                            &vPos[1],
                                            &pObj->mColor,
                                            0,0);
                                    mpLowLevelGraphics->AddVertexToBatch_Size2D(pObj->mpObject->GetVtxPtr(2),
                                            &vPos[2],
                                            &pObj->mColor,
                                            0,0);
                                    mpLowLevelGraphics->AddVertexToBatch_Size2D(pObj->mpObject->GetVtxPtr(3),
                                            &vPos[3],
                                            &pObj->mColor,
                                            pObj->mvSize.x,pObj->mvSize.y);
                                }
                            else
                                {
                                    mpLowLevelGraphics->AddVertexToBatch_Size2D(pObj->mpObject->GetVtxPtr(0),
                                            &vPos[0],
                                            &pObj->mColor,
                                            0,0);
                                    mpLowLevelGraphics->AddVertexToBatch_Size2D(pObj->mpObject->GetVtxPtr(1),
                                            &vPos[1],
                                            &pObj->mColor,
                                            0,0);
                                    mpLowLevelGraphics->AddVertexToBatch_Size2D(pObj->mpObject->GetVtxPtr(2),
                                            &vPos[2],
                                            &pObj->mColor,
                                            0,0);
                                    mpLowLevelGraphics->AddVertexToBatch_Size2D(pObj->mpObject->GetVtxPtr(3),
                                            &vPos[3],
                                            &pObj->mColor,
                                            0,0);
                                }

                            for(int i=0; i<4; i++)
                                mpLowLevelGraphics->AddIndexToBatch(lIdxAdd + i);
                        }
                    else
                        {
                            for(int i=0; i<(int)pObj->mpObject->GetVertexVec()->size(); i++)
                                {
                                    mpLowLevelGraphics->AddVertexToBatch(pObj->mpObject->GetVtxPtr(i),
                                                                         &pObj->mvTransform);
                                    mpLowLevelGraphics->AddIndexToBatch(lIdxAdd + i);
                                }
                        }
                    lIdxAdd+=(int)pObj->mpObject->GetVertexVec()->size();

                    pPrevMat = pMat;
                    ObjectIt++;

                    if(ObjectIt == m_setGfxBuffer.end())
                        {
                            pMat=NULL;
                            break;
                        }
                    else
                        {
                            pMat = ObjectIt->GetMaterial();
                        }
                }
            while(	pMat->GetType(eMaterialRenderType_Diffuse) ==
                    pPrevMat->GetType(eMaterialRenderType_Diffuse)
                    &&
                    pMat->GetTexture(eMaterialTexture_Diffuse) ==
                    pPrevMat->GetTexture(eMaterialTexture_Diffuse)
                 );

            lIdxAdd =0;

            do
                {
                    mpLowLevelGraphics->FlushQuadBatch(pPrevMat->GetBatchFlags(eMaterialRenderType_Diffuse),false);
                }
            while(pPrevMat->NextPass(eMaterialRenderType_Diffuse));

            mpLowLevelGraphics->ClearBatch();

            pPrevMat->EndRendering(eMaterialRenderType_Diffuse);
        }

    //Clear the buffer of objects.
    m_setGfxBuffer.clear();

    //Reset all states
    mpLowLevelGraphics->SetDepthTestActive(true);
}
Example #4
0
    mpGame->GetInput()->AddAction(new cActionKeyboard("Forward",mpGame->GetInput(),eKey_w));
    mpGame->GetInput()->AddAction(new cActionKeyboard("Backward",mpGame->GetInput(),eKey_s));
    mpGame->GetInput()->AddAction(new cActionKeyboard("Right",mpGame->GetInput(),eKey_d));
    mpGame->GetInput()->AddAction(new cActionKeyboard("Left",mpGame->GetInput(),eKey_a));
    mpGame->GetInput()->AddAction(new cActionKeyboard("Gravity",mpGame->GetInput(),eKey_g));

    mpGame->GetInput()->GetLowLevel()->LockInput(true);

    mpCamera = mpGame->GetScene()->CreateCamera3D(eCameraMoveMode_Fly);
    mpGame->GetScene()->SetCamera(mpCamera);
    mpCamera->SetPosition(avStartPos);
    //mpCamera->SetFarClipPlane(1000);

    mpCharBody = mpGame->GetScene()->GetWorld3D()->GetPhysicsWorld()->CreateCharacterBody("Test",
                 cVector3f(0.6f,1.6f,0.6f));
    mpCharBody->SetPosition(cVector3f(0,mpCharBody->GetSize().y/2 + 0.1f,0));

    mpCharBody->SetCamera(mpCamera);
    mpCharBody->SetCameraPosAdd(cVector3f(0,-0.15f,0));

    mpCharBody->SetMaxPositiveMoveSpeed(eCharDir_Forward,4.0f);
    mpCharBody->SetMaxNegativeMoveSpeed(eCharDir_Forward,-4.0f);

    mpCharBody->SetMaxPositiveMoveSpeed(eCharDir_Right,4.0f);
    mpCharBody->SetMaxNegativeMoveSpeed(eCharDir_Right,-4.0f);

    mpCharBody->SetMoveAcc(eCharDir_Forward,12.0f);
    mpCharBody->SetMoveDeacc(eCharDir_Forward,8.0f);
    mpCharBody->SetMoveAcc(eCharDir_Right,12.0f);
    mpCharBody->SetMoveDeacc(eCharDir_Right,12.0f);
Example #5
0
	void iWidget::DrawBordersAndCorners(cGuiGfxElement *apBackground,
										cGuiGfxElement **apBorderVec,cGuiGfxElement **apCornerVec,
										const cVector3f &avPosition, const cVector2f &avSize)
	{
		mpSet->SetDrawOffset(avPosition);

		///////////////////////
		// Background
		if(apBackground)
		{

			mpSet->DrawGfx(apBackground,cVector3f(	apCornerVec[0]->GetActiveSize().x,
												apCornerVec[0]->GetActiveSize().y,0 ),
							avSize - apCornerVec[2]->GetActiveSize()-apCornerVec[0]->GetActiveSize(),
							cColor(1,1));
		}



		///////////////////////
		// Borders
		//Right
		mpSet->DrawGfx(	apBorderVec[0],
			cVector3f(	avSize.x - apBorderVec[0]->GetActiveSize().x,
			apCornerVec[1]->GetActiveSize().y,0),
			cVector2f(	apBorderVec[0]->GetImageSize().x, 
			avSize.y - (apCornerVec[2]->GetActiveSize().y +
			apCornerVec[1]->GetActiveSize().y)));
		//Left
		mpSet->DrawGfx(	apBorderVec[1],
			cVector3f(	0,apCornerVec[0]->GetActiveSize().y,0),
			cVector2f(	apBorderVec[1]->GetImageSize().x, 
			avSize.y - (apCornerVec[3]->GetActiveSize().y + 
			apCornerVec[0]->GetActiveSize().y)));

		//Up
		mpSet->DrawGfx(	apBorderVec[2],
			cVector3f(	apCornerVec[0]->GetActiveSize().x,0,0),
			cVector2f(	avSize.x - (apCornerVec[0]->GetActiveSize().x+
			apCornerVec[1]->GetActiveSize().x), 
			apBorderVec[2]->GetImageSize().y));

		//Down
		mpSet->DrawGfx(	apBorderVec[3],
			cVector3f(	apCornerVec[3]->GetActiveSize().x, 
			avSize.y - apBorderVec[3]->GetActiveSize().y,0),
			cVector2f(	avSize.x - (apCornerVec[2]->GetActiveSize().x+
			apCornerVec[3]->GetActiveSize().x), 
			apBorderVec[3]->GetImageSize().y));


		///////////////////////
		// Corners
		//Left Up
		mpSet->DrawGfx(apCornerVec[0], cVector3f(0,0,0));
		//Right Up
		mpSet->DrawGfx(apCornerVec[1], cVector3f(	avSize.x - apCornerVec[1]->GetActiveSize().x,0,0));

		//Right Down
		mpSet->DrawGfx(apCornerVec[2], cVector3f(	avSize.x -  apCornerVec[2]->GetActiveSize().x,
			avSize.y -  apCornerVec[2]->GetActiveSize().y,0));
		//Left Down
		mpSet->DrawGfx(apCornerVec[3], cVector3f(	0,avSize.y - apCornerVec[3]->GetActiveSize().y,0));


		mpSet->SetDrawOffset(0);
	}
Example #6
0
	void cPhysicsBodyNewton::ClearForces()
	{
		m_vTotalForce = cVector3f(0,0,0);
		m_vTotalTorque = cVector3f(0,0,0);
	}
Example #7
0
    void cCylinder::Build()
    {                               // surface_QUADS + bound1_TRI + bound2_TRI
        unsigned int numVertices = 4 * mNrMesh + 3 * mNrMesh + 3 * mNrMesh;
        unsigned int numIndices = 6 * mNrMesh + 3 * mNrMesh + 3 * mNrMesh;

        mpSolidVertexBuffer->Clear();

        mpSolidVertexBuffer->ReserveVertices(numVertices);
        mpSolidVertexBuffer->ReserveIndices(numIndices);

        float dth = 0;
        if (mNrMesh != 0)
            dth = 2 * PI / mNrMesh;
        unsigned int ind = 0;

        tVertexVec rect;
        rect.resize(4);

        tVertexVec triangle;
        triangle.resize(3);

        // surface

        float th = 0;
        int n = 0;

        while (n < mNrMesh)
        {
            float vtx = mRadius*cos(th);
            float vty = mRadius*sin(th);

            float vdx = mRadius*cos(th+dth);
            float vdy = mRadius*sin(th+dth);

            float l = mLength;

                                                     // GetSurfaceNormal(p)
            rect[0] = cVertex( cVector3f(vtx,vty,0), cVector3f(vtx,vty,0), mColor );
            rect[1] = cVertex( cVector3f(vdx,vdy,0), cVector3f(vdx,vdy,0), mColor );
            rect[2] = cVertex( cVector3f(vdx,vdy,l), cVector3f(vdx,vdy,0), mColor );
            rect[3] = cVertex( cVector3f(vtx,vty,l), cVector3f(vtx,vty,0), mColor );

            for (int i = 0; i < 4; i++)
                rect[i].nor.Normalize();

            AddTriangle(rect[0], rect[1], rect[2]);
            AddTriangle(rect[0], rect[2], rect[3]);

            for (int i = 0; i < 6; i++)
                mpSolidVertexBuffer->AddIndex(ind++);

            n++;
            th = th + dth;
        }

        // bound (z = 0)

        th = 0;
        n = 0;

        while (n < mNrMesh)
        {
            float vtx = mRadius*cos(th);
            float vty = mRadius*sin(th);

            float vdx = mRadius*cos(th+dth);
            float vdy = mRadius*sin(th+dth);

            triangle[0] = cVertex( cVector3f(0,0,0),     cVector3f(0,0,-1), mColor );
            triangle[1] = cVertex( cVector3f(vdx,vdy,0), cVector3f(0,0,-1), mColor );
            triangle[2] = cVertex( cVector3f(vtx,vty,0), cVector3f(0,0,-1), mColor );

            for (int i = 0; i < 3; i++)
                triangle[i].nor.Normalize();

            AddTriangle(triangle[0], triangle[1], triangle[2]);

            for (int i = 0; i < 3; i++)
                mpSolidVertexBuffer->AddIndex(ind++);

            n++;
            th = th + dth;
        }

        // bound (z = L)

        th = 0;
        n = 0;

        while (n < mNrMesh)
        {
            float vtx = mRadius*cos(th);
            float vty = mRadius*sin(th);

            float vdx = mRadius*cos(th+dth);
            float vdy = mRadius*sin(th+dth);

            float l = mLength;

            triangle[0] = cVertex( cVector3f(0,0,l),     cVector3f(0,0,1), mColor );
            triangle[1] = cVertex( cVector3f(vtx,vty,l), cVector3f(0,0,1), mColor );
            triangle[2] = cVertex( cVector3f(vdx,vdy,l), cVector3f(0,0,1), mColor );

            for (int i = 0; i < 3; i++)
                triangle[i].nor.Normalize();

            AddTriangle(triangle[0], triangle[1], triangle[2]);

            for (int i = 0; i < 3; i++)
                mpSolidVertexBuffer->AddIndex(ind++);

            n++;
            th = th + dth;
        }

        rect.clear();
        triangle.clear();

        // bounding volume

        mBoundingVolume.SetSize(cVector3f(-mRadius,-mRadius,0),
            cVector3f(mRadius,mRadius,mLength));

        mvSize.x = mRadius;
        mvSize.y = mRadius;
        mvSize.z = mLength;

        mpSolidVertexBuffer->RemoveDuplicateVertices();
    }
Example #8
0
cVector3f cGameLadder::GetStartRotation()
{
	iCharacterBody *pCharBody = mpInit->mpPlayer->GetCharacterBody();

	return cMath::GetAngleFromPoints3D(cVector3f(0,0,0), GetForward()*-1);
}
	cVector3f cPhysicsJointScrewNewton::GetAngularVelocity()
	{
		return cVector3f(0,0,0);
	}
Example #10
0
void cPreMenu::Update(float afTimeStep)
{

	mfStateTimer += afTimeStep;

	// Update wind sound fading
	if (mbFadeWindSound)
	{
		cSoundEntry* pEntry = mpInit->mpGame->GetSound()->GetSoundHandler()->GetEntryFromSound(mpWindSound);
		if (pEntry)
		{
			if (pEntry->mfNormalVolumeFadeSpeed > 0)
			{
				if (pEntry->mfNormalVolume < pEntry->mfNormalVolumeFadeDest)
				{
					pEntry->mfNormalVolume += pEntry->mfNormalVolumeFadeSpeed * afTimeStep;
					//hpl::Log ("Vol:%f\n",pEntry->mfNormalVolume);
				}
				else
				{
					pEntry->mfNormalVolume = pEntry->mfNormalVolumeFadeDest;
					mbFadeWindSound = false;
				}

			}
			else if (pEntry->mfNormalVolumeFadeSpeed < 0)
			{
				if (pEntry->mfNormalVolume > pEntry->mfNormalVolumeFadeDest)
				{
					pEntry->mfNormalVolume += pEntry->mfNormalVolumeFadeSpeed * afTimeStep;
					//hpl::Log ("Vol:%f\n",pEntry->mfNormalVolume);
				}
				else
				{
					pEntry->mfNormalVolume = pEntry->mfNormalVolumeFadeDest;
					mbFadeWindSound = false;
				}
			}
			else
				mbFadeWindSound = false;
		}
	}

    // Update rain sound fading
	if (mbFadeRainSound)
	{
		cSoundEntry* pEntry = mpInit->mpGame->GetSound()->GetSoundHandler()->GetEntryFromSound(mpRainSound);
		if (pEntry)
		{
			if (pEntry->mfNormalVolumeFadeSpeed > 0)
			{
				if (pEntry->mfNormalVolume < pEntry->mfNormalVolumeFadeDest)
				{
					pEntry->mfNormalVolume += pEntry->mfNormalVolumeFadeSpeed * afTimeStep;
					//hpl::Log ("Vol:%f\n",pEntry->mfNormalVolume);
				}
				else
				{
					pEntry->mfNormalVolume = pEntry->mfNormalVolumeFadeDest;
					mbFadeRainSound = false;
				}

			}
			else if (pEntry->mfNormalVolumeFadeSpeed < 0)
			{
				if (pEntry->mfNormalVolume > pEntry->mfNormalVolumeFadeDest)
				{
					pEntry->mfNormalVolume += pEntry->mfNormalVolumeFadeSpeed * afTimeStep;
					//hpl::Log ("Vol:%f\n",pEntry->mfNormalVolume);
				}
				else
				{
					pEntry->mfNormalVolume = pEntry->mfNormalVolumeFadeDest;
					mbFadeRainSound = false;
				}
			}
			else
				mbFadeRainSound = false;
            
			mfRaindropFade = mpRainSound->GetVolume();
		}
		else
		{
			mfRaindropFade = 1;
			mbFadeRainSound = false;
		}
	}

    // Update raindrops
	for ( int i = 0; i < (int)mvRaindropVector.size(); ++i )
	{
		cRaindrop *pRaindrop = &(mvRaindropVector[i]);
		pRaindrop->vPos += pRaindrop->vDir * (1.75f*pRaindrop->fLength);
		pRaindrop->vPos.x += cMath::RandRectf(0,0.05f);
			
		if (pRaindrop->vPos.y > 600)
		{
			pRaindrop->vPos = cVector2f(cMath::RandRectf(-60,800),-80);
			pRaindrop->vDir = cVector2f(cMath::RandRectf(20,100), 600);
			pRaindrop->vDir.Normalise();
			pRaindrop->fLength = cMath::RandRectf(30,70);
			pRaindrop->fColor = cMath::RandRectf(0.5f,1) * mfRaindropFade;
		}
	}


	
	
	//////////////////////////////////
	// STATE 0 (Premenu Text)
	if(mlState ==0)
	{
		if(mbShowText==false)
		{
			mlState = 1;
			mfStateTimer = 0;
			return;
		}
		if (mpWindSound == NULL)
			mpWindSound = mpInit->mpGame->GetSound()->GetSoundHandler()->PlayGui("gui_wind1",true,0);
		
		if ( mpWindSound  && !mbPlayingWindSound )
		{
			cSoundEntry* pEntry = mpInit->mpGame->GetSound()->GetSoundHandler()->GetEntryFromSound(mpWindSound);
			if (pEntry)
			{
				pEntry->mfNormalVolumeFadeDest = 1;
				pEntry->mfNormalVolumeFadeSpeed = 0.2f;
				mbFadeWindSound = true;
			}
			mbPlayingWindSound = true;
		}

		if(mlCurrentTextChar < mlMaxChars)
		{
			mfNewCharCount -= afTimeStep;
			mfClickCount  -=afTimeStep;

			if(mfNewCharCount <=0)
			{
				if(mfClickCount <=0)
				{
					mpInit->mpGame->GetSound()->GetSoundHandler()->PlayGui("gui_type",false,1);
					mfClickCount = (1.0f / 8.0f) + cMath::RandRectf(-0.05f,0.05f);
				}

				mlCurrentTextChar++;
				mfNewCharCount =1.0f / 19.0f;

				if(mlCurrentTextChar == mlMaxChars) 
				{
					mlState = 3;
					mfStateTimer = 0;
				}

				int lCharCount =0;
				for(size_t i=0; i < mvTextRows.size(); ++i)
				{
					lCharCount += (int)mvTextRows[i].length();
					if(lCharCount == mlCurrentTextChar)
					{
						if(i+1 < mvTextRows.size() && mvTextRows[i+1].size()==0){
							mfNewCharCount = 1.0f;
						}
					}
					else if(lCharCount > mlCurrentTextChar)
					{
						break;
					}
				}	
			}
		}
	}
	/////////////////////
	// STATE 1 (Logos)
	else if (mlState == 1) 
	{
		if ( mpRainSound == NULL )
			mpRainSound = mpInit->mpGame->GetSound()->GetSoundHandler()->PlayGui("gui_rain1",true,0);

        if ( mpWindSound && mbPlayingWindSound )
		{
			cSoundEntry* pEntry = mpInit->mpGame->GetSound()->GetSoundHandler()->GetEntryFromSound(mpWindSound);
			if (pEntry)
			{
				pEntry->mfNormalVolumeFadeDest = 0;
				pEntry->mfNormalVolumeFadeSpeed = -0.5f;
				mbFadeWindSound = true;
			}
			mbPlayingWindSound = false;
		}
		if (mpRainSound && !mbPlayingRainSound)
		{
			cSoundEntry* pEntry = mpInit->mpGame->GetSound()->GetSoundHandler()->GetEntryFromSound(mpRainSound);
			if (pEntry)
			{
				pEntry->mfNormalVolumeFadeDest = 1;
				pEntry->mfNormalVolumeFadeSpeed = 0.2f;
				mbFadeRainSound = true;
			}
			mbPlayingRainSound = true;
		}
		

		if (!mbPlayingMusic)
		{
			mpInit->mpGame->GetSound()->GetMusicHandler()->Play("music_theme.ogg",1,0,false);
			mbPlayingMusic = true;
		}

		mfAlpha += afTimeStep*mfAlphaAdd;

		if(mfAlphaAdd >0)
		{
			if(mfAlpha >1){
				mfAlpha = 1;
				mfAlphaAdd = -mfAlphaAdd;
			}
		}
		else
		{
			if(mfAlpha <0)
			{
				mfAlpha =0;
				mfAlphaAdd = -mfAlphaAdd;

				mlCurrentLogo++;
				if(mlCurrentLogo >= (int) mvTextures.size())
				{
					mlState=4;
					mfStateTimer = 0;
				}
			}
		}
	}
	//////////////////////////////////
	// STATE 2 (FAST FADE LOGO)
	else if(mlState ==2)
	{
		mfAlpha -= cMath::Abs(mfAlphaAdd) * afTimeStep;
		if(mfAlpha<=0)
		{
			mfStateTimer = 0;
			mlState=1;
			mlCurrentLogo++;
			if (mlCurrentLogo >= (int) mvTextures.size())
				mlState = 4;
		}
	}
	//////////////////////////////////
	// STATE 3 (Text Pause)
	else if(mlState ==3)
	{
		if ( mpWindSound && mbPlayingWindSound )
		{
			cSoundEntry* pEntry = mpInit->mpGame->GetSound()->GetSoundHandler()->GetEntryFromSound(mpWindSound);
			if (pEntry)
			{
				//pEntry->mfNormalVolumeMul= 0;
				pEntry->mfNormalVolumeFadeDest = 0;
				pEntry->mfNormalVolumeFadeSpeed = -0.2f;
				//mpWindSound->Stop();
				mbFadeWindSound = true;
			}
			mbPlayingWindSound = false;
		}

		mlCurrentTextChar = mlMaxChars;
		mfNewCharCount += afTimeStep;

		if (mfStateTimer > 1)
		{
			mlState = 5;
			mfStateTimer = 0;
		}
		
	}
	///////////////////
	// STATE 5 (Text Vanishing)
	else if(mlState ==5)
	{
		mlCurrentTextChar = mlMaxChars;
		
		if ( mpWindSound && mbPlayingWindSound ) 
		{
			cSoundEntry* pEntry = mpInit->mpGame->GetSound()->GetSoundHandler()->GetEntryFromSound(mpWindSound);
			if (pEntry)
			{
				pEntry->mfNormalVolumeFadeDest = 0;
				pEntry->mfNormalVolumeFadeSpeed	= -0.1f;
			}
			mbFadeWindSound = true;
			mbPlayingWindSound = false;
		}

		mfFontColor -= afTimeStep;
		mvecLastTextPos +=  cVector2f(10*afTimeStep, -2.5f*afTimeStep);
		mfLastTextSize += 1.05f * afTimeStep;
		mfLastTextSpeed1 += 4 * afTimeStep;
		mfLastTextSpeed2 += 8 * afTimeStep;
		mfLastTextColor -= 0.5f * afTimeStep;
		
		if (mfStateTimer > 0.5f)
		{
			if (!mbPlayingMusic) 
			{
				mpInit->mpGame->GetSound()->GetMusicHandler()->Play("music_theme.ogg",1,0,false);
				mbPlayingMusic = true;
			}
		}

		if (mfStateTimer > 3.5f)
		{
			mlState = 1;
            mfStateTimer = 0;
		}

	}
	/////////////////////////////////
	// STATE 4 (PENUMBRA TITLES)
	else if(mlState == 4)
	{
		if (!mbPlayingThunderSound)
		{
			mpInit->mpGame->GetSound()->GetSoundHandler()->PlayGui("gui_thunder1",false,1);
			mbPlayingThunderSound = true;
		}

		if (mbFlash && mfStateTimer >= 0.2f)
			mbFlash = false;

		if (mfStateTimer >0.5f && mfStateTimer < 1.5f)
			if (mfEpFade <1) mfEpFade += afTimeStep;

		if (mfStateTimer < 1)
		{
			mfAdd = 0.2f * afTimeStep;
		}
		else if ( mfStateTimer < 1.5f )
		{
			mfAdd = 0.08f * afTimeStep;
		}
		else if ( mfStateTimer < 1.75f )
		{
			mfAdd = 0.05f *afTimeStep;
		}
		else if ( mfStateTimer >= 1.75f )
		{
            mfAdd = 0.03f *afTimeStep;
			
			mfLogoFade -= 0.25f*afTimeStep;
			mfEpFade = mfLogoFade;
		}

		mfLogoSizeFactor -= mfAdd;
		mvecLogoSize = cVector3f(1024,301,0) * mfLogoSizeFactor;

		if (mfStateTimer > 5)
		{
			if (mfRaindropFade > 0)
				mfRaindropFade -= afTimeStep;
			else
                SetActive(false);
		}
	}
}
Example #11
0
tFlag cCollider2D::CollideRect(cRect2f& aRect,tFlag alCollideFlags, cCollideData2D* apData)
{
    tFlag lCollision = eFlagBit_None;

    cRect2f CollideRect = aRect;

    cCollisionMesh2D* pCollMesh = hplNew( cCollisionMesh2D, () );
    pCollMesh->mvPos.resize(4);
    pCollMesh->mvNormal.resize(4);
    SetCollideMesh(pCollMesh, aRect);

    cVector2f vPushVector;
    cVector2f vLastPushVector;

    //// Check for all tiles if the flag is set
    if(alCollideFlags & eFlagBit_0)
        {
            float fTileSize = mpWorld->GetTileMap()->GetTileSize();
            cRect2f TileRect = cRect2f(0,0,fTileSize,fTileSize);

            for(int i=0; i<mpWorld->GetTileMap()->GetTileLayerNum(); i++)
                {
                    if(mpWorld->GetTileMap()->GetTileLayer(i)->HasCollision()==false)continue;

                    iTileMapIt *pTileIt = mpWorld->GetTileMap()->GetRectIterator(CollideRect,i);

                    while(pTileIt->HasNext())
                        {
                            cTile *pTile = pTileIt->Next();
                            TileRect.x = pTile->GetPosition().x-fTileSize/2;
                            TileRect.y = pTile->GetPosition().y-fTileSize/2;

                            if(pTile->GetCollisionMesh()==NULL)continue;

                            if(apData)apData->mlstTiles.push_back(cCollidedTile(pTile,i));

                            if(Collide(pCollMesh, pTile->GetCollisionMesh(), vPushVector) )
                                {
                                    cVector3f vD;
                                    vD = cVector3f(aRect.x, aRect.y,0) - pTile->GetPosition();
                                    if ( (vD.x*vPushVector.x + vD.y*vPushVector.y) < 0.0f)
                                        vPushVector = vPushVector * -1;

                                    cVector3f vPos;
                                    vPos.x = aRect.x;
                                    vPos.y = aRect.y;

                                    //reverse the latest push, maybe pos here instead?
                                    if(lCollision)
                                        {
                                            vPos -= vLastPushVector;
                                        }

                                    vPos += vPushVector;
                                    aRect.x = vPos.x;
                                    aRect.y = vPos.y;

                                    SetCollideMesh(pCollMesh, aRect);
                                    CollideRect = aRect;

                                    lCollision |= eFlagBit_0;
                                    vLastPushVector = vPushVector;
                                }
                        }

                    hplDelete(pTileIt);
                }
        }

    iGridMap2DIt* pBodyIt = mpWorld->GetGridMapBodies()->GetRectIterator(CollideRect);

    while(pBodyIt->HasNext())
        {
            cBody2D* pBody = static_cast<cBody2D*>(pBodyIt->Next());

            if(pBody->IsActive() && pBody->GetCollideType() & alCollideFlags)
                {
                    if(cMath::BoxCollision(CollideRect, pBody->GetBoundingBox()))
                        {
                            if(Collide(pCollMesh,pBody->GetCollisionMesh(), vPushVector))
                                {
                                    if(apData)apData->mlstBodies.push_back(pBody);

                                    lCollision |= pBody->GetCollideType();

                                    /*Perhaps fix the push vector here?*/
                                }
                        }
                }
        }

    hplDelete(pBodyIt);

    /// Do some stuff when colliding
    if(lCollision)
        {
            if(apData) apData->mvPushVec = vPushVector;
        }

    hplDelete(pCollMesh);

    return lCollision;
}
Example #12
0
void cBillboard::LoadXMLProperties(const tString asFile)
{
    tString sNewFile = cString::SetFileExt(asFile,"bnt");
    tString sPath = mpFileSearcher->GetFilePath(sNewFile);
    if(sPath != "")
        {
            TiXmlDocument *pDoc = hplNew( TiXmlDocument, (sPath.c_str()) );
            if(pDoc->LoadFile())
                {
                    TiXmlElement *pRootElem = pDoc->RootElement();

                    TiXmlElement *pMainElem = pRootElem->FirstChildElement("MAIN");
                    if(pMainElem!=NULL)
                        {
                            mType = ToType(pMainElem->Attribute("Type"));
                            tString sMaterial = cString::ToString(pMainElem->Attribute("Material"),"");
                            bool bUsesOffset = cString::ToBool(pMainElem->Attribute("UseOffset"),false);
                            if(bUsesOffset==false) mfForwardOffset =0;

                            /////////////////
                            //Halo stuff
                            bool bIsHalo = cString::ToBool(pMainElem->Attribute("IsHalo"),false);
                            SetIsHalo(bIsHalo);

                            if(bIsHalo)
                                {
                                    bool bHaloSourceIsParent  = cString::ToBool(pMainElem->Attribute("HaloSourceIsParent"),false);
                                    SetHaloSourceIsParent(bHaloSourceIsParent);

                                    if(bHaloSourceIsParent == false)
                                        {
                                            tString sSizeVec = cString::ToString(pMainElem->Attribute("HaloSourceSize"),"1 1 1");
                                            tFloatVec vSizeValues;
                                            cString::GetFloatVec(sSizeVec,vSizeValues,NULL);
                                            SetHaloSourceSize(cVector3f(vSizeValues[0],vSizeValues[1],vSizeValues[2]));
                                        }
                                }

                            /////////////////
                            //Load material
                            iMaterial *pMat = mpMaterialManager->CreateMaterial(sMaterial);
                            if(pMat)
                                {
                                    SetMaterial(pMat);
                                }
                            else
                                {
                                    Error("Couldn't load material '%s' in billboard file '%s'",
                                          sMaterial.c_str(), sNewFile.c_str());
                                }
                        }
                    else
                        {
                            Error("Cannot find main element in %s\n",sNewFile.c_str());
                        }
                }
            else
                {
                    Error("Couldn't load file '%s'\n",sNewFile.c_str());
                }
            hplDelete(pDoc);
        }
    else
        {
            Error("Couldn't find file '%s'\n",sNewFile.c_str());
        }

}
	cCollideShapeNewton::cCollideShapeNewton(eCollideShapeType aType, const cVector3f &avSize,
											cMatrixf* apOffsetMtx, NewtonWorld* apNewtonWorld,
											iPhysicsWorld *apWorld)
	: iCollideShape(apWorld)
	{
		mpNewtonCollision = NULL;
		mpNewtonWorld = apNewtonWorld;
		mvSize = avSize;
		mType = aType;

		mfVolume = 0;

		float *pMtx = NULL;
		cMatrixf mtxTranspose;
		if(apOffsetMtx)
		{
			m_mtxOffset = *apOffsetMtx;
			mtxTranspose = m_mtxOffset.GetTranspose();

			pMtx = &(mtxTranspose.m[0][0]);
		}
		else
			m_mtxOffset = cMatrixf::Identity;

		////////////////////////////////////////////
		// Create Newton collision

		switch(aType)
		{
		case eCollideShapeType_Null:		mpNewtonCollision = NewtonCreateNull(apNewtonWorld); break;

		case eCollideShapeType_Box:			mpNewtonCollision = NewtonCreateBox(apNewtonWorld,
												mvSize.x, mvSize.y, mvSize.z,
												pMtx); break;

		case eCollideShapeType_Sphere:		mpNewtonCollision = NewtonCreateSphere(apNewtonWorld,
												mvSize.x, mvSize.y, mvSize.z,
												pMtx); break;

		case eCollideShapeType_Cylinder:	mpNewtonCollision = NewtonCreateCylinder(apNewtonWorld,
												mvSize.x, mvSize.y,
												pMtx); break;

		case eCollideShapeType_Capsule:		mpNewtonCollision = NewtonCreateCapsule(apNewtonWorld,
												mvSize.x, mvSize.y,
												pMtx); break;
		}

		////////////////////////////////////////////
		// Calculate Bounding volume and volume.
		if(mType == eCollideShapeType_Box)
		{
			mBoundingVolume.SetSize(mvSize);

			mfVolume = mvSize.x * mvSize.y *mvSize.z;
		}
		else if(mType == eCollideShapeType_Sphere)
		{
			mBoundingVolume.SetSize(mvSize*2);

			mfVolume = (4.0f / 3.0f) * kPif * (mvSize.x*mvSize.x*mvSize.x);
		}
		else if(mType == eCollideShapeType_Cylinder ||
				mType == eCollideShapeType_Capsule)
		{
			mBoundingVolume.SetSize(cVector3f(mvSize.y,mvSize.x*2,mvSize.x*2));

			//Not gonna be correct for capsule...
			if(mType == eCollideShapeType_Cylinder)
				mfVolume = kPif * (mvSize.x*mvSize.x)*mvSize.y;
			else
			{
				//Height of the cylinder part.
				float fCylHeight = mvSize.y - (mvSize.x*2);
				mfVolume =0;

				//The volume of the cylinder part.
				if(fCylHeight>0)
					mfVolume += kPif * (mvSize.x*mvSize.x)*fCylHeight;

				//The volume of the sphere part.
				mfVolume += (4.0f / 3.0f) * kPif * (mvSize.x*mvSize.x*mvSize.x);
			}
		}

		mBoundingVolume.SetTransform(m_mtxOffset);
	}
Example #14
0
    void cBox::Build() // without mesh
    {
        unsigned int numVertices = 24;
        unsigned int numIndices = 36;

        mpSolidVertexBuffer->Clear();

        mpSolidVertexBuffer->ReserveVertices(numVertices);
        mpSolidVertexBuffer->ReserveIndices(numIndices);

        tVertexVec rect;
        rect.resize(4);

        float minX = 0;
        float minY = 0;
        float minZ = 0;

        float maxX = mWidth;
        float maxY = mHeight;
        float maxZ = mLength;

        // plane XY
        rect[0] = cVertex( cVector3f(minX,minY,minZ), cVector3f(0,0,-1), mColor );
        rect[1] = cVertex( cVector3f(minX,maxY,minZ), cVector3f(0,0,-1), mColor );
        rect[2] = cVertex( cVector3f(maxX,maxY,minZ), cVector3f(0,0,-1), mColor );
        rect[3] = cVertex( cVector3f(maxX,minY,minZ), cVector3f(0,0,-1), mColor );

        AddTriangle(rect[0], rect[1], rect[2]);
        AddTriangle(rect[0], rect[2], rect[3]);

        rect[0] = cVertex( cVector3f(minX,minY,maxZ), cVector3f(0,0,1),  mColor );
        rect[1] = cVertex( cVector3f(maxX,minY,maxZ), cVector3f(0,0,1),  mColor );
        rect[2] = cVertex( cVector3f(maxX,maxY,maxZ), cVector3f(0,0,1),  mColor );
        rect[3] = cVertex( cVector3f(minX,maxY,maxZ), cVector3f(0,0,1),  mColor );

        AddTriangle(rect[0], rect[1], rect[2]);
        AddTriangle(rect[0], rect[2], rect[3]);

        // plane YZ
        rect[0] = cVertex( cVector3f(minX,minY,minZ), cVector3f(-1,0,0), mColor );
        rect[1] = cVertex( cVector3f(minX,minY,maxZ), cVector3f(-1,0,0), mColor );
        rect[2] = cVertex( cVector3f(minX,maxY,maxZ), cVector3f(-1,0,0), mColor );
        rect[3] = cVertex( cVector3f(minX,maxY,minZ), cVector3f(-1,0,0), mColor );

        AddTriangle(rect[0], rect[1], rect[2]);
        AddTriangle(rect[0], rect[2], rect[3]);

        rect[0] = cVertex( cVector3f(maxX,minY,minZ), cVector3f(1,0,0),  mColor );
        rect[1] = cVertex( cVector3f(maxX,maxY,minZ), cVector3f(1,0,0),  mColor );
        rect[2] = cVertex( cVector3f(maxX,maxY,maxZ), cVector3f(1,0,0),  mColor );
        rect[3] = cVertex( cVector3f(maxX,minY,maxZ), cVector3f(1,0,0),  mColor );

        AddTriangle(rect[0], rect[1], rect[2]);
        AddTriangle(rect[0], rect[2], rect[3]);

        // plane XZ
        rect[0] = cVertex( cVector3f(minX,minY,minZ), cVector3f(0,-1,0), mColor );
        rect[1] = cVertex( cVector3f(maxX,minY,minZ), cVector3f(0,-1,0), mColor );
        rect[2] = cVertex( cVector3f(maxX,minY,maxZ), cVector3f(0,-1,0), mColor );
        rect[3] = cVertex( cVector3f(minX,minY,maxZ), cVector3f(0,-1,0), mColor );

        AddTriangle(rect[0], rect[1], rect[2]);
        AddTriangle(rect[0], rect[2], rect[3]);

        rect[0] = cVertex( cVector3f(minX,maxY,minZ), cVector3f(0,1,0),  mColor );
        rect[1] = cVertex( cVector3f(minX,maxY,maxZ), cVector3f(0,1,0),  mColor );
        rect[2] = cVertex( cVector3f(maxX,maxY,maxZ), cVector3f(0,1,0),  mColor );
        rect[3] = cVertex( cVector3f(maxX,maxY,minZ), cVector3f(0,1,0),  mColor );

        AddTriangle(rect[0], rect[1], rect[2]);
        AddTriangle(rect[0], rect[2], rect[3]);

        unsigned int ind = 0;

        for (int i = 0; i < (int)numIndices; i++)
            mpSolidVertexBuffer->AddIndex(ind++);

        rect.clear();

        // bounding volume

        mBoundingVolume.SetSize( cVector3f(0,0,0), cVector3f(mWidth,mHeight,mLength) );

        mvSize.x = mWidth;
        mvSize.y = mHeight;
        mvSize.z = mLength;
    }
	cVector3f cPhysicsJointBallNewton::GetVelocity()
	{
		return cVector3f(0,0,0);
	}
Example #16
0
	cShadowVolumeBV* cBoundingVolume::GetShadowVolume(const cVector3f& avLightPos,
														float afLightRange,bool abForceUpdate)
	{
		if(cMath::PointBVCollision(avLightPos, *this)) return NULL;
		
		if(!abForceUpdate && !mbShadowPlanesNeedUpdate) return &mShadowVolume;
		
		//Set size 0.
		mShadowVolume.mvPoints.resize(0);
		
		//Get the corners.
		cVector3f vMax = GetMax();
		cVector3f vMin = GetMin();
		cVector3f vCorners[8];
		vCorners[0] = cVector3f(vMax.x,vMax.y,vMax.z);
		vCorners[1] = cVector3f(vMax.x,vMax.y,vMin.z);
		vCorners[2] = cVector3f(vMax.x,vMin.y,vMax.z);
		vCorners[3] = cVector3f(vMax.x,vMin.y,vMin.z);

		vCorners[4] = cVector3f(vMin.x,vMax.y,vMax.z);
		vCorners[5] = cVector3f(vMin.x,vMax.y,vMin.z);
		vCorners[6] = cVector3f(vMin.x,vMin.y,vMax.z);
		vCorners[7] = cVector3f(vMin.x,vMin.y,vMin.z);
		
		/////////////////////////////////////////////////////////////////////
		//Iterate the faces and check which ones are facing the light.
		int lNearPoint =-1;
		mShadowVolume.mlPlaneCount=0;
		for(int face=0; face< 6; face++)
		{
			gvFaces[face].facingLight = cMath::Vector3Dot(gvFaces[face].normal, 
														vCorners[kvFacePoints[face]] - avLightPos)<0;
			
			//Get a point for the near plane. (any edge point will do)
			if(gvFaces[face].facingLight)
			{
				mShadowVolume.mvPlanes[mShadowVolume.mlPlaneCount] = cPlanef(
												gvFaces[face].normal*-1.0f,vCorners[kvFacePoints[face]]);
				mShadowVolume.mlPlaneCount++;
			}
		}

		mShadowVolume.mlCapPlanes = mShadowVolume.mlPlaneCount;
	
		//The direction a point is pushed away in
		cVector3f vDir;
		
		//The length to push the shadow points.
		float fPushLength = afLightRange*kSqrt2f;
		
		//////////////////////////////////////////////////////////
		//Iterate the edges and build quads from the silhouette
		for(int edge=0; edge< 12;edge++)
		{
			const cTriEdge& Edge = kvBVEdges[edge];

			cTriangleData &Face1 = gvFaces[Edge.tri1];
			cTriangleData &Face2 = gvFaces[Edge.tri2];

			if((Face1.facingLight && !Face2.facingLight) ||	(Face2.facingLight && !Face1.facingLight))
			{
				if(Face1.facingLight)
				{
					mShadowVolume.mvPoints.push_back(vCorners[Edge.point1]);
					mShadowVolume.mvPoints.push_back(vCorners[Edge.point2]);
					
					vDir = (vCorners[Edge.point2]-avLightPos); vDir.Normalise();
					mShadowVolume.mvPoints.push_back(vCorners[Edge.point2] + vDir*fPushLength);
					
					vDir = (vCorners[Edge.point1]-avLightPos); vDir.Normalise();
					mShadowVolume.mvPoints.push_back(vCorners[Edge.point1] + vDir*fPushLength);
				}
				else
				{
					mShadowVolume.mvPoints.push_back(vCorners[Edge.point2]);
					mShadowVolume.mvPoints.push_back(vCorners[Edge.point1]);
					
					vDir = (vCorners[Edge.point1]-avLightPos); vDir.Normalise();
					mShadowVolume.mvPoints.push_back(vCorners[Edge.point1] + vDir*fPushLength);

					vDir = (vCorners[Edge.point2]-avLightPos); vDir.Normalise();
					mShadowVolume.mvPoints.push_back(vCorners[Edge.point2] + vDir*fPushLength);
				}
			}
		}
		
		/////////////////////////////////////
		//Create the side planes:
		
		for(int i=0; i< (int)mShadowVolume.mvPoints.size(); i+=4)
		{
			//Normal should point inwards
			cVector3f vNormal = cMath::Vector3Cross(
								mShadowVolume.mvPoints[i+1] - mShadowVolume.mvPoints[i+0],
								mShadowVolume.mvPoints[i+2] - mShadowVolume.mvPoints[i+0]);
			mShadowVolume.mvPlanes[mShadowVolume.mlPlaneCount].FromNormalPoint(vNormal,
															 mShadowVolume.mvPoints[i+0]);
			mShadowVolume.mvPlanes[mShadowVolume.mlPlaneCount].Normalise();

			mShadowVolume.mlPlaneCount++;
		}

		return &mShadowVolume;
	}
Example #17
0
 void cSolid::Scale(float aTimes)
 {
     mObjectCamera.Scale( cVector3f(aTimes,aTimes,aTimes) );
 }
Example #18
0
	bool cWidgetWindow::OnMouseMove(cGuiMessageData &aData)
	{
		if(mbMoving) SetGlobalPosition(mvRelMousePos + cVector3f(aData.mvPos.x, aData.mvPos.y,0));
		return true;
	}
Example #19
0
	void cWorld3D::SetUpData()
	{
		mpPortalContainer->Compile();

		tSectorMap *pSectorMap = mpPortalContainer->GetSectorMap();

		//////////////////////////////////////////////
		// Get world size by getting sector BV
		if(pSectorMap->size()>0)
		{
			tSectorMapIt SectorIt = pSectorMap->begin();
			cSector *pSector = SectorIt->second;

			cVector3f vMin = pSector->GetBV()->GetMin();
			cVector3f vMax = pSector->GetBV()->GetMax();
			++SectorIt;
			for(; SectorIt != pSectorMap->end(); ++SectorIt)
			{
				pSector = SectorIt->second;

				cVector3f vLocalMin = pSector->GetBV()->GetMin();
				cVector3f vLocalMax = pSector->GetBV()->GetMax();

				CheckMinMaxUpdate(vMin,vMax,vLocalMin,vLocalMax);
			}

			//Log("World Min: (%s) Max: (%s)\n",vMin.ToString().c_str(), vMax.ToString().c_str());

			//Create a 10 m border around the world aswell:
			vMin = vMin - cVector3f(10,10,10);
			vMax = vMax + cVector3f(10,10,10);

			if(mpPhysicsWorld) mpPhysicsWorld->SetWorldSize(vMin, vMax);
		}
		//////////////////////////////////////////////
		// Get world size by getting global objects BV
		else
		{
			cVector3f vMin = cVector3f(10000,10000,100000);
			cVector3f vMax =cVector3f(-10000,-10000,-100000);

			//Dynamic
			tRenderableSet *pRenSet = mpPortalContainer->GetGlobalDynamicObjectSet();
			tRenderableSetIt DynIt = pRenSet->begin();
			for(;DynIt != pRenSet->end();++DynIt)
			{
				iRenderable *pObject = *DynIt;
				cVector3f vLocalMin = pObject->GetBoundingVolume()->GetMin();
				cVector3f vLocalMax = pObject->GetBoundingVolume()->GetMax();

				CheckMinMaxUpdate(vMin,vMax,vLocalMin,vLocalMax);
			}

			//Static
			tRenderableList *pRenList = mpPortalContainer->GetGlobalStaticObjectList();
			tRenderableListIt StaticIt = pRenList->begin();
			for(;StaticIt != pRenList->end();++StaticIt)
			{
				iRenderable *pObject = *StaticIt;
				cVector3f vLocalMin = pObject->GetBoundingVolume()->GetMin();
				cVector3f vLocalMax = pObject->GetBoundingVolume()->GetMax();

				CheckMinMaxUpdate(vMin,vMax,vLocalMin,vLocalMax);
			}



			vMin = vMin - cVector3f(10,10,10);
			vMax = vMax + cVector3f(10,10,10);
			if(mpPhysicsWorld) mpPhysicsWorld->SetWorldSize(vMin, vMax);
		}
	}
Example #20
0
iSoundChannel* cSoundHandler::PlayStream(const tString& asFileName,bool abLoop,float afVolume,bool ab3D, eSoundDest aEffectType)
{
    if(asFileName == "")return NULL;

    iSoundData* pData = mpResources->GetSoundManager()->CreateSoundData(asFileName,true,abLoop);
    if(pData==NULL)
        {
            Error("Couldn't load stream '%s'\n",asFileName.c_str());
            return false;
        }

    iSoundChannel *pSound = pData->CreateChannel(256);
    if(!pSound)
        {
            Error("Can't create sound channel for '%s'\n",asFileName.c_str());
            return NULL;
        }

    //If it is silent do everything as normal except stop the sound at start.
    if(mbSilent)
        {
            //pSound->SetLooping(false);
            pSound->Stop();
        }
    else
        {
            pSound->Play();
        }

    pSound->SetId(mlIdCount);

    pSound->Set3D(ab3D);

    cSoundEntry Entry;
    Entry.mpSound = pSound;
    Entry.mfNormalVolume = afVolume;
    Entry.msName = asFileName;
    Entry.mfNormalSpeed = 1.0f;

    Entry.mfBlockFadeDest = 1;
    Entry.mfBlockFadeSpeed = 1;
    Entry.mfBlockMul = 1;
    Entry.mbFirstTime = true;

    Entry.mbStream = true;

    Entry.mEffectType = aEffectType;

    /////////////////////////
    //Setup position
    pSound->SetPositionRelative(true);
    pSound->SetRelPosition(cVector3f(0,0,1));
    cVector3f vPos = cMath::MatrixMul(	mpLowLevelSound->GetListenerMatrix(),
                                        pSound->GetRelPosition() );
    pSound->SetPosition(vPos);

    mlstGuiSounds.push_back(Entry);

    mlIdCount++;

    return pSound;
}
void cGameSwingDoor::BreakAction()
{
	if(mvBodies.empty()) return;

	iPhysicsBody *pDynBody = NULL;
	iPhysicsBody *pStaticBody = NULL;

	for(size_t i=0; i < mvBodies.size();++i)
	{
		if(mvBodies[i]->GetMass()!=0) pDynBody = mvBodies[i];
		if(mvBodies[i]->GetMass()==0) pStaticBody = mvBodies[i];
	}

	if(pDynBody==NULL && pStaticBody==NULL) return;

	//////////////////
	//Script
	if(mvCallbackScripts[eGameEntityScriptType_OnBreak])
	{
		tString sCommand = GetScriptCommand(eGameEntityScriptType_OnBreak);
		mpInit->RunScriptCommand(sCommand);
	}

	cWorld3D *pWorld = mpInit->mpGame->GetScene()->GetWorld3D();

	//////////////////
	//Check if player os holding object
	if( (mpInit->mpPlayer->GetState()==ePlayerState_Grab ||
		mpInit->mpPlayer->GetState()==ePlayerState_Move ||
		mpInit->mpPlayer->GetState()==ePlayerState_Push)
		&&
		(mpInit->mpPlayer->GetPushBody() == pDynBody ||
		 mpInit->mpPlayer->GetPushBody() == pStaticBody))
	{
		mpInit->mpPlayer->ChangeState(ePlayerState_Normal);
	}

	cBoundingVolume *pBV = mpMeshEntity->GetBoundingVolume();

	//////////////////
	//Particle System
	if(msBreakPS!="")
	{
		cParticleSystem3D *pPS = pWorld->CreateParticleSystem("Break",msBreakPS,cVector3f(1,1,1),
													pDynBody->GetWorldMatrix());
	}
	
	//////////////////
	//Entity
	if(msBreakEntity != "")
	{
		iEntity3D * pEntity = pWorld->CreateEntity(mpMeshEntity->GetName() + "_broken",
													pDynBody->GetWorldMatrix(),
													msBreakEntity, true);
		if(pEntity)
		{
			iGameEntity *pGameEntity = mpInit->mpMapHandler->GetLatestEntity();

			cVector3f vImpulse = mvLastImpulse * 2;// / (float)pGameEntity->GetBodyNum();

			for(int i=0; i< pGameEntity->GetBodyNum(); ++i)
			{
				//Add the object velocity
				iPhysicsBody *pNewBody = pGameEntity->GetBody(i);
				
				if(pNewBody->GetMass()==0 && pStaticBody)
				{
					pNewBody->SetMatrix(pStaticBody->GetWorldMatrix());
				}

				//pNewBody->SetLinearVelocity(pBody->GetLinearVelocity());
				pNewBody->AddImpulse(vImpulse);
			}
		}
	}

	mpInit->mpGame->ResetLogicTimer();
}