示例#1
0
int main(int argc, char **argv) {

  // create a simulator
  simphys::SimEngine sim;

  auto clock_ptr = std::make_shared< simphys::Clock<fseconds> >(fseconds{0.0f});
  clock_ptr->setScale(0.01f);
  sim.setClock(clock_ptr);

  // create a world to simulate
  auto world_ptr = std::make_shared<simphys::SimWorld>(); 
  sim.setSimWorld(world_ptr);

  // create and initialize an object
  simphys::Particle p;
  simphys::Sprite s;
  simphys::SimObject2D testObject(p,s);
  auto obj_ptr = std::make_shared<simphys::SimObject2D>(testObject);
  auto objState = testObject.getState();
  objState->setPosition(simphys::vec3{40, 50, 0});
  objState->setVelocity(simphys::vec3{50.0, 100.0, 0});
  objState->setAcceleration(simphys::vec3{0, -20.0, 0});
  objState->setMass(10000.0f);
  
  // create and initialize another object
  simphys::Particle p2;
  simphys::Sprite s2;
  simphys::SimObject2D testObject2(p2,s2);
  auto obj_ptr2 = std::make_shared<simphys::SimObject2D>(testObject2);
  auto objState2 = testObject2.getState();
  objState2->setPosition(simphys::vec3{550, 50, 0});
  objState2->setVelocity(simphys::vec3{-50.0, 100.0, 0});
  objState2->setAcceleration(simphys::vec3{0, -20.0, 0});
  objState2->setMass(100.0f);
  objState2->setColor(1.0f,0.0f,0.0f);
  objState2->setRadius(45.0f);
  
  // Command line velocity setting
  if( argc == 4 )
  {
  	objState->setVelocity(simphys::vec3{ float(atof(argv[1])), float(atof(argv[2])), 0});
  	objState2->setVelocity(simphys::vec3{ float(atof(argv[1]) * -1), float(atof(argv[2])), 0});
  }
  if( argc == 3 )
  {
  	objState->setVelocity(simphys::vec3{ float(atof(argv[1])), float(atof(argv[2])), 0});
  	objState2->setVelocity(simphys::vec3{ float(atof(argv[1]) * -1), float(atof(argv[2])), 0});
  }

  // add objects to the world.
  world_ptr->add(obj_ptr);
  world_ptr->add(obj_ptr2);

  // initialize the simulator and run it.
  sim.init();
  sim.run();

}
示例#2
0
//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
void 
PhysicsActor::SetStatic(bool _isStatic = false)
{
	m_IsStatic = _isStatic;
	if (_isStatic)
	{
		setMass(0);
	}
	else
		setMass(m_mass);
}
示例#3
0
Balloon* Balloon::create(Point* pos)
{
    Balloon* b = new Balloon();

    if (b && b->initWithFile("balloon.png"))
    {
        // Set auto release.
        b->autorelease();
        // Set Scale
        b->setScale(0.15f);

        // CHANGE TO A DEFINED NUMBER AFTER
        b->setTag(0);
        auto body = PhysicsBody::createCircle(b->getBoundingBox().size.width/2.5f);
        body->setMass(1);
        body->setDynamic(true);
        b->setPhysicsBody(body);

        // Set Position
        b->setPosition(*pos);

        // Setup Event Listener
        //b->input();

        b->schedule(schedule_selector(Balloon::update));

        return b;
    }
    CC_SAFE_DELETE(b);

    return NULL;
}
示例#4
0
void GameLayer::createPips() {
    // Create the pips
    for (int i = 0; i < PIP_COUNT; i++) {
        Size visibleSize = Director::getInstance()->getVisibleSize();
        Sprite *pipUp = Sprite::createWithSpriteFrame(AtlasLoader::getInstance()->getSpriteFrameByName("pipe_up"));
        Sprite *pipDown = Sprite::createWithSpriteFrame(AtlasLoader::getInstance()->getSpriteFrameByName("pipe_down"));
        Node *singlePip = Node::create();
        
        // bind to pair
        pipDown->setPosition(0, PIP_HEIGHT + PIP_DISTANCE);
		singlePip->addChild(pipDown, 0, DOWN_PIP);
        singlePip->addChild(pipUp, 0, UP_PIP);
        singlePip->setPosition(visibleSize.width + i*PIP_INTERVAL + WAIT_DISTANCE, this->getRandomHeight());
		auto body = PhysicsBody::create();
		auto shapeBoxDown = PhysicsShapeBox::create(pipDown->getContentSize(),PHYSICSSHAPE_MATERIAL_DEFAULT, Point(0, PIP_HEIGHT + PIP_DISTANCE));
		body->addShape(shapeBoxDown);
		body->addShape(PhysicsShapeBox::create(pipUp->getContentSize()));
		body->setDynamic(false);
        body->setMass(1.0f);
        body->setContactTestBitmask(0xFFFFFFFF);
		singlePip->setPhysicsBody(body);
        singlePip->setTag(PIP_NEW);
        
        
        this->addChild(singlePip);
        this->pips.push_back(singlePip);
    }
}
示例#5
0
Balloon* Balloon::createWithForce(Point* pos, Point* force)
{
    Balloon* b = new Balloon();

    if (b && b->initWithFile("balloon.png"))
    {
        // Set auto release.
        b->autorelease();
        // Set Scale
        b->setScale(0.15f);

        // Set Position
        b->setPosition(*pos);

        // CHANGE TO A DEFINED NUMBER AFTER
        //this->setTag(0);
        auto body = PhysicsBody::createCircle(b->getBoundingBox().size.width/2.5f);
        body->setMass(1);
        body->setDynamic(true);
        body->setContactTestBitmask(2);
        body->setCategoryBitmask(0x01); //0001
        b->setPhysicsBody(body);

        // give forces
        b->getPhysicsBody()->applyImpulse(*force);

        b->schedule(schedule_selector(Balloon::update));

        return b;
    }
    CC_SAFE_DELETE(b);

    return NULL;
}
Sun::Sun(double x, double y, float _radius, sf::Color _colour, float _rotation) : AstroObject(x, y, _radius, _colour, _rotation) {
	setMass(_radius * 9.3 * 10);
	setHabitable(false);
	//circle.setRadius(_radius);
	//circle.setPointCount(100);
	//circle.setFillColor(_colour);
}
示例#7
0
BSPSceneObject::BSPSceneObject(char * filename, int curveTesselation) : RigidSceneObject()
{
	hasVisibility = true;
	
	bspObject = new BSP();
	bspObject->Load(filename,curveTesselation);
	bspObject->buildSingleCluster();
	
	bind(bspObject->clusterObject);
	
	//		bspObject->disableVIS(true);
	//		bspObject->showAll(true);
	
	setMass(0);
	setMargin(0.01f);
	createRigidBody();
	mRigidBody->setActivationState(WANTS_DEACTIVATION); 
	
	segmentMask = new BITSET;
	segmentMask->Init(bspObject->clusterObject.numSegments);
	segmentMask->SetAll();
	
//	createRigidBody();
//	colShape->setMargin(0.005);
}
	void updateComponent(Entity &entity, SmartPointer<Component::SpaceshipController> c, double time)
	{
			c->resetControls();
			auto &inputs = _scene->getEngine().getInstance<Input>();
			auto &controls = c->getControls();
			auto &keys = c->getKeys();

			float yAngle = inputs.getMouseDelta().y * 0.3f;
			float xAngle = - inputs.getMouseDelta().x * 0.3f;

			entity->setLocalTransform() = glm::rotate(entity->getLocalTransform(), yAngle, glm::vec3(1, 0, 0));
			entity->setLocalTransform() = glm::rotate(entity->getLocalTransform(), xAngle, glm::vec3(0, 1, 0));

			// UPDATE KEYS
			for (unsigned int i = 0; i < controls.size(); ++i)
			{
				controls[i] = inputs.getKey(keys[i]);
			}

			auto forwardDir = glm::vec3(0,0,1);
			auto upDir = glm::vec3(0,1,0);
			auto sideDir = glm::vec3(1,0,0);


			glm::vec3 direction = glm::vec3(0);
			if (controls[Component::SpaceshipController::LEFT])
				direction += sideDir * (float)(10.0f * time);

			if (controls[Component::SpaceshipController::RIGHT])
				direction -= sideDir * (float)(10.0f * time);

			if (controls[Component::SpaceshipController::FORWARD])
				direction += forwardDir * (float)(10.0f * time);

			if (controls[Component::SpaceshipController::BACKWARD])
				direction -= forwardDir * (float)(10.0f * time);
			static std::vector<Entity> balls;

			if (controls[Component::SpaceshipController::SHOOT])
			{
				Entity b = _scene->createEntity();
				b->setLocalTransform() = entity->getLocalTransform();
				b->addComponent<Component::GraphNode>();
				auto rigidBody = b->addComponent<Component::RigidBody>();
				rigidBody->setMass(1.0f);
				rigidBody->setCollisionShape(Component::RigidBody::SPHERE);
//				rigidBody->getBody().applyCentralImpulse(btVector3(0, 0, 1000));
				auto mesh = b->addComponent<Component::MeshRenderer>("model:ball");
				mesh->setShader("MaterialBasic");
//				_scene->destroy(b);
				balls.push_back(b);
			}
			if (inputs.getKey(SDLK_p))
			{
				for (auto e : balls)
					_scene->destroy(e);
				balls.clear();
			}
			entity->setLocalTransform() = glm::translate(entity->getLocalTransform(), direction);
	}
