Ejemplo n.º 1
0
//  updatePoses - Set car pos for Ogre nodes, update particles, trails
//---------------------------------------------------------------------------------------------------------------
void App::updatePoses(float time)
{
    if (carModels.empty())  return;
    PROFILER.beginBlock(".updPos ");

    //  Update all carmodels from their carPos
    const CarModel* playerCar = carModels.front();

    int cgh = -1;
    for (int c = 0; c < carModels.size(); ++c)
    {
        CarModel* carM = carModels[c];
        if (!carM)  {
            PROFILER.endBlock(".updPos ");
            return;
        }

        ///  ghosts visibility  . . .
        //  hide when empty or near car
        bool bGhostCar = carM->eType == (isGhost2nd ? CarModel::CT_GHOST2 : CarModel::CT_GHOST),  // show only actual
             bGhTrkVis = carM->isGhostTrk() && ghtrk.GetTimeLength()>0 && pSet->rpl_trackghost,
             bGhostVis = ghplay.GetNumFrames()>0 && pSet->rpl_ghost,
             bGhostEnd = pGame->timer.GetPlayerTime(0) > ghplay.GetTimeLength();
        if (bGhostCar)  cgh = c;

        if (carM->isGhost())  // for all
        {
            bool loading = iLoad1stFrames >= 0;  // show during load ?..
            bool curVisible = carM->mbVisible;
            bool newVisible = bGhostVis && bGhostCar /**/&& !bGhostEnd/**/ || bGhTrkVis;

            if (loading)
                carM->setVisible(true);  //!carM->isGhost());
            else
            {   //  hide ghost when close to player
                float d = carM->pMainNode->getPosition().squaredDistance(playerCar->pMainNode->getPosition());
                if (d < pSet->ghoHideDist * pSet->ghoHideDist)
                    newVisible = false;

                if (carM->isGhostTrk() && cgh >= 0)  // hide track's ghost when near ghost
                {
                    float d = carM->pMainNode->getPosition().squaredDistance(carModels[cgh]->pMainNode->getPosition());
                    if (d < pSet->ghoHideDistTrk * pSet->ghoHideDistTrk)
                        newVisible = false;
                }
                if (curVisible == newVisible)
                    carM->hideTime = 0.f;
                else
                {   carM->hideTime += time;  // change vis after delay
                    if (carM->hideTime > gPar.ghostHideTime)
                        carM->setVisible(newVisible);
                }
            }
        }


        //  update car pos
        int q = iCurPoses[c];
        int cc = (c + iRplCarOfs) % carModels.size();  // replay offset, camera from other car
        int qq = iCurPoses[cc];
        PosInfo& pi = carPoses[q][c], &pic = carPoses[qq][cc];
        carM->Update(carPoses[q][c], carPoses[qq][cc], time);


        //  nick text pos upd  3d to 2d
        if (carM->pNickTxt && carM->pMainNode)
        {
            Camera* cam = playerCar->fCam->mCamera;  //above car 1m
            Vector3 p = hud->projectPoint(cam, carM->pMainNode->getPosition() + Vector3(0,1.f,0));
            p.x = p.x * mSplitMgr->mDims[0].width * 0.5f;  //1st viewport dims
            p.y = p.y * mSplitMgr->mDims[0].height * 0.5f;
            carM->pNickTxt->setPosition(p.x-40, p.y-16);  //center doesnt work
            carM->pNickTxt->setVisible(p.z > 0.f);
        }
    }

    ///  Replay info
    if (bRplPlay && !pGame->cars.empty())
    {
        double pos = pGame->timer.GetPlayerTime(0);
        float len = replay.GetTimeLength();
        gui->valRplPerc->setCaption(fToStr(pos/len*100.f, 1,4)+" %");
        gui->valRplCur->setCaption(CHud::StrTime(pos));
        gui->valRplLen->setCaption(CHud::StrTime(len));

        float v = pos/len;
        gui->slRplPos->setValue(v);
    }


    ///  objects - dynamic (props)  -------------------------------------------------------------
    for (int i=0; i < scn->sc->objects.size(); ++i)
    {
        Object& o = scn->sc->objects[i];
        if (o.ms)
        {
            btTransform tr, ofs;
            o.ms->getWorldTransform(tr);
            const btVector3& p = tr.getOrigin();
            const btQuaternion& q = tr.getRotation();
            o.pos[0] = p.x();
            o.pos[1] = p.y();
            o.pos[2] = p.z();
            o.rot[0] = q.x();
            o.rot[1] = q.y();
            o.rot[2] = q.z();
            o.rot[3] = q.w();
            o.SetFromBlt();
        }
    }

    PROFILER.endBlock(".updPos ");
}
Ejemplo n.º 2
0
//  updatePoses - Set car pos for Ogre nodes, update particles, trails
//---------------------------------------------------------------------------------------------------------------
void App::updatePoses(float time)
{	
	//  Update all carmodels with their newPosInfo
	int i=0;
	std::vector<CarModel*>::iterator carIt = carModels.begin();
	std::vector<PosInfo>::iterator newPosIt = newPosInfos.begin();
	while (carIt != carModels.end())
	{
		CarModel* carM = *carIt;
		if (!carM)  return;
		PosInfo newPosInfo = *newPosIt;
		
		//  hide ghost when empty
		bool bGhost = carM->eType == CarModel::CT_GHOST,
			bGhostVis = (ghplay.GetNumFrames() > 0) && pSet->rpl_ghost;
		if (bGhost)
		{
			carM->setVisible(bGhostVis);
			
			//  hide ghost car when close to player car (only when not transparent)
			if (!pSet->rpl_alpha)
			{
				CarModel* playerCar = carModels.front();
				float distance = carM->pMainNode->getPosition().squaredDistance(playerCar->pMainNode->getPosition());
				if (distance < 16.f)
					carM->setVisible(false);
			}
		}
		
		carM->Update(newPosInfo, time);
		
		//  nick text 3d pos
		//projectPoint()
		
		//  pos on minimap  x,y = -1..1
		//if (!bGhost)
		{	float xp =(-newPosInfo.pos[2] - minX)*scX*2-1,
				  yp =-(newPosInfo.pos[0] - minY)*scY*2+1;
			newPosInfos[i].miniPos = Vector2(xp,yp);
			
			if (vNdPos[i])
				if (bGhost && !bGhostVis)  vNdPos[i]->setPosition(-100,0,0);  //hide
				else if (pSet->mini_zoomed)  vNdPos[i]->setPosition(0,0,0);
				else					vNdPos[i]->setPosition(xp,yp,0);
		}
		carIt++;  newPosIt++;  i++;
	}
	
	///  Replay info
	if (bRplPlay && pGame->cars.size() > 0)
	{
		double pos = pGame->timer.GetPlayerTime();
		float len = replay.GetTimeLength();
		if (valRplPerc){  sprintf(s, "%4.1f %%", pos/len * 100.f);  valRplPerc->setCaption(s);  }
		if (valRplCur)  valRplCur->setCaption(GetTimeString(pos));
		if (valRplLen)  valRplLen->setCaption(GetTimeString(len));

		if (slRplPos)
		{	int v = pos/len * res;  slRplPos->setScrollPosition(v);  }
	}	
}