当前位置: 首页>>代码示例>>C++>>正文


C++ Physics::getPosition方法代码示例

本文整理汇总了C++中Physics::getPosition方法的典型用法代码示例。如果您正苦于以下问题:C++ Physics::getPosition方法的具体用法?C++ Physics::getPosition怎么用?C++ Physics::getPosition使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Physics的用法示例。


在下文中一共展示了Physics::getPosition方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: apply_fun

void GravitationalForce::apply_fun(float d_t){
	for (unsigned int i = 0; i < mInfluencedPhysics.size()-1; i++){
		Physics* lhs = mInfluencedPhysics[i];
		for (unsigned int j = i+1 ; j < mInfluencedPhysics.size(); j++){
			Physics* rhs = mInfluencedPhysics[j];
			Vector3 distanceVector = rhs->getPosition()-lhs->getPosition();
			float distance = distanceVector.length();
			//Distanz in Ordnung
			if (distance < getMaxDistance() && distance >= 1.0){
				if(distance < 1){
					distance = 1;
				}
				distanceVector.normalize();
				//Anziehungskraft berechnen
				float force = mScale * (rhs->getMass()*lhs->getMass() / (distance*distance));
				//Anziehungskraft in Ordnung
				if (force > getMinForce()){
					Vector3 Rhs_forceVector = distanceVector;
					Rhs_forceVector *= force;
					//Anziehungskraft um d_t skaliert anwenden
					lhs->applyForce(Rhs_forceVector*d_t);
					Vector3 Lhs_forceVector = (-1.0) * distanceVector;
					Lhs_forceVector *= force;
					//Anziehungskraft um d_t skaliert anwenden
					rhs->applyForce(Lhs_forceVector*d_t);
				}
			}
		}
	}
}
开发者ID:Secumfex,项目名称:AniSimProjekt,代码行数:30,代码来源:Forces.cpp

示例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));
            }
        }
//.........这里部分代码省略.........
开发者ID:DirkLaserblast,项目名称:Goldenrod_Engine,代码行数:101,代码来源:main.cpp


注:本文中的Physics::getPosition方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。