Exemple #1
0
// Add a mass to or remove a mass from the end of the chain
void TForm1::add_ball() {

  // Put this ball to the right of the current last ball
  CBall* b = new CBall();
  m_active_balls.push_back(b);

  int ball_index = m_active_balls.size() - 1;

  CBall* neighbor = m_active_balls[ball_index - 1];

  // Create a position for each ball, moving from left to right
  // with increasing i
  cVector3d pos = neighbor->getPos();
  pos.add(INITIAL_BALL_SPACING,0,0);
  b->setPos(pos);
  world->addChild(b);

  CSpring* s = new CSpring();
  m_active_springs.push_back(s);

  s->m_endpoint_1 = m_active_balls[ball_index];
  s->m_endpoint_2 = m_active_balls[ball_index-1];

  s->m_endpoint_1->m_springs.push_back(s);
  s->m_endpoint_2->m_springs.push_back(s);

  // Set the spring's rest length to be the initial distance between
  // the balls
  double d = cDistance(s->m_endpoint_1->getPos(),s->m_endpoint_2->getPos());
  s->m_rest_length = d;
  world->addChild(s);
}
Exemple #2
0
int judge(CBramka1 bramka1, CBramka2 bramka2, CBall ball) {
	
	if ((ball.get_x() >= bramka1.get_x()) && (ball.get_x() <= (bramka1.get_x() + bramka1.get_bok())) && (ball.get_y() >= bramka1.get_y()) (ball.get_y() <= bramka1.get_y() + bramka1.get_bok())) return 1;
	else if ((ball.x >= bramka2.x) && (ball.x <= (bramka2.x + bramka2.bok)) && (ball.y >= bramka2.y) (ball.y <= bramka2.y + bramka2.bok)) return 2;
	else return 0;

}
Exemple #3
0
CBall *GetNearestPlayerBall(const Vector &pos)
{
	CBall *pNearestBall = GetMatchBall();
	Vector ballPos = pNearestBall->GetPos();
	float shortestDist = (ballPos - pos).Length2DSqr();

	for (int i = 1; i <= gpGlobals->maxClients; i++)
	{
		CSDKPlayer *pPl = ToSDKPlayer(UTIL_PlayerByIndex(i));
		if (!pPl || !CSDKPlayer::IsOnField(pPl))
			continue;

		CBall *pBall = pPl->GetPlayerBall();
		if (!pBall)
			continue;

		Vector ballPos = pBall->GetPos();

		float dist = (ballPos - pos).Length2DSqr();
		if (dist < shortestDist)
		{
			shortestDist = dist;
			pNearestBall = pBall;
		}
	}

	return pNearestBall;
}
Exemple #4
0
CBall* CBall::createBallWithFileName(const char* fileName)
{

	CBall* ball = new CBall();

	if(ball && ball->initWithFile(fileName))
	{
		ball->autorelease();

		return ball;
	}
	CC_SAFE_DELETE(ball);
	return NULL;
}
Exemple #5
0
void CBall::UpdateBall(float dt)
{
	for(b2Body *b = PhysicsWorld::getInstance().GetBodyList(); b; b=b->GetNext()) 
	{    
        if (b->GetUserData() != NULL) 
		{
			CBall *ballData = (CBall *)b->GetUserData();
			if(b->GetType() == b2_dynamicBody && ballData)
			{			
				ballData->setPosition(ccp(b->GetPosition().x * PTM_RATIO, b->GetPosition().y * PTM_RATIO));
				ballData->setRotation (-1 * CC_RADIANS_TO_DEGREES(b->GetAngle()));
			}

        }        
    }
}
Exemple #6
0
int main() {

	int x;
	int y;

	CGoal goal1 = CGoal(50,50,100);
	CGoal goal2 = CGoal(1,1,100);
	CBall ball = CBall(25,25);

	bool goal;

	cout << "Welcome! Let's play some football." << endl;
	cout << "Kick by typing two integers from your keyboard." << endl;

	while (1) {

		cin >> x;
		cin >> y;

		// if (x >= -2147483648 && x <= 2147483648 && y >= -2147483648 && y <= 2147483648) {       // numbers from int range
		
			ball.set_x(ball.get_x() + x);
			ball.set_y(ball.get_y() + y);

			goal = judge(ball, goal1, goal2);

			if (goal == true) {

				cout << "You won, the game is over!" << endl;
				break;

			}
			else {

				cout << "Not this time, try again." << endl;

			}
		
		// }
		// else cout << "Not funny at all! I said INTEGER." << endl;

	}

	system("pause");
	return 0;
}
Exemple #7
0
bool MazeWallObstacle::IsIntersect( CBall const & ball ) const
{
	CPoint2D const & pt = ball.GetPos();
	double const r = ball.GetR();

	double const sqrR = r * r;
	if (m_pt1.SquareDistTo(pt) < sqrR || m_pt2.SquareDistTo(pt) < sqrR)
		return true;

	double const h = 0.5 * fabs(CrossProduct(m_pt1 - pt, m_pt2 - pt)) / m_length;
	if (h >= r)
		return false;

	double const projection = DotProduct(pt - m_pt1, m_pt2 - m_pt1) / m_length;
	if (projection < 0 || projection > m_length)
		return false;

	return true;
}
Exemple #8
0
int main(int argc, char *argv[])
{
     
	CBall *cPlayer;
	cPlayer = new CBall();
	CDisplay *cDsp;
	cDsp = new CDisplay(XRES,YRES,BPP,SDL_SWSURFACE|SDL_DOUBLEBUF|SDL_ANYFORMAT,0);
	CInput *cInp;
	cInp = new CInput(1);
        CPaddle *cPdl;
        cPdl = new CPaddle();
        
	cout << cPlayer->GetLives()<<endl;
	cPlayer->LoadIMG("images/ball.png");
	cPdl->LoadIMG("images/paddle.png");
        cPdl->setY((YRES/3)*2);
	cPdl->setX((XRES/2));
 	cout << cPdl->getX() << " " << cPdl->getY();
        cPdl->srect.w = cPdl->Surface->w;
        cPdl->srect.h = cPdl->Surface->h;
        cPdl->srect.x = cPdl->srect.y = 0;
        cPdl->drect.w = cPdl->Surface->w;
        cPdl->drect.h = cPdl->Surface->h;
        
	while (CBall::running)
	{
            cPdl->drect.x = cPdl->xco;
            cPdl->drect.y = cPdl->yco;
    	SDL_Event event;
    	while(SDL_PollEvent(&event))
	{
		CInput *cInp;
		cInp = new CInput(1);
			
		cout<<(cInp->updateInput(event))<<endl;
		delete cInp;
	}
            cPdl->Blit(*cDsp->Surface,cPdl->srect);//,&cPdl->drect);
            updateGameData();
            SDL_Flip(cDsp->Surface);  	
	}
	return(0);
}
Exemple #9
0
//=============================================================================
// 止まった時のジャッジ
//=============================================================================
void CCamera::JudgeCamera(void)
{
	D3DXVECTOR3 posModel = CGame::GetPlayerCamera();
	D3DXVECTOR3 rotModel = D3DXVECTOR3(0, 0, 0);
	D3DXVECTOR3 moveModel = D3DXVECTOR3(0, 0, 0);

	//ボールの受け取り
	CBall *pBall;
	pBall = CGame::GetBall(CGame::GetPlayerCount());

	//ボールの位置&向き取得
	D3DXVECTOR3 EposModel = pBall->GetPos();
	D3DXVECTOR3 ErotModel = CGame::GetVectorShot();

	//Distance = (float)sqrt((double)(posModel.x - EposModel.x)*(double)(posModel.x - EposModel.x) + (double)(posModel.y - EposModel.y)*(double)(posModel.y - EposModel.y) + (double)(posModel.z - EposModel.z)*(double)(posModel.z - EposModel.z));

	//注視点座標設定
	m_posCameraP = posModel;
	m_posCameraR = EposModel;
}
Exemple #10
0
//=============================================================================
// ボール動いてるなう
//=============================================================================
void CCamera::MoveCamera(void)
{
	D3DXVECTOR3 posModel = CGame::GetPlayerCamera();
	D3DXVECTOR3 rotModel = D3DXVECTOR3(0, 0, 0);
	D3DXVECTOR3 moveModel = D3DXVECTOR3(0, 0, 0);
	m_shottime++;
	//ボールの受け取り
	CBall *pBall;
	pBall = CGame::GetBall(CGame::GetPlayerCount());

	//ボールの位置&向き取得
	D3DXVECTOR3 EposModel = pBall->GetPos();
	D3DXVECTOR3 ErotModel = CGame::GetVectorShot();

	//Distance = (float)sqrt((double)(posModel.x - EposModel.x)*(double)(posModel.x - EposModel.x) + (double)(posModel.y - EposModel.y)*(double)(posModel.y - EposModel.y) + (double)(posModel.z - EposModel.z)*(double)(posModel.z - EposModel.z));

	//注視点座標設定
	m_posCameraP = posModel;
	if (m_shottime > 90)m_posCameraP = EposModel + ErotModel * -200.0f;
	m_posCameraR = EposModel;
	//m_posPointView = pBall->GetPos();
}
Exemple #11
0
void __fastcall TForm1::MassSpringFormCreate(TObject *Sender)
{
    m_floor = 0;
    m_floor_spring_constant = DEFAULT_FLOOR_SPRING_CONSTANT;

    // init world scale
    scale = 2.0;

    // create a world
    world = new cWorld();

    // set background properties
    world->setBackgroundColor(0.2,0.2,0.2);

    // create a camera in world
    camera  = new cCamera(world);
    world->addChild(camera);

    // set camera position and orientation
    camera->set(   cVector3d(0.0, 0.0, 7.0),   // position of camera.
                   cVector3d(0.0, 0.0, 0.0),   // camera looking at origin.
                   cVector3d(0.0, 1.0, 0.0));  // orientation of camera. (standing up.)

    // Create a light source and attach it to camera
    light = new cLight(world);
    camera->addChild(light);
    light->setEnabled(true);
    light->setPos(cVector3d(0,2,4));
    light->rotate(cVector3d(0,0,1), cDegToRad(180));

    // create a display for graphic rendering
    viewport = new cViewport(Panel1->Handle, camera, false);

    // create a tool
    tool = new cMeta3dofPointer(world, 0, true);
    tool->initialize();
    tool->setRenderingMode(RENDER_DEVICE);

    // Rotate the tool so its axes align with our opengl-like axes
    tool->rotate(cVector3d(0,0,1),-90.0*M_PI/180.0);
    tool->rotate(cVector3d(1,0,0),-90.0*M_PI/180.0);
    tool->computeGlobalPositions();

    tool->setWorkspace(3.5*scale, 3.5*scale, 3.5*scale);
    tool->setRadius(scale / 70.0);

    // tool becomes a child of the camera which we can control from
    world->addChild(tool);

    // Create a mesh to represent the floor
    m_floor = new cMesh(world);
    world->addChild(m_floor);

    // Fill in meaningful vertex positions
    m_floor->newVertex(-FLOOR_X_SIZE/2.0,  FLOOR_Y_POSITION, -FLOOR_Z_SIZE/2.0);
    m_floor->newVertex(-FLOOR_X_SIZE/2.0,  FLOOR_Y_POSITION,  FLOOR_Z_SIZE/2.0);
    m_floor->newVertex( FLOOR_X_SIZE/2.0,  FLOOR_Y_POSITION,  FLOOR_Z_SIZE/2.0);
    m_floor->newTriangle(0,1,2);

    m_floor->newVertex( FLOOR_X_SIZE/2.0,  FLOOR_Y_POSITION, -FLOOR_Z_SIZE/2.0);
    m_floor->newVertex(-FLOOR_X_SIZE/2.0,  FLOOR_Y_POSITION, -FLOOR_Z_SIZE/2.0);
    m_floor->newVertex( FLOOR_X_SIZE/2.0,  FLOOR_Y_POSITION,  FLOOR_Z_SIZE/2.0);
    m_floor->newTriangle(3,4,5);

    for(int n=0; n<6; n++)
    {
      cVertex* curVertex = m_floor->getVertex(n);
      curVertex->setNormal(0,1,0);
    }

    // Give him some material properties...
    cMaterial material;
    material.m_ambient.set( 0.2, 0.2, 0.2, 1.0 );
    material.m_diffuse.set( 0.6, 0.6, 0.6, 1.0 );
    material.m_specular.set( 0.9, 0.9, 0.9, 1.0 );
    material.setShininess(100);
    m_floor->m_material = material;

    // Create an initial ball
    CBall* b = new CBall();
    m_active_balls.push_back(b);
    cVector3d pos(-1.0,0,1.0);
    b->setPos(pos);
    world->addChild(b);

    // Create a series of masses connected by springs
    for(int i=1; i<INITIAL_NUM_BALLS; i++) {
      add_ball();
    }
    simulationOn = false;
}
Exemple #12
0
void TForm1::compute_spring_forces()
{
    double curtime = g_timer.GetTime();

    if (g_last_iteration_time < 0)
    {
      g_last_iteration_time = curtime;
      return;
    }

    double elapsed = curtime - g_last_iteration_time;
    g_last_iteration_time = curtime;

    unsigned int i;

    // Clear the force that's applied to each ball
    for(i=0; i<m_active_balls.size(); i++)
    {
        m_active_balls[i]->current_force.set(0,0,0);
    }

    if (simulationOn)
    {
        CBall* b = m_active_balls[0];
        cVector3d old_p = b->getPos();
        b->setPos(tool->m_deviceGlobalPos);
        b->m_velocity = cDiv(elapsed,cSub(b->getPos(),old_p));
    }

    // Compute the current length of each spring and apply forces
    // on each mass accordingly
    for(i=0; i<m_active_springs.size(); i++)
    {
        CSpring* s = m_active_springs[i];

        double d = cDistance(s->m_endpoint_1->getPos(),s->m_endpoint_2->getPos());
        s->m_current_length = d;

        // This spring's deviation from its rest length
        //
        // (positive deviation -> spring is too long)
        double x = s->m_current_length - s->m_rest_length;

        // Apply a force to ball 1 that pulls it toward ball 2
        // when the spring is too long
        cVector3d f1 = cMul(s->m_spring_constant*x*1.0,
          cSub(s->m_endpoint_2->getPos(),s->m_endpoint_1->getPos()));
        s->m_endpoint_1->current_force.add(f1);

        // Add the opposite force to ball 2
        s->m_endpoint_2->current_force.add(cMul(-1.0,f1));
    }

    // Update velocities and positions based on forces
    for(i=0; i<m_active_balls.size(); i++)
    {
        CBall* b = m_active_balls[i];

        // Certain forces don't get applied to the "haptic ball"
        // when haptics are enabled...
        if (simulationOn == 0 || i != 0) {
          cVector3d f_damping = cMul(DAMPING_CONSTANT,b->m_velocity);
          b->current_force.add(f_damping);
        }

        cVector3d f_gravity(0,GRAVITY_CONSTANT*b->m_mass,0);
        b->current_force.add(f_gravity);

        cVector3d p = b->getPos();

        if (p.y - b->m_radius < FLOOR_Y_POSITION) {
          double penetration = FLOOR_Y_POSITION - (p.y - b->m_radius);
          b->current_force.add(0,m_floor_spring_constant*penetration,0);
        }

        cVector3d f_floor(0,0,0);

        cVector3d a = cDiv(b->m_mass,b->current_force);

        b->m_velocity.add(cMul(elapsed,a));

        // We handle the 0th ball specially when haptics is enabled
        if (simulationOn == 0 || i != 0) {
          p.add(cMul(elapsed,b->m_velocity));
          b->setPos(p);
        }
    }

    // Set the haptic force appropriately to reflect the force
    // applied to ball 0
    m_haptic_force = cMul(HAPTIC_FORCE_CONSTANT,m_active_balls[0]->current_force);
}
Exemple #13
0
CBall* CBall::create() {
    CBall *obj = new CBall();
    obj->init();
    return obj;
}
Exemple #14
0
void CReplayManager::RestoreSnapshot()
{
	float watchDuration = gpGlobals->curtime - m_flReplayStartTime;

	if (watchDuration > m_flRunDuration)
	{
		if (m_nReplayRunIndex < m_nMaxReplayRuns - 1)
		{
			m_nReplayRunIndex += 1;
			m_bIsReplayStart = true;
		}
		else if (m_bIsHighlightReplay)
		{
			m_nReplayIndex = FindNextHighlightReplayIndex(m_nReplayIndex + 1, SDKGameRules()->State_Get());

			if (m_nReplayIndex == -1)
			{
				StopReplay();
				return;
			}

			m_nReplayRunIndex = 0;
			m_bIsReplayStart = true;
			m_bIsHighlightStart = true;
		}
		else
		{
			StopReplay();
			return;
		}
	}

	MatchEvent *pMatchEvent = m_MatchEvents[m_nReplayIndex];

	if (m_bIsReplayStart)
	{
		m_bIsReplayStart = false;
		m_bAtMinGoalPos = pMatchEvent->atMinGoalPos;
		m_bIsReplaying = true;
		m_bReplayIsPending = false;
		CalcMaxReplayRunsAndDuration(pMatchEvent, gpGlobals->curtime);
		watchDuration = 0;

		if (m_bIsHighlightReplay && m_bIsHighlightStart)
		{
			m_bIsHighlightStart = false;

			if (pMatchEvent->matchEventType == MATCH_EVENT_GOAL)
			{
				IGameEvent *pEvent = gameeventmanager->CreateEvent("highlight_goal");
				if (pEvent)
				{
					pEvent->SetInt("second", pMatchEvent->second);
					pEvent->SetInt("match_period", pMatchEvent->matchPeriod);
					pEvent->SetInt("scoring_team", pMatchEvent->team);
					pEvent->SetString("scorer", pMatchEvent->pPlayer1Data ? pMatchEvent->pPlayer1Data->m_szName : "");
					pEvent->SetString("first_assister", pMatchEvent->pPlayer2Data ? pMatchEvent->pPlayer2Data->m_szName : "");
					pEvent->SetString("second_assister", pMatchEvent->pPlayer3Data ? pMatchEvent->pPlayer3Data->m_szName : "");
					gameeventmanager->FireEvent(pEvent);
				}
			}
			else if (pMatchEvent->matchEventType == MATCH_EVENT_OWNGOAL)
			{
				IGameEvent *pEvent = gameeventmanager->CreateEvent("highlight_owngoal");
				if (pEvent)
				{
					pEvent->SetInt("second", pMatchEvent->second);
					pEvent->SetInt("match_period", pMatchEvent->matchPeriod);
					pEvent->SetInt("scoring_team", pMatchEvent->team);
					pEvent->SetString("scorer", pMatchEvent->pPlayer1Data ? pMatchEvent->pPlayer1Data->m_szName : "");
					gameeventmanager->FireEvent(pEvent);
				}
			}
			else if (pMatchEvent->matchEventType == MATCH_EVENT_MISS)
			{
				IGameEvent *pEvent = gameeventmanager->CreateEvent("highlight_miss");
				if (pEvent)
				{
					pEvent->SetInt("second", pMatchEvent->second);
					pEvent->SetInt("match_period", pMatchEvent->matchPeriod);
					pEvent->SetInt("finishing_team", pMatchEvent->team);
					pEvent->SetString("finisher", pMatchEvent->pPlayer1Data ? pMatchEvent->pPlayer1Data->m_szName : "");
					pEvent->SetString("first_assister", pMatchEvent->pPlayer2Data ? pMatchEvent->pPlayer2Data->m_szName : "");
					pEvent->SetString("second_assister", pMatchEvent->pPlayer3Data ? pMatchEvent->pPlayer3Data->m_szName : "");
					gameeventmanager->FireEvent(pEvent);
				}
			}
			else if (pMatchEvent->matchEventType == MATCH_EVENT_KEEPERSAVE)
			{
				IGameEvent *pEvent = gameeventmanager->CreateEvent("highlight_keepersave");
				if (pEvent)
				{
					pEvent->SetInt("second", pMatchEvent->second);
					pEvent->SetInt("match_period", pMatchEvent->matchPeriod);
					pEvent->SetInt("keeper_team", pMatchEvent->team);
					pEvent->SetString("keeper", pMatchEvent->pPlayer1Data ? pMatchEvent->pPlayer1Data->m_szName : "");
					pEvent->SetString("finisher", pMatchEvent->pPlayer2Data ? pMatchEvent->pPlayer2Data->m_szName : "");
					gameeventmanager->FireEvent(pEvent);
				}
			}
			else if (pMatchEvent->matchEventType == MATCH_EVENT_REDCARD)
			{
				IGameEvent *pEvent = gameeventmanager->CreateEvent("highlight_redcard");
				if (pEvent)
				{
					pEvent->SetInt("second", pMatchEvent->second);
					pEvent->SetInt("match_period", pMatchEvent->matchPeriod);
					pEvent->SetInt("fouling_team", pMatchEvent->team);
					pEvent->SetString("fouling_player", pMatchEvent->pPlayer1Data ? pMatchEvent->pPlayer1Data->m_szName : "");
					gameeventmanager->FireEvent(pEvent);
				}
			}
		}
	}

	CBall *pRealBall = GetMatchBall();
	if (pRealBall && !(pRealBall->GetEffects() & EF_NODRAW))
	{
		pRealBall->AddEffects(EF_NODRAW);
		pRealBall->AddSolidFlags(FSOLID_NOT_SOLID);
	}

	for (int i = 1; i <= gpGlobals->maxClients; i++)
	{
		CSDKPlayer *pRealPl = ToSDKPlayer(UTIL_PlayerByIndex(i));
		if (!CSDKPlayer::IsOnField(pRealPl))
			continue;

		if (!(pRealPl->GetEffects() & EF_NODRAW))
		{
			pRealPl->AddEffects(EF_NODRAW);
			pRealPl->DoServerAnimationEvent(PLAYERANIMEVENT_CANCEL);
			pRealPl->AddSolidFlags(FSOLID_NOT_SOLID);
			pRealPl->SetMoveType(MOVETYPE_NONE);
		}
		
		if (pRealPl->GetPlayerBall() && !(pRealPl->GetPlayerBall()->GetEffects() & EF_NODRAW))
		{
			pRealPl->GetPlayerBall()->AddEffects(EF_NODRAW);
			pRealPl->GetPlayerBall()->AddSolidFlags(FSOLID_NOT_SOLID);
		}
	}

	float normalRunDuration = m_flRunDuration - m_flSlowMoDuration;

	if (watchDuration > normalRunDuration)
		watchDuration = normalRunDuration + m_flSlowMoCoeff * (watchDuration - normalRunDuration);

	// To find the correct snapshot calculate the time passed since we started watching the replay and match it to the right snapshot in our recording list

	Snapshot *pNextSnap = NULL;
	Snapshot *pSnap = NULL;
	float snapDuration = 0;

	// Traverse backwards looking for a recorded snapshot matching the time since replay start
	for (int i = pMatchEvent->snapshots.Count() - 1; i >= 0; i--)
	{
		// Save the snapshot of the previous iteration, so we have a snapshot to interpolate to when we found our target snapshot
		pNextSnap = pSnap;

		// Save the current snapshot
		pSnap = pMatchEvent->snapshots[i];

		// Snapshots have absolute match times, so calculate the relative time span between the first recorded snapshot and the current snapshot
		snapDuration = pSnap->snaptime - pMatchEvent->snapshots[0]->snaptime - m_flReplayStartTimeOffset;

		// We usually only play the last x seconds of a replay instead of the whole thing, so subtract the start time offset from the time since the first snapshot.
		// The first snapshot which time span is equal or shorter than the duration since replay start is the one which should be shown next.
		if (snapDuration <= watchDuration)
			break;
	}

	// No snapshots in the list
	if (!pSnap)
		return;

	float nextSnapDuration;

	if (pNextSnap)
		nextSnapDuration = pNextSnap->snaptime - pMatchEvent->snapshots[0]->snaptime - m_flReplayStartTimeOffset;
	else
		nextSnapDuration = 0;

	BallSnapshot *pBallSnap = pSnap->pBallSnapshot;

	if (pBallSnap)
	{
		if (!m_pBall)
		{
			m_pBall = (CReplayBall *)CreateEntityByName("replayball");
			m_pBall->Spawn();
		}

		if (Q_strcmp(m_pBall->m_szSkinName, GetMatchBall()->GetSkinName()))
			Q_strncpy(m_pBall->m_szSkinName.GetForModify(), GetMatchBall()->GetSkinName(), MAX_KITNAME_LENGTH);

		m_pBall->VPhysicsGetObject()->SetPosition(pBallSnap->pos, pBallSnap->ang, false);
		m_pBall->VPhysicsGetObject()->SetVelocity(&pBallSnap->vel, &pBallSnap->rot);
	}
	else
	{
		UTIL_Remove(m_pBall);
		m_pBall = NULL;
	}

	float frac;

	if (pNextSnap)
	{
		// Calc fraction between both snapshots
		frac = clamp((watchDuration - snapDuration) / (nextSnapDuration - snapDuration), 0.0f, 1.0f);
	}
	else
	{
		// Exact snapshot time matched or no next snapshot to interpolate to
		frac = 0.0f;
	}

	for (int i = 0; i < 2; i++)
	{
		for (int j = 0; j < 11; j++)
		{
			PlayerSnapshot *pPlSnap = pSnap->pPlayerSnapshot[i][j];
			if (!pPlSnap)
			{
				UTIL_Remove(m_pPlayers[i][j]);
				m_pPlayers[i][j] = NULL;
				continue;
			}

			if (!m_pPlayers[i][j])
			{
				m_pPlayers[i][j] = (CReplayPlayer *)CreateEntityByName("replayplayer");
				m_pPlayers[i][j]->Spawn();
				m_pPlayers[i][j]->SetNumAnimOverlays(NUM_LAYERS_WANTED);
			}

			CReplayPlayer *pPl = m_pPlayers[i][j];

			pPl->m_nTeamNumber = pPlSnap->teamNumber;
			pPl->m_nTeamPosIndex = pPlSnap->teamPosIndex;
			pPl->m_bIsKeeper = pPlSnap->isKeeper;
			pPl->m_nShirtNumber = pPlSnap->shirtNumber;

			if (Q_strcmp(pPl->m_szPlayerName, pPlSnap->pPlayerData->m_szName))
				Q_strncpy(pPl->m_szPlayerName.GetForModify(), pPlSnap->pPlayerData->m_szName, MAX_PLAYER_NAME_LENGTH);

			if (Q_strcmp(pPl->m_szShirtName, pPlSnap->pPlayerData->m_szShirtName))
				Q_strncpy(pPl->m_szShirtName.GetForModify(), pPlSnap->pPlayerData->m_szShirtName, MAX_PLAYER_NAME_LENGTH);

			pPl->m_nSkinIndex = pPlSnap->skinIndex;
			pPl->m_nBody = pPlSnap->body;

			PlayerSnapshot *pNextPlSnap = NULL;

			if (pNextSnap)
				pNextPlSnap = pNextSnap->pPlayerSnapshot[i][j];

			if (frac > 0.0f && pNextPlSnap)
			{
				pPl->SetLocalOrigin(Lerp( frac, pPlSnap->pos, pNextPlSnap->pos  ));
				//pPl->SetLocalVelocity(Lerp( frac, pPlSnap->vel, pNextPlSnap->vel  ));
				pPl->SetLocalAngles(Lerp( frac, pPlSnap->ang, pNextPlSnap->ang ));
			}
			else
			{
				pPl->SetLocalOrigin(pPlSnap->pos);
				//pPl->SetLocalVelocity(pPlSnap->vel);
				pPl->SetLocalAngles(pPlSnap->ang);
			}

			bool interpolationAllowed;

			if (frac > 0.0f && pNextPlSnap && pPlSnap->masterSequence == pNextPlSnap->masterSequence)
			{
				// If the master state changes, all layers will be invalid too, so don't interp (ya know, interp barely ever happens anyway)
				interpolationAllowed = true;
			}
			else
				interpolationAllowed = false;

			// First do the master settings
			if (interpolationAllowed)
			{
				pPl->SetSequence( Lerp( frac, pPlSnap->masterSequence, pNextPlSnap->masterSequence ) );
				pPl->SetCycle( Lerp( frac, pPlSnap->masterCycle, pNextPlSnap->masterCycle ) );

				if( pPlSnap->masterCycle > pNextPlSnap->masterCycle )
				{
					// the older record is higher in frame than the newer, it must have wrapped around from 1 back to 0
					// add one to the newer so it is lerping from .9 to 1.1 instead of .9 to .1, for example.
					float newCycle = Lerp( frac, pPlSnap->masterCycle, pNextPlSnap->masterCycle + 1 );
					pPl->SetCycle(newCycle < 1 ? newCycle : newCycle - 1 );// and make sure .9 to 1.2 does not end up 1.05
				}
				else
				{
					pPl->SetCycle( Lerp( frac, pPlSnap->masterCycle, pNextPlSnap->masterCycle ) );
				}

				pPl->SetPoseParameter(pPl->GetModelPtr(), 4, Lerp(frac, pPlSnap->moveX, pNextPlSnap->moveX));
				pPl->SetPoseParameter(pPl->GetModelPtr(), 3, Lerp(frac, pPlSnap->moveY, pNextPlSnap->moveY));
			}
			else
			{
				pPl->SetSequence(pPlSnap->masterSequence);
				pPl->SetCycle(pPlSnap->masterCycle);
				pPl->SetPoseParameter(pPl->GetModelPtr(), 4, pPlSnap->moveX);
				pPl->SetPoseParameter(pPl->GetModelPtr(), 3, pPlSnap->moveY);
			}

			// Now do all the layers
			for (int layerIndex = 0; layerIndex < NUM_LAYERS_WANTED; layerIndex++)
			{
				CAnimationLayer *pTargetLayer = pPl->GetAnimOverlay(layerIndex);
				if(!pTargetLayer)
					continue;

				LayerRecord *pSourceLayer = &pPlSnap->layerRecords[layerIndex];

				pTargetLayer->m_nOrder = pSourceLayer->order;
				pTargetLayer->m_nSequence = pSourceLayer->sequence;
				pTargetLayer->m_flPlaybackRate = pSourceLayer->playbackRate;
				pTargetLayer->m_fFlags = pSourceLayer->flags;
				pTargetLayer->m_bLooping = pSourceLayer->looping;
				pTargetLayer->m_bSequenceFinished = pSourceLayer->sequenceFinished;
				pTargetLayer->m_nPriority = pSourceLayer->priority;
				pTargetLayer->m_nActivity = pSourceLayer->activity;
				pTargetLayer->m_flLastAccess = pSourceLayer->lastAccess;
				pTargetLayer->m_flLastEventCheck = pSourceLayer->lastEventCheck;

				if (interpolationAllowed)
				{
					LayerRecord *pNextSourceLayer = &pNextPlSnap->layerRecords[layerIndex];

					if(pSourceLayer->order == pNextSourceLayer->order && pSourceLayer->sequence == pNextSourceLayer->sequence)
					{
						// We can't interpolate across a sequence or order change
						if( pSourceLayer->cycle > pNextSourceLayer->cycle )
						{
							// the older record is higher in frame than the newer, it must have wrapped around from 1 back to 0
							// add one to the newer so it is lerping from .9 to 1.1 instead of .9 to .1, for example.
							float newCycle = Lerp( frac, pSourceLayer->cycle, pNextSourceLayer->cycle + 1 );
							pTargetLayer->m_flCycle = newCycle < 1 ? newCycle : newCycle - 1;// and make sure .9 to 1.2 does not end up 1.05
						}
						else
						{
							pTargetLayer->m_flCycle = Lerp(frac, pSourceLayer->cycle, pNextSourceLayer->cycle);
						}

						pTargetLayer->m_flWeight = Lerp(frac, pSourceLayer->weight, pNextSourceLayer->weight);
						pTargetLayer->m_flLayerAnimtime = Lerp(frac, pSourceLayer->layerAnimtime, pNextSourceLayer->layerAnimtime);
						pTargetLayer->m_flBlendIn = Lerp(frac, pSourceLayer->blendIn, pNextSourceLayer->blendIn);
						pTargetLayer->m_flBlendOut = Lerp(frac, pSourceLayer->blendOut, pNextSourceLayer->blendOut);
						pTargetLayer->m_flPrevCycle = Lerp(frac, pSourceLayer->prevCycle, pNextSourceLayer->prevCycle);
						pTargetLayer->m_flKillDelay = Lerp(frac, pSourceLayer->killDelay, pNextSourceLayer->killDelay);
						pTargetLayer->m_flKillRate = Lerp(frac, pSourceLayer->killRate, pNextSourceLayer->killRate);
						pTargetLayer->m_flLayerFadeOuttime = Lerp(frac, pSourceLayer->layerFadeOuttime, pNextSourceLayer->layerFadeOuttime);
					}
				}
				else
				{
					//Either no interp, or interp failed.  Just use record.
					pTargetLayer->m_flCycle = pSourceLayer->cycle;
					pTargetLayer->m_flWeight = pSourceLayer->weight;
					pTargetLayer->m_flLayerAnimtime = pSourceLayer->layerAnimtime;
					pTargetLayer->m_flBlendIn = pSourceLayer->blendIn;
					pTargetLayer->m_flBlendOut = pSourceLayer->blendOut;
					pTargetLayer->m_flPrevCycle = pSourceLayer->prevCycle;
					pTargetLayer->m_flKillDelay = pSourceLayer->killDelay;
					pTargetLayer->m_flKillRate = pSourceLayer->killRate;
					pTargetLayer->m_flLayerFadeOuttime = pSourceLayer->layerFadeOuttime;
				}
			}
		}
	}
}
Exemple #15
0
void CReplayManager::StopReplay()
{
	if (m_bReplayIsPending)
		m_bReplayIsPending = false;

	if (!m_bIsReplaying)
		return;

	m_bIsReplaying = false;

	if (m_pBall)
	{
		UTIL_Remove(m_pBall);
		m_pBall = NULL;
	}

	for (int i = 0; i < 2; i++)
	{
		for (int j = 0; j < 11; j++)
		{
			if (m_pPlayers[i][j])
			{
				UTIL_Remove(m_pPlayers[i][j]);
				m_pPlayers[i][j] = NULL;
			}
		}
	}

	if (IsMarkedForDeletion())
		return;

	CBall *pRealBall = GetMatchBall();
	if (pRealBall)
	{
		//pRealBall->SetRenderMode(kRenderNormal);
		//pRealBall->SetRenderColorA(255);
		pRealBall->RemoveEffects(EF_NODRAW);
		pRealBall->RemoveSolidFlags(FSOLID_NOT_SOLID);
	}

	for (int i = 1; i <= gpGlobals->maxClients; i++)
	{
		CSDKPlayer *pRealPl = ToSDKPlayer(UTIL_PlayerByIndex(i));
		if (!CSDKPlayer::IsOnField(pRealPl))
			continue;

		//pRealPl->SetRenderMode(kRenderNormal);
		//pRealPl->SetRenderColorA(255);
		pRealPl->SetLocalOrigin(pRealPl->GetSpawnPos());
		QAngle ang;
		VectorAngles(Vector(0, pRealPl->GetTeam()->m_nForward, 0), ang);
		pRealPl->SetLocalAngles(ang);
		pRealPl->SnapEyeAngles(ang);
		pRealPl->SetLocalVelocity(vec3_origin);
		pRealPl->RemoveEffects(EF_NODRAW);
		//pRealPl->RemoveEFlags(EFL_NOCLIP_ACTIVE);
		pRealPl->SetMoveType(MOVETYPE_WALK);
		pRealPl->RemoveSolidFlags(FSOLID_NOT_SOLID);

		if (pRealPl->GetPlayerBall())
		{
			pRealPl->GetPlayerBall()->RemoveEffects(EF_NODRAW);
			pRealPl->GetPlayerBall()->RemoveSolidFlags(FSOLID_NOT_SOLID);
		}
	}

	if (SDKGameRules()->IsIntermissionState())
	{
		IGameEvent *pEvent = gameeventmanager->CreateEvent("match_period");
		if (pEvent)
		{
			pEvent->SetInt("period", SDKGameRules()->State_Get());
			gameeventmanager->FireEvent(pEvent);
		}
	}
}
Exemple #16
0
//--------------------------------------------------------------------
// Función:    CParticles::Update
// Creador:    Nacho (AMD)
// Fecha:      Wednesday  14/02/2007  19:48:41
//--------------------------------------------------------------------
void CParticles::Update(float dt, CLevel* pTheLevel, CSound* pSoundPlayer)
{	
	CVideo * pVideo = CVideo::GetSingleton();

	m_fAngType3 += (240.0f * dt);
	m_fAngType3 = MAT_NormalizarAngulo360(m_fAngType3);

	CBall* pBall = pTheLevel->GetBall();
	CSmoke* pSmoke = pTheLevel->GetSmoke();

	VECTOR3 vecBallPos = pBall->GetPosition();
	VECTOR2 vecBallVel = pBall->GetVelocity();
	float fBallRadius = pBall->GetRadius();

	sceGuEnable(GU_BLEND);
	sceGuBlendFunc(GU_ADD, GU_SRC_ALPHA, GU_ONE_MINUS_SRC_ALPHA, 0, 0);
	sceGuTexFunc(GU_TFX_MODULATE, GU_TCC_RGBA);

	ENEMY* pEnemies = pTheLevel->GetEnemies();
	int iNumEnemies = pTheLevel->GetNumEnemies();
	
	///--- TIPO 0: Disparo amarillo
	//////////////////////////////////////////////////////////////////////

	pVideo->EnableTexture(m_pTexture[0]);

	for (int i=0; i<MAX_PARTICLES; i++)
	{
		if (m_pParticleArray[0][i].enable)
		{			
			m_pParticleArray[0][i].timeStamp += dt;

			if (m_pParticleArray[0][i].timeStamp >= 5.0f)
			{
				m_pParticleArray[0][i].enable = false;
				m_pParticleArray[0][i].next = m_iFreeSlot[0];
				m_iFreeSlot[0] = i;

				continue;
			}

			m_pParticleArray[0][i].pos.x += m_pParticleArray[0][i].vel.x * dt;
			m_pParticleArray[0][i].pos.y += m_pParticleArray[0][i].vel.y * dt;


			stCollisionData data;

			data.radius = 1.0f;
			data.x = m_pParticleArray[0][i].pos.x;
			data.y = m_pParticleArray[0][i].pos.y;
			data.velX = m_pParticleArray[0][i].vel.x;
			data.velY = m_pParticleArray[0][i].vel.y;

			if (pTheLevel->TestCollision(&data, false))
			{		
				m_pParticleArray[0][i].pos.x = data.x;
				m_pParticleArray[0][i].pos.y = data.y;
				m_pParticleArray[0][i].vel.x = data.velX;
				m_pParticleArray[0][i].vel.y = data.velY;
			}

			for (int a=0; a<iNumEnemies; a++)
			{
				if (pEnemies[a].active)
				{					
					///--- sierra
					///--- rebota
					if ((pEnemies[a].type == 0) || (pEnemies[a].type == 3))
					{
						VECTOR3 vDis;
						VECTOR3 vTemp = {m_pParticleArray[0][i].pos.x, m_pParticleArray[0][i].pos.y, 4.0f};
						VECTOR3 vTemp2 = {pEnemies[a].posX + 4.0f, pEnemies[a].posY + 4.0f, 4.0f};

						MAT_VectorSubtract(&vDis, &vTemp2, &vTemp);

						float length = MAT_VectorQuadraticLength(&vDis);

						if (length < 6.25f)
						{
							m_pParticleArray[0][i].enable = false;
							m_pParticleArray[0][i].next = m_iFreeSlot[0];
							m_iFreeSlot[0] = i;

							pSmoke->AddExplosion(vTemp2, 20.0f, true);

							pEnemies[a].active = false;

							pSoundPlayer->Play(SOUND_ENE_EXPLO);

							break;
						}
					}
					///--- dirigidos
					///--- rectos
					else if ((pEnemies[a].type == 1) || (pEnemies[a].type == 2))
					{	
						VECTOR3 vTemp = {0};

						if (pEnemies[a].rot==0)
						{
							vTemp.x = pEnemies[a].posX+2.0f;
							vTemp.y = pEnemies[a].posY+4.0f;
						}						
						else if (pEnemies[a].rot==3)
						{
							vTemp.x = pEnemies[a].posX+4.0f;
							vTemp.y = pEnemies[a].posY+2.0f;
						}
						else if (pEnemies[a].rot==2)
						{
							vTemp.x = pEnemies[a].posX+6.0f;
							vTemp.y = pEnemies[a].posY+4.0f;
						}
						else if (pEnemies[a].rot==1)
						{
							vTemp.x = pEnemies[a].posX+4.0f;
							vTemp.y = pEnemies[a].posY+6.0f;						
						}	

						vTemp.z = 4.0f;

						VECTOR3 vDis;
						VECTOR3 vTemp2 = {m_pParticleArray[0][i].pos.x, m_pParticleArray[0][i].pos.y, 4.0f};
						
						MAT_VectorSubtract(&vDis, &vTemp, &vTemp2);

						float disx = vecBallPos.x - m_pParticleArray[0][i].pos.x,;

						float length = MAT_VectorQuadraticLength(&vDis);

						if (length < 6.0f)
						{
							m_pParticleArray[0][i].enable = false;
							m_pParticleArray[0][i].next = m_iFreeSlot[0];
							m_iFreeSlot[0] = i;

							pSmoke->AddExplosion(vTemp, 20.0f, true);

							pEnemies[a].active = false;

							pSoundPlayer->Play(SOUND_ENE_EXPLO);

							int pan = 127;

							if (disx < 0.0f)
							{
								if (disx < -32.0f)
								{
									pan = 255;
								}
								else
								{
									pan = MAT_Clamp(128 + (int)(((-disx) / 32.0f) * 127.0f), 128, 255);									
								}
							}
							else

							{
								if (disx > 32.0f)
								{
									pan = 0;
								}
								else
								{ 
									pan = MAT_Clamp((int)(127.0f - ((disx / 32.0f) * 127.0f)), 0, 127);
								}
							}

							pSoundPlayer->Play(SOUND_ENE_EXPLO, pan);

							break;
						}						
					}				
				}
			}

			if (!m_pParticleArray[0][i].enable)
				continue;

			///--- render

			sceGumMatrixMode(GU_MODEL);
			sceGumLoadIdentity();
			{
				VECTOR3 pos =  { m_pParticleArray[0][i].pos.x -1.0f,
					-(m_pParticleArray[0][i].pos.y + 1.0f), 4.0f };
				VECTOR3 scale = { 2.0f, 2.0f, 2.0f };
				sceGumTranslate(&pos);
				sceGumScale(&scale);			
			}			

			if (m_pParticleArray[0][i].timeStamp >= 4.0f)
			{
				int alpha = (int)MAT_Clampf((5.0f - m_pParticleArray[0][i].timeStamp) * 255.0f, 0.0f, 255.0f);

				sceGuBlendFunc(GU_ADD, GU_SRC_ALPHA, GU_ONE_MINUS_SRC_ALPHA, 0, 0);

				sceGuAmbientColor(COLOR_ARGB(alpha, 255, 255, 255));

				m_pQuad->Render();

				sceGuBlendFunc(GU_ADD, GU_FIX, GU_FIX, COLOR_ARGB(alpha, alpha, alpha, alpha), 0xffffffff);

				m_pQuad->Render();

				sceGuAmbientColor(0xffffffff);
			}
			else
			{
				sceGuAmbientColor(0xffffffff);

				m_pQuad->Render();

				sceGuBlendFunc(GU_ADD, GU_FIX, GU_FIX, 0xffffffff, 0xffffffff);

				m_pQuad->Render();
			}

			sceGuBlendFunc(GU_ADD, GU_SRC_ALPHA, GU_ONE_MINUS_SRC_ALPHA, 0, 0);			
		}