void DiffuseCubeDemo::updateScene(float dt) { mGfxStats->setVertexCount(24); mGfxStats->setTriCount(12); 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(); }
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(); }
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(); }