本文整理汇总了C++中Physics::setSpeed方法的典型用法代码示例。如果您正苦于以下问题:C++ Physics::setSpeed方法的具体用法?C++ Physics::setSpeed怎么用?C++ Physics::setSpeed使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Physics
的用法示例。
在下文中一共展示了Physics::setSpeed方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: launchBall
//Start the ball moving using direction and power from GLUI input
void launchBall(int i){
ballMoving = true;
launchAngleRadians = (float) launchAngle * (PI/180);
launchVector = normalize(vec3(sin(launchAngleRadians), 0.0, cos(launchAngleRadians)));
Level *currentLevel = levelController->getCurrentLevel();
Ball *ball = currentLevel->getBall();
Physics *physics = ball->getPhysics();
puttSFX(physics->getSpeed(), sound);
float prevY = physics->getDirection().y;
physics->setDirection(glm::vec3(launchVector.x, prevY, launchVector.z));
// If new tile is flat make sure no y-component
if(levelController->getCurrentLevel()->getTile(ball->getCurrentTileID())->getShapes().at(0)->normals()[0] == glm::vec3(0.0,1.0,0.0)){
physics->setDirection(
glm::vec3(physics->getDirection().x, 0.0, physics->getDirection().z));
}
// If new tile is not flat add y-component
else{
glm::vec3 oldDirection = physics->getDirection();
glm::vec3 upVector = glm::vec3(0.0,1.0,0.0);
// Get current tile normal
glm::vec3 tileNormal = levelController->getCurrentLevel()->getTile(ball->getCurrentTileID())->getShapes().at(0)->normals()[0];
glm::vec3 xVector = glm::cross(oldDirection, upVector);
glm::vec3 newDirection = glm::normalize(glm::cross(tileNormal, xVector));
physics->setDirection(newDirection);
}
physics->setSpeed(launchPower/100.1f);
// Increment current hole score and update glui
currentHoleScore++;
numStrokes->set_int_val(currentHoleScore);
angleSpinner->disable();
powerSpinner->disable();
fireButton->disable();
}
示例2: tick
// Run by GLUT every [tickspeed] miliseconds
void tick(int in)
{
// Local handles to objects
Level *currentLevel = levelController->getCurrentLevel();
Ball *ball = currentLevel->getBall();
Physics *physics = ball->getPhysics();
Tile* currentTile = currentLevel->getTile(ball->getCurrentTileID());
vector<int> borderIDs = currentTile->getNeighborIDs();
vector<Shape*> borderShapes = currentTile->getBorders()->getInwardShapes();
vec3 ballPosition = physics->getPosition();
// Debug -- Highlight current tile
if (DEBUG_TILE_PAINT)
{
currentTile->getShapes()[0]->changeColor(TILE_HIGHLIGHT_COLOR);
currentTile->getShapes()[0]->reload();
}
// Collision with cup
glm::vec3 ballPos = physics->getPosition();
glm::vec3 cupPos = currentLevel->getCup()->getPhysics()->getPosition();
float cupPlaneDist = sqrt(((ballPos.x - cupPos.x)*(ballPos.x - cupPos.x)) + ((ballPos.z - cupPos.z)*(ballPos.z - cupPos.z)));
if(cupPlaneDist < (CUP_RADIUS - (0.8 * BALL_RADIUS)) && abs(cupPos.y - ballPos.y) <= 1.1*BALL_OFFSET){ // allow for slight error
//Play SFX for falling in hole
sound->getEngine()->play2D("sfx/retro_cup.wav");
//----------------CHANGE TO NEXT HOLE----------------//
nextHole();
}
// Physics and collision calculations
vec3 newDirection = physics->getDirection(); // used for tile transitions
if(ballMoving)
{
// Check for collision
if(detectCollisions(currentTile, physics, sound)){
newDirection = physics->getDirection();
}
// Update ball direction
newDirection = updateBallDirection(levelController, sound);
// Update current tile
currentTile = currentLevel->getTile(ball->getCurrentTileID());
// Update ball speed
double ballSpeed = physics->getSpeed();
if(currentTile->getShapes().at(0)->normals()[0] == glm::vec3(0.0,1.0,0.0)){ // flat tile
if(ballSpeed > 0.01){
physics->setSpeed(ballSpeed - TILE_DEFAULT_FRICTION);
ballSpeed = physics->getSpeed();
}
else{
physics->setSpeed(0.0);
ballStopped();
}
}
else if(newDirection.y > 0){ // going up hill
//cout << endl << "UP";
//cout << "Direction y-value: " << newDirection.y << endl;
if(ballSpeed > 0.01){
physics->setSpeed(ballSpeed - (TILE_DEFAULT_FRICTION + (2.0*currentTile->getSlope()*TILE_DEFAULT_FRICTION)));
ballSpeed = physics->getSpeed();
}
}
else{ // going down hill
//cout << endl << "DOWN";
//cout << "Direction y-value: " << newDirection.y << endl;
if(ballSpeed <= (100.0/100.1)){
physics->setSpeed(ballSpeed + TILE_DEFAULT_FRICTION);
}
else{ // clmap speed
ballSpeed = (100.0/100.1);
}
}
// Update ballPosition
physics->updatePosition();
// Update shape using velocity
Shape* ballShape = ball->getShapes().at(0);
ballShape->translate(physics->getVelocity());
// Update ball direction
physics->setDirection(newDirection);
// Snap ball to correct y value -- hacky
if(currentTile->getShapes().at(0)->normals()[0] == glm::vec3(0.0,1.0,0.0)){ // flat tile
if(physics->getPosition().y != (currentTile->getPhysics()->getPosition().y + BALL_OFFSET)){
// Snap ball shape
ball->getShapes()[0]->translate(vec3(0.0, -(physics->getPosition().y), 0.0));
ball->getShapes()[0]->translate(vec3(0.0, (currentTile->getPhysics()->getPosition().y + BALL_OFFSET), 0.0));
// Update ball physics
physics->setPosition(vec3(physics->getPosition().x, (currentTile->getPhysics()->getPosition().y + BALL_OFFSET), physics->getPosition().z));
}
}
//.........这里部分代码省略.........