示例#9
0
文件: Boat.cpp 项目: BSkin/Rune
Boat::Boat(string m, string t, string s, glm::vec3 position, glm::vec3 direction, glm::vec3 up, string path) : PropObject(m, t, s, position, direction, up, path)
{
	oceanHeightModObjects->push_back(this);

	turnRate = 0.0f;

	setMass(10000.0f);
	setFriction(2.0f);
	body->setDamping(0.9f, 0.9f);
	//setGravity(0,-19.62f*2,0);
	//body->setAngularFactor(1.0f);
	collisionType = "vehicle";
		
	buoyancyPoints.push_back(BuoyancyPoint(0.0f, -1.0f, 26.85f));
	buoyancyPoints.push_back(BuoyancyPoint(0.0f, -1.0f, -26.85f));

	buoyancyPoints.push_back(BuoyancyPoint(9.0f, -1.0f, 0.0f));
	buoyancyPoints.push_back(BuoyancyPoint(-9.0f, -1.0f, 0.0f));

	buoyancyPoints.push_back(BuoyancyPoint(9.0f, -1.0f, 14.0f));
	buoyancyPoints.push_back(BuoyancyPoint(-9.0f, -1.0f, 14.0f));

	buoyancyPoints.push_back(BuoyancyPoint(9.0f, -1.0f, -14.0f));
	buoyancyPoints.push_back(BuoyancyPoint(-9.0f, -1.0f, -14.0f));
	
	for (list<BuoyancyPoint>::iterator it = buoyancyPoints.begin(); it != buoyancyPoints.end(); it++)
		(it)->update(&body->getWorldTransform());
}
示例#10
0
EntityMotionState::EntityMotionState(btCollisionShape* shape, EntityItemPointer entity) :
    ObjectMotionState(nullptr),
    _entityPtr(entity),
    _entity(entity.get()),
    _serverPosition(0.0f),
    _serverRotation(),
    _serverVelocity(0.0f),
    _serverAngularVelocity(0.0f),
    _serverGravity(0.0f),
    _serverAcceleration(0.0f),
    _serverActionData(QByteArray()),
    _lastVelocity(0.0f),
    _measuredAcceleration(0.0f),
    _nextOwnershipBid(0),
    _measuredDeltaTime(0.0f),
    _lastMeasureStep(0),
    _lastStep(0),
    _loopsWithoutOwner(0),
    _accelerationNearlyGravityCount(0),
    _numInactiveUpdates(1),
    _outgoingPriority(0)
{
    _type = MOTIONSTATE_TYPE_ENTITY;
    assert(_entity);
    assert(entityTreeIsLocked());
    setMass(_entity->computeMass());
    // we need the side-effects of EntityMotionState::setShape() so we call it explicitly here
    // rather than pass the legit shape pointer to the ObjectMotionState ctor above.
    setShape(shape);
}
示例#11
0
Bird::Bird(cocos2d::Layer *layer){
	visibleSize = Director::getInstance()->getVisibleSize();
	origin = Director::getInstance()->getVisibleOrigin();

	flappyBird = Sprite::create("Will.png");
	flappyBird->setPosition(Point(visibleSize.width / 2 + origin.x, visibleSize.height / 2 + origin.y));

	willLocationX = flappyBird->getPositionX();
	willLocationY = flappyBird->getPositionY();

	auto flappyBody = PhysicsBody::createBox(Size(flappyBird->getContentSize().width, flappyBird->getContentSize().height), PhysicsMaterial(0, 1, 0));
	flappyBody->setGravityEnable(false);
	flappyBird->setPhysicsBody(flappyBody);

	layer -> addChild(flappyBird, 100);

	flappyBody->setCollisionBitmask(BIRD_COLLISION_BITMASK);
	flappyBody->setContactTestBitmask(true);
	flappyBody->setMass(1);

	//isFalling = true;

	flappyBird->getPhysicsBody()->setVelocityLimit(300);
	
}
示例#12
0
EntityMotionState::EntityMotionState(btCollisionShape* shape, EntityItemPointer entity) :
    ObjectMotionState(shape),
    _entity(entity),
    _sentInactive(true),
    _lastStep(0),
    _serverPosition(0.0f),
    _serverRotation(),
    _serverVelocity(0.0f),
    _serverAngularVelocity(0.0f),
    _serverGravity(0.0f),
    _serverAcceleration(0.0f),
    _serverActionData(QByteArray()),
    _lastMeasureStep(0),
    _lastVelocity(glm::vec3(0.0f)),
    _measuredAcceleration(glm::vec3(0.0f)),
    _measuredDeltaTime(0.0f),
    _accelerationNearlyGravityCount(0),
    _nextOwnershipBid(0),
    _loopsWithoutOwner(0)
{
    _type = MOTIONSTATE_TYPE_ENTITY;
    assert(_entity != nullptr);
    assert(entityTreeIsLocked());
    setMass(_entity->computeMass());
}
示例#13
0
void PhysicsShape::setDensity(float density)
{
    if (density < 0)
    {
        return;
    }
    
    _material.density = density;
    
    if (_material.density == PHYSICS_INFINITY)
    {
        setMass(PHYSICS_INFINITY);
    }else if (_area > 0)
    {
        setMass(_material.density * _area);
    }
}
示例#14
0
// Creates an instance of Player
// @param png - The path to the PNG representation of the sprite
// @param plist - The path to the PLIST representation of the sprite
Player* Player::create()
{
	// Create an instance of Player
	Player* playerSprite = new Player();

	// Reset travelled distance
	playerSprite->setDistanceTravelled(0);

	// Get resource loader instance
	ResourceLoader resLoader = ResourceLoader::getInstance();

	// Get running animation
	Vector<SpriteFrame*> runningAnimation = resLoader.getAnimation(PLAYER_ANIMATION_RUNNING);

	// Generate player movement sprites
	if (playerSprite->initWithSpriteFrame(runningAnimation.at(0)))
	{
		auto animation = Animation::createWithSpriteFrames(runningAnimation);

		// Set delay between frames
		animation->setDelayPerUnit(PLAYER_SPRITE_DELAY_RUNNING);

		//Create running action
		auto runningAction = RepeatForever::create(Animate::create(animation));

		//Set tag for action
		runningAction->setTag(PLAYER_ANIMATION_RUNNING);

		// Run animation forever
		playerSprite->runAction(runningAction);

		// Set properties
		playerSprite->autorelease();
		playerSprite->initOptions();
		playerSprite->setScale(Director::getInstance()->getWinSize().width * 1.8 / 800);
		playerSprite->scheduleUpdate();

		// Add weapon
		Weapon* weapon = Weapon::create();
		playerSprite->setWeapon(weapon);

		//Create physical body
		auto spriteBody = PhysicsBody::createBox(playerSprite->boundingBox().size, PhysicsMaterial(1.0f, 0.5f, 0.5f));
		spriteBody->setAngularVelocityLimit(0.0f);
		spriteBody->setMass(1);
		spriteBody->setCollisionBitmask(PLAYER_COLLISION_BITMASK);
		spriteBody->setContactTestBitmask(true);
		playerSprite->setPhysicsBody(spriteBody);
		
		// Return
		return playerSprite;
	}

	CC_SAFE_DELETE(playerSprite);
	return NULL;
}
int GLWindow::qt_metacall(QMetaObject::Call _c, int _id, void **_a)
{
    _id = QGLWidget::qt_metacall(_c, _id, _a);
    if (_id < 0)
        return _id;
    if (_c == QMetaObject::InvokeMetaMethod) {
        switch (_id) {
        case 0:
            toggleWireframe((*reinterpret_cast< bool(*)>(_a[1])));
            break;
        case 1:
            toggleBoidAnimation((*reinterpret_cast< bool(*)>(_a[1])));
            break;
        case 2:
            toggleGoalAnimation((*reinterpret_cast< bool(*)>(_a[1])));
            break;
        case 3:
            toggleRecord((*reinterpret_cast< bool(*)>(_a[1])));
            break;
        case 4:
            setMass((*reinterpret_cast< double(*)>(_a[1])));
            break;
        case 5:
            setMaxSpeed((*reinterpret_cast< double(*)>(_a[1])));
            break;
        case 6:
            setMaxForce((*reinterpret_cast< double(*)>(_a[1])));
            break;
        case 7:
            setSepDist((*reinterpret_cast< double(*)>(_a[1])));
            break;
        case 8:
            setCohDist((*reinterpret_cast< double(*)>(_a[1])));
            break;
        case 9:
            setAliDist((*reinterpret_cast< double(*)>(_a[1])));
            break;
        case 10:
            setGoalInf((*reinterpret_cast< int(*)>(_a[1])));
            break;
        case 11:
            removeBoid();
            break;
        case 12:
            addBoid();
            break;
        case 13:
            resetGoals();
            break;
        default:
            ;
        }
        _id -= 14;
    }
    return _id;
}
//--------------------------------------------------------------
void ofxBulletSoftTriMesh::create( ofxBulletWorldSoft* a_world, ofMesh& aMesh, btTransform &a_bt_tr, float a_mass ) {
    
    if(a_world == NULL) {
        ofLogError("ofxBulletSoftTriMesh") << "create(): a_world param is NULL";
        return;
    }
    
    if( aMesh.getMode() != OF_PRIMITIVE_TRIANGLES ) {
        ofLogError("ofxBulletSoftTriMesh") << " only excepts meshes that are triangles";
        return;
    }
    
    _world = a_world;
    
    _cachedMesh.clear();
    _cachedMesh = aMesh;
    
    if( bullet_vertices != NULL ) {
        delete bullet_vertices;
        bullet_vertices = NULL;
    }
    
    int vertStride  = sizeof(btVector3);
    int indexStride = 3*sizeof(int);
    
    int totalVerts    = (int)aMesh.getNumVertices();
    int totalIndices  = (int)aMesh.getNumIndices();
    
    bullet_vertices = new btScalar[ totalVerts * 3 ];
    int* bullet_indices = new int[ totalIndices ];
    
    auto& tverts       = aMesh.getVertices();
    vector< ofIndexType >& tindices = aMesh.getIndices();
    
    for( int i = 0; i < totalVerts; i++ ) {
        bullet_vertices[i*3+0] = tverts[i].x;
        bullet_vertices[i*3+1] = tverts[i].y;
        bullet_vertices[i*3+2] = tverts[i].z;
    }
    for( int i = 0; i < totalIndices; i++ ) {
        bullet_indices[i] = tindices[i];
    }
    
    _softBody = btSoftBodyHelpers::CreateFromTriMesh( _world->getInfo(),
                                                         bullet_vertices,
                                                         bullet_indices,
                                                         totalIndices/3 );
    _softBody->transform( a_bt_tr );
    setMass( a_mass, true );
    
    setCreated(_softBody);
    createInternalUserData();

    delete [] bullet_indices;
    
}
示例#17
0
void ExplisonScreen::initBody()
{
	auto body = PhysicsBody::createBox(m_WinSize);
	body->setGravityEnable(false);
	body->setMass(100000);
	body->setCategoryBitmask(SELF_SCOPE_CATEGORYBITMASK);
	body->setCollisionBitmask(0);
	body->setContactTestBitmask(SELF_SCOPE_CONTACTTESTBITMASK);
	setPhysicsBody(body);
}
示例#18
0
void Player::resumePlayer()
{
	auto spriteBody = PhysicsBody::createBox(this->boundingBox().size, PhysicsMaterial(1.0f, 0.5f, 0.5f));
	spriteBody->setAngularVelocityLimit(0.0f);
	spriteBody->setMass(1);
	spriteBody->setCollisionBitmask(PLAYER_COLLISION_BITMASK);
	spriteBody->setContactTestBitmask(true);
	this->setPhysicsBody(spriteBody);
	this->getPhysicsBody()->setVelocity(velocityOnPause);
}
示例#19
0
int QwtWheel::qt_metacall(QMetaObject::Call _c, int _id, void **_a)
{
    _id = QwtAbstractSlider::qt_metacall(_c, _id, _a);
    if (_id < 0)
        return _id;
    if (_c == QMetaObject::InvokeMetaMethod) {
        switch (_id) {
        case 0: setTotalAngle((*reinterpret_cast< double(*)>(_a[1]))); break;
        case 1: setViewAngle((*reinterpret_cast< double(*)>(_a[1]))); break;
        default: ;
        }
        _id -= 2;
    }
#ifndef QT_NO_PROPERTIES
      else if (_c == QMetaObject::ReadProperty) {
        void *_v = _a[0];
        switch (_id) {
        case 0: *reinterpret_cast< double*>(_v) = totalAngle(); break;
        case 1: *reinterpret_cast< double*>(_v) = viewAngle(); break;
        case 2: *reinterpret_cast< int*>(_v) = tickCnt(); break;
        case 3: *reinterpret_cast< int*>(_v) = wheelWidth(); break;
        case 4: *reinterpret_cast< int*>(_v) = borderWidth(); break;
        case 5: *reinterpret_cast< int*>(_v) = wheelBorderWidth(); break;
        case 6: *reinterpret_cast< double*>(_v) = mass(); break;
        }
        _id -= 7;
    } else if (_c == QMetaObject::WriteProperty) {
        void *_v = _a[0];
        switch (_id) {
        case 0: setTotalAngle(*reinterpret_cast< double*>(_v)); break;
        case 1: setViewAngle(*reinterpret_cast< double*>(_v)); break;
        case 2: setTickCnt(*reinterpret_cast< int*>(_v)); break;
        case 3: setWheelWidth(*reinterpret_cast< int*>(_v)); break;
        case 4: setBorderWidth(*reinterpret_cast< int*>(_v)); break;
        case 5: setWheelBorderWidth(*reinterpret_cast< int*>(_v)); break;
        case 6: setMass(*reinterpret_cast< double*>(_v)); break;
        }
        _id -= 7;
    } else if (_c == QMetaObject::ResetProperty) {
        _id -= 7;
    } else if (_c == QMetaObject::QueryPropertyDesignable) {
        _id -= 7;
    } else if (_c == QMetaObject::QueryPropertyScriptable) {
        _id -= 7;
    } else if (_c == QMetaObject::QueryPropertyStored) {
        _id -= 7;
    } else if (_c == QMetaObject::QueryPropertyEditable) {
        _id -= 7;
    } else if (_c == QMetaObject::QueryPropertyUser) {
        _id -= 7;
    }
#endif // QT_NO_PROPERTIES
    return _id;
}
示例#20
0
void Level::createRectFixture(TMXLayer* layer, Sprite* spr){
	//TILE SIZE CALCULATION
	auto tileSize = this->map->getTileSize();
	const float ppm = 32.0f; //pixel per meter

	//PHYSICS BODY
	auto body = PhysicsBody::createBox(Size(tileSize.width, tileSize.width));
	body->setDynamic(false);
	body->setMass(PHYSICS_INFINITY);
	body->setContactTestBitmask(0xFFFFFFFF);
	spr->setPhysicsBody(body);
}
示例#21
0
OpenCloth::OpenCloth()
	: _built(false), _device(nullptr), _vertexBuffer(nullptr), _indexBuffer(nullptr), _vertices(nullptr), _indexCount(0), _indices(nullptr),
		_positions(nullptr), _lastPositions(nullptr), _forces(nullptr), _springCount(0), _springs(nullptr), _shader(nullptr), _constantsBuffer(nullptr) {
	setDivisions(20, 20);
	setSize(7);
	setMass(1.0f);
	setDamping(-0.0125f);
	setSpringParams(500.75f, -0.25f, 500.75f, -0.25f, 500.95f, -0.25f);
	setGravity(cc::Vec3f(0.0f, -9.81f ,0.0f));

	_timeStep = 1.0f / 60.0f;
	_timeAccumulator = _timeStep;
}
示例#22
0
void RigidBody::initValues(float mass, Matrix3 Ibody ,

		Vector3 position, Vector3 velocity,
		Quaternion rotation , Vector3 angularMomentum ){
		setPosition(position);
		setRotation(rotation);

		setMass(mass);
		setIbody(Ibody);
		setVelocity(velocity);

		setAngularMomentum(angularMomentum);
}
示例#23
0
	void PhysicsObject::Init(Vec2 Pos,double e,double mu,double mass){
		this->Pos=Pos;
		Vel.SetValue(0,0);
		angle=0;
		angleSpeed=0;
		setRestitution(e);
		setFriction(mu); 
		setMass(mass);
		
		
		ID = runningNr;
		runningNr += 1;
	}
