Ejemplo n.º 1
0
void MultiTexDemo::updateScene(float dt)
{
	mGfxStats->update(dt);

	// Get snapshot of input devices.
	gDInput->poll();

	// Check input.
	if( gDInput->keyDown(DIK_W) )	 
		mCameraHeight   += 25.0f * dt;
	if( gDInput->keyDown(DIK_S) )	 
		mCameraHeight   -= 25.0f * dt;

	// Divide by 50 to make mouse less sensitive. 
	mCameraRotationY += gDInput->mouseDX() / 100.0f;
	mCameraRadius    += gDInput->mouseDY() / 25.0f;

	// If we rotate over 360 degrees, just roll back to 0
	if( fabsf(mCameraRotationY) >= 2.0f * D3DX_PI ) 
		mCameraRotationY = 0.0f;

	// Don't let radius get too small.
	if( mCameraRadius < 5.0f )
		mCameraRadius = 5.0f;

	// The camera position/orientation relative to world space can 
	// change every frame based on input, so we need to rebuild the
	// view matrix every frame with the latest changes.
	buildViewMtx();
}
Ejemplo n.º 2
0
void EngineMain::updateScene(float dt)
{
	m_GfxStats->update(dt);
	buildViewMtx();
	skull->Rotate(sin(dt));
	tiny->Rotate(sin(dt));
}
Ejemplo n.º 3
0
void TriGridDemo::updateScene(float dt)
{
	mGfxStats->setVertexCount(mNumVertices);
	mGfxStats->setTriCount(mNumTriangles);
	mGfxStats->update(dt);

	gDInput->poll();

	if (gDInput->keyDown(DIK_W))
		mCameraHeight += 25.0f * dt;
	if (gDInput->keyDown(DIK_S))
		mCameraHeight -= 25.0f * dt;

	// divide by 50 to make mouse less sensitive
	mCameraRotationY += gDInput->mouseDX() / 50.0f;
	mCameraRadius    += gDInput->mouseDY() / 50.0f;

	if (fabsf(mCameraRotationY) >= 2.0f * D3DX_PI)
		mCameraRotationY = 0.0f;

	if (mCameraRadius < 5.0f)
		mCameraRadius = 5.0f;

	buildViewMtx();
}
Ejemplo n.º 4
0
void RobotArmDemo::updateScene(float dt)
{
	mGfxStats->update(dt);

	// Get snapshot of input devices.
	gDInput->poll();

	// Check input.
	if( gDInput->keyDown(DIK_W) )	 
		mCameraHeight   += 25.0f * dt;
	if( gDInput->keyDown(DIK_S) )	 
		mCameraHeight   -= 25.0f * dt;

	// Allow the user to select a bone (zero based index)
	if( gDInput->keyDown(DIK_1) )	mBoneSelected = 0; 
	if( gDInput->keyDown(DIK_2) )	mBoneSelected = 1;  
	if( gDInput->keyDown(DIK_3) )	mBoneSelected = 2; 
	if( gDInput->keyDown(DIK_4) )	mBoneSelected = 3; 
	if( gDInput->keyDown(DIK_5) )	mBoneSelected = 4; 

	// Allow the user to rotate a bone.
	if( gDInput->keyDown(DIK_A) )	 
		mBones[mBoneSelected].zAngle += 1.0f * dt;
	if( gDInput->keyDown(DIK_D) )	 
		mBones[mBoneSelected].zAngle -= 1.0f * dt;


	// If we rotate over 360 degrees, just roll back to 0
	if( fabsf(mBones[mBoneSelected].zAngle) >= 2.0f*D3DX_PI)
		mBones[mBoneSelected].zAngle = 0.0f;


	// Divide by 50 to make mouse less sensitive. 
	//mCameraRotationY += gDInput->mouseDX() / 100.0f;
	//mCameraRadius    += gDInput->mouseDY() / 25.0f;
	if( gDInput->keyDown(DIK_LEFT) )	 
		mCameraRotationY += 1.0f * dt;
	if( gDInput->keyDown(DIK_RIGHT) )	 
		mCameraRotationY -= 1.0f * dt;

	if( gDInput->keyDown(DIK_UP) )	 
		mCameraRadius -= 1.0f * dt;
	if( gDInput->keyDown(DIK_DOWN) )	 
		mCameraRadius += 1.0f * dt;


	// If we rotate over 360 degrees, just roll back to 0
	if( fabsf(mCameraRotationY) >= 2.0f * D3DX_PI ) 
		mCameraRotationY = 0.0f;

	// Don't let radius get too small.
	//if( mCameraRadius < 2.0f )
	//	mCameraRadius = 2.0f;

	// The camera position/orientation relative to world space can 
	// change every frame based on input, so we need to rebuild the
	// view matrix every frame with the latest changes.
	buildViewMtx();
}
Ejemplo n.º 5
0
void SolarSysDemo::updateScene(float dt)
{
	mGfxStats->update(dt);

	// Get snapshot of input devices.
	gDInput->poll();

	// Check input.
	if( gDInput->keyDown(DIK_W) )	 
		mCameraHeight   += 25.0f * dt;
	if( gDInput->keyDown(DIK_S) )	 
		mCameraHeight   -= 25.0f * dt;

	// Divide by 50 to make mouse less sensitive. 
	mCameraRotationY += gDInput->mouseDX() / 100.0f;
	mCameraRadius    += gDInput->mouseDY() / 25.0f;

	// If we rotate over 360 degrees, just roll back to 0
	if( fabsf(mCameraRotationY) >= 2.0f * D3DX_PI ) 
		mCameraRotationY = 0.0f;

	// Don't let radius get too small.
	if( mCameraRadius < 2.0f )
		mCameraRadius = 2.0f;

	// The camera position/orientation relative to world space can 
	// change every frame based on input, so we need to rebuild the
	// view matrix every frame with the latest changes.
	buildViewMtx();

	//================================================
	// Animate the solar objects with respect to time.

	for(int i = 0; i < NUM_OBJECTS; ++i)
	{
		switch(mObject[i].typeID)
		{
		case SUN:
			mObject[i].yAngle += 1.5f * dt;
			break;
		case PLANET:
			mObject[i].yAngle += 2.0f * dt;
			break;
		case MOON:
			mObject[i].yAngle += 2.5f * dt;
			break;
		}

		// If we rotate over 360 degrees, just roll back to 0.
		if(mObject[i].yAngle >= 2.0f*D3DX_PI)
			mObject[i].yAngle = 0.0f;
	}
}
Ejemplo n.º 6
0
void CubeDemo::render() {
    buildViewMtx();

    device->SetStreamSource(0, mVB, 0, sizeof(VertexPos));
    device->SetIndices(mIB);
    device->SetVertexDeclaration(VertexPos::Decl);

    D3DXMATRIX W;
    D3DXMatrixIdentity(&W);
    device->SetTransform(D3DTS_WORLD, &W);
    device->SetTransform(D3DTS_VIEW, &mView);
    device->SetTransform(D3DTS_PROJECTION, &mProj);
    device->SetRenderState(D3DRS_FILLMODE, D3DFILL_WIREFRAME);
    device->SetRenderState(D3DRS_CULLMODE, D3DCULL_NONE);
    device->DrawIndexedPrimitive(D3DPT_TRIANGLELIST, 0, 0, 8, 0, 12);
}
Ejemplo n.º 7
0
void AmbientDiffuseDemo::updateScene(float dt)
{
    mGfxStats->setVertexCount(mTeapot->GetNumVertices());
    mGfxStats->setTriCount(mTeapot->GetNumFaces());
    mGfxStats->update(dt);

    // Get snapshot of input devices.
    gDInput->poll();

    // Check input.
    if( gDInput->keyDown(DIK_W) )
        mCameraHeight   += 25.0f * dt;
    if( gDInput->keyDown(DIK_S) )
        mCameraHeight   -= 25.0f * dt;

    // Divide by 50 to make mouse less sensitive.
    //mCameraRotationY += gDInput->mouseDX() / 100.0f;
    //mCameraRadius    += gDInput->mouseDY() / 25.0f;
    if( gDInput->keyDown(DIK_LEFT) )
        mCameraRotationY += 1.0f * dt;
    if( gDInput->keyDown(DIK_RIGHT) )
        mCameraRotationY -= 1.0f * dt;

    if( gDInput->keyDown(DIK_UP) )
        mCameraRadius -= 3.0f * dt;
    if( gDInput->keyDown(DIK_DOWN) )
        mCameraRadius += 3.0f * dt;


    // If we rotate over 360 degrees, just roll back to 0
    if( fabsf(mCameraRotationY) >= 2.0f * D3DX_PI )
        mCameraRotationY = 0.0f;

    // Don't let radius get too small.
    if( mCameraRadius < 5.0f )
        mCameraRadius = 5.0f;

    // The camera position/orientation relative to world space can
    // change every frame based on input, so we need to rebuild the
    // view matrix every frame with the latest changes.
    buildViewMtx();
}
Ejemplo n.º 8
0
void StencilMirrorDemo::updateScene(float dt)
{
	mGfxStats->update(dt);

	gDInput->poll();

	if (gDInput->keyDown(DIK_W))
		mCameraHeight += 25.0f * dt;
	if (gDInput->keyDown(DIK_S))
		mCameraHeight -= 25.0f * dt;

	// divide by 50 to make mouse less sensitive
	mCameraRotationY += gDInput->mouseDX() / 100.0f;
	mCameraRadius    += gDInput->mouseDY() / 25.0f;

	if (fabsf(mCameraRotationY) >= 2.0f * D3DX_PI)
		mCameraRotationY = 0.0f;

	if (mCameraRadius < 3.0f)
		mCameraRadius = 3.0f;

	buildViewMtx();
}
Ejemplo n.º 9
0
void SkeletonClass::updateScene(float dt)
{
	// Reset the statistics for the scene - each object will add to it.
	GfxStats::GetInstance()->setVertexCount(0);
	GfxStats::GetInstance()->setTriCount(0);
	GfxStats::GetInstance()->update(dt);

	input(dt);

	if (mCurrentObject == m_Objects.size())
		mCurrentObject = 0;

	//if we go above 360 or below 0, wrap around
	if (mCameraRotationX > 2 * D3DX_PI)
		mCameraRotationX = 0;
	else if (mCameraRotationX < 0)
		mCameraRotationX = 2 * D3DX_PI;

	//if the camera is on one side, it's up is one direction. The other side, the camera's up is in the opposite direction
	//this prevents the camera from switching orientation at the bottom of the camera swing
	if (mCameraRotationX > D3DX_PI)
		mUp.y = 1;
	if (mCameraRotationX < D3DX_PI)
		mUp.y = -1;
		
	// If we rotate over 360 degrees, just roll back to 0
	if (fabsf(mCameraRotationY) >= 2.0f * D3DX_PI)
		mCameraRotationY = 0.0f;

	// Don't let radius get too small.
	if( mCameraRadius < 5.0f )
		mCameraRadius = 5.0f;

	if (mNormalStrength < 0.0f)
	{
		mNormalStrength = 0.0f;
	}
	if (mNormalStrength > 1.0f)
	{
		mNormalStrength = 1.0f;
	}

	if (mReflectSpecBlend < 0.0f)
	{
		mReflectSpecBlend = 0.0f;
	}
	if (mReflectSpecBlend > 1.0f)
	{
		mReflectSpecBlend = 1.0f;
	}
	GfxStats::GetInstance()->setReflectSpecBlend(mReflectSpecBlend);
	GfxStats::GetInstance()->setNormalStrength(mNormalStrength);
	// The camera position/orientation relative to world space can 
	// change every frame based on input, so we need to rebuild the
	// view matrix every frame with the latest changes.
	buildViewMtx();

	//D3DXMATRIX mViewInv;
	//D3DXMatrixTranspose(&mViewInv, &mView);
	m_Objects[mCurrentObject % m_Objects.size()]->Update(mLightPos, D3DXVECTOR3(mView._41, mView._42, mView._43), mSpecularCoefficient);
}
Ejemplo n.º 10
0
void Evolution::updateScene(float dt)
{
    gDInput->poll();

    mTrueTime = dt;
    mCoolTime += mTrueTime;

    //mBellyFoods = 0;

    mGfxStats->setTriCount((lifeformList.size()+foodList.size()+eggList.size())*2);
    mGfxStats->setVertexCount((lifeformList.size()+foodList.size()+eggList.size())*4);
    mGfxStats->update(mTrueTime);

    dt *= mTimeSpeed;

    if (gDInput->keyDown(DIK_LEFT) && mCoolTime > 0.1f)
    {
        --mTimeSpeed;
        if (mTimeSpeed < 1.0f)
            mTimeSpeed = 1.0f;
        mCoolTime = 0.0f;
    }

    if (gDInput->keyDown(DIK_RIGHT) && mCoolTime > 0.1f)
    {
        ++mTimeSpeed;
        if (mTimeSpeed > 30.0f)
            mTimeSpeed = 30.0f;
        mCoolTime = 0.0f;
    }


    POINT mpos;
    GetCursorPos(&mpos);
    ScreenToClient(mhMainWnd, &mpos);
    //mpos.x -= 400;
    ////mpos.y = -mpos.y + 300;
    //D3DXVECTOR4 mousePos;
    //D3DXVec3Transform(&mousePos, &(D3DXVECTOR3(mpos.x, mpos.y, 0.0f)), &(mView*mProj));

    //Mouse position and clicking stuff
    D3DXVECTOR3 mousePos(0.0f, 0.0f, 0.0f);
    static float w = (float)md3dPP.BackBufferWidth;
    static float h = (float)md3dPP.BackBufferHeight;
    float x = (2.0f*mpos.x/w - 1.0f) / mProj(0,0);
    float y = (-2.0f*mpos.y/h + 1.0f) / mProj(1,1);

    D3DXVECTOR3 dir(x, y, 1.0f);

    D3DXMATRIX invView;
    D3DXMatrixInverse(&invView, 0, &mView);

    D3DXVec3TransformNormal(&mousePos, &dir, &invView);
    D3DXVec3Normalize(&mousePos, &mousePos);

    float ratio = -mCameraPos.z/mousePos.z;

    mousePos.x = mousePos.x*ratio + mCameraPos.x;
    mousePos.y = mousePos.y*ratio + mCameraPos.y;

    //Zooming in/out
    // Try making a ray to each of the four corners and go from there
    if (gDInput->mouseDZ() != 0.0f)
    {
        mCameraPos.z += gDInput->mouseDZ()*mTrueTime*400.000f;
        mCameraPos.x += (gDInput->mouseDZ()*0.5000f*(mousePos.x-mCameraPos.x))*mTrueTime;
        mCameraPos.y += (gDInput->mouseDZ()*0.5000f*(mousePos.y-mCameraPos.y))*mTrueTime;
    }

    if (mbFollow)
    {
        mCameraPos.x = mFollowPos.x;
        mCameraPos.y = mFollowPos.y;
    }

    if (mCameraPos.z > -300.0f)
        mCameraPos.z = -300.0f;
    if (mCameraPos.z < -MapX)
        mCameraPos.z = -MapX;

    if (mCameraPos.x < -HalfMapX-mCameraPos.z/2.0f)
        mCameraPos.x = -HalfMapX-mCameraPos.z/2.0f;
    if (mCameraPos.x > HalfMapX+mCameraPos.z/2.0f)
        mCameraPos.x = HalfMapX+mCameraPos.z/2.0f;

    if (mCameraPos.y < -HalfMapY-mCameraPos.z*3.0f/8.0f)
        mCameraPos.y = -HalfMapY-mCameraPos.z*3.0f/8.0f;
    if (mCameraPos.y > HalfMapY+mCameraPos.z*3.0f/8.0f)
        mCameraPos.y = HalfMapY+mCameraPos.z*3.0f/8.0f;

    if (gDInput->mouseButtonDown(0) && mCoolTime > 1.0f)
    {
        mbDrawInfo = false;
    }

    if (gDInput->mouseButtonDown(1) && mCoolTime > 1.0f)
    {
        mbFollow = false;
    }

    /*if (gDInput->mouseButtonDown(2) && mCoolTime > 0.4f) // Add rightclick functions
    {
    	Stat newStat;
    	newStat.carnivoreParts = GetRandFloat()*20 + 1;
    	newStat.eggCycleLength = GetRandFloat()*60.0f;
    	newStat.lifeTimeLength = GetRandFloat()*360.0f;
    	newStat.eggTimeLength  = GetRandFloat()*120.0f;
    	newStat.foodCycleLength= GetRandFloat()*90.0f;
    	newStat.speed	       = GetRandFloat()*40.0f;
    	newStat.sightDistance  = GetRandFloat()*20.0f;
    	newStat.fearDistance   = GetRandFloat()*30.0f;
    	newStat.pursuitLength  = GetRandFloat()*20.0f;
    	newStat.pos			   = D3DXVECTOR3(mousePos.x, mousePos.y, 0.0f);

    	Egg egg;
    	egg.spawn(newStat);
    	eggList.push_back(egg);

    	mCoolTime = 0.0f;
    }*/

    bool followFlag = true;
    // Update the lovely lifeforms.
    std::list<Lifeform>::iterator iLifeform = lifeformList.begin();
    while (iLifeform != lifeformList.end())
    {
        iLifeform->updateLifeform(dt, mTrueTime);

        // Did the mouse CLICK on this lifeform?
        if ( gDInput->mouseButtonDown(0) )
            if (!mbDrawInfo)
                if (Distance(mousePos, iLifeform->getPosition()) < 10.0f)
                {
                    mDrawInfo = iLifeform->getStat();
                    mbDrawInfo = true;
                    mCoolTime = 0.0f;
                }
        if ( gDInput->mouseButtonDown(1) )
            if (!mbFollow)
                if (Distance(mousePos, iLifeform->getPosition()) < 10.0f)
                {
                    mbFollow = true;
                    mFollowNumber = iLifeform->getNameber();
                    mCoolTime = 0.0f;
                }
        if (mbFollow)
            if (mFollowNumber == iLifeform->getNameber())
            {
                mFollowPos = iLifeform->getPosition();
                followFlag = false;
            }





        if (iLifeform->isDead())
            iLifeform = lifeformList.erase(iLifeform);

        else
            ++iLifeform;
    }

    if (followFlag && mbFollow)
        mbFollow = false;

    // Run through the egg list and update them
    std::list<Egg>::iterator iEgg = eggList.begin();
    while (iEgg != eggList.end())
    {
        iEgg->updateEgg(dt);

        if (iEgg->isHatched())
            iEgg = eggList.erase(iEgg);

        else
            ++iEgg;
    }

    // Collect total food in stomach!
    /*std::list<Lifeform>::iterator iCheck = lifeformList.begin();
    while (iCheck != lifeformList.end())
    {
    	if (iCheck->isDead())
    		iCheck = lifeformList.erase(iCheck);

    	else
    	{
    		mBellyFoods += iCheck->getStomach();
    		++iCheck;
    	}
    }*/

    // Update food and the amount of them
    //mFoodSpawnTime += dt;
    //if (mFoodSpawnTime > mFoodSpawnCycleLength &&
    //foodList.size() < mFoodAmount &&
    //while(foodList.size() + mBellyFoods + eggList.size() < mMaxBio)
    //{
    //for (int i=0; i<mFoodAmount; ++i)
    //{
    //	Food food;
    //	food.spawn(GetRandPos());
    //	foodList.push_back(food);
    //}
    ///mFoodSpawnTime = 0.0f;
    //}

    // Updating the food
    std::list<Food>::iterator iFood = foodList.begin();
    while (iFood != foodList.end())
    {
        if (iFood->isEaten())
            iFood = foodList.erase(iFood);
        else
            ++iFood;
    }

    while(foodList.size() + BellyFoods + eggList.size() < mMaxBio)
    {
        Food food;
        food.spawn(GetRandPos());
        foodList.push_back(food);
    }


    buildViewMtx();
}