示例#24
0
文件: Me.cpp 项目: Glyca/RunicOrbs
Me::Me(World* world) : Player(world->physicEngine(), 1) // For the moment we take the id 1 for all Me, which is wrong in mulitplayer
{
	setMass(70.0f); // 70kg is good
	//m_world = world;

	int spawnX = rand() % (5 * CHUNK_X_SIZE) + 1;
	int spawnZ = rand() % (5 * CHUNK_Z_SIZE) + 1;

	int altitude = this->world()->altitude(spawnX, spawnZ);
	v_position = Vector(spawnX, altitude + 20, spawnZ);

	qDebug("Me created");
}
示例#25
0
//--------------------------------------------------------------
void ofxBulletSoftBody::add() {
    _bAdded = true;
    _world->getWorld()->addSoftBody(_softBody);
    
    if( _type != OFX_BULLET_TRI_MESH_SHAPE ) {
        setMass(1);
    }
    setStiffness(0.9, 0.9, 0.9);
    
    setSolverIterations(4);
    
//    _softBody->getCollisionShape()->setMargin(getMargin() * 2);
}
示例#26
0
// default constructor: creates a particle represented by a default (square).
// Notes:
// - particle rotated so that it is orthogonal to the z axis.
// - scaled 
// - no shader allocated by default to avoid creating a Shader object for each particle.
Particle::Particle()
{
	setMesh(Mesh::Mesh());
	scale(glm::vec3(.1f, .1f, .1f));
	rotate((GLfloat)M_PI_2, glm::vec3(1.0f, 0.0f, 0.0f));
	
	// set dynamic values
	setAcc(glm::vec3(0.0f, 0.0f, 0.0f));
	setVel(glm::vec3(0.0f, 0.0f, 0.0f));

	// physical properties
	setMass(1.0f);
	setCor(1.0f);
}
示例#27
0
void VirusBase::constructCircleBase(float $numPoints, float $r) {
	setMass( $r * .07 );
	float angle = 360 / $numPoints;
	
	 for (int i = 0; i < $numPoints; i++) {
		 ofxVec2f len($r, 0);
		 len.rotate(angle * (float)i);
		 
		 addBasePt(len.x, len.y, len.x, len.y);
	 }
	
	calculateMOICircle( $r );
	 
}
示例#28
0
void PlaneProtect::initBody()
{
	auto body = PhysicsBody::createCircle(getContentSize().width * 0.5);
	body->setGravityEnable(false);
	body->setMass(10000000);
	body->setCategoryBitmask(SELF_SCOPE_CATEGORYBITMASK);
	body->setCollisionBitmask(0);
	body->setContactTestBitmask(SELF_SCOPE_CONTACTTESTBITMASK);
	setPhysicsBody(body);
	setMaxBlood(Protect_Hp);
	m_ContactPro.hurts = -Ene_Plane_Hp_max - 10;
	
	setUnitId(UnitId::eFanghudun);
}
示例#29
0
RigidBlock::RigidBlock(float a, float b, float c, float mass,
	Vector3 position, Vector3 velocity,
	Quaternion rotation, Vector3 angularMomentum){
	//Status setzen
	setMass(mass);
	setPosition(position);
	setRotation(rotation);

	//Trägheitstensor berechnen
	setDimensions(a,b,c);

	setVelocity(velocity);
	setAngularMomentum(angularMomentum);

	//printState();
}
示例#30
0
Window::Window(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::Window)
{
    QGLFormat qglFormat;
    qglFormat.setVersion(3, 2);
    qglFormat.setProfile(QGLFormat::CoreProfile);
    qglFormat.setSampleBuffers(true);
    QGLFormat::setDefaultFormat(qglFormat);
    ui->setupUi(this);

    // Set the default values.
    setRadius(DEF_RADIUS);
    setRestitution(DEF_RESTITUTION);
    setMass(DEF_MASS);
    setNumSpheres(0);
}