Exemple #1
0
Model::Model(
		string _name,
		Image* _image,
		string _description,
		Engine* _defaultEngine,
		float _mass,
		short int _thrustOffset,
		float _rotPerSecond,
		float _maxSpeed,
		int _hullStrength,
		int _shieldStrength,
		int _msrp,
		int _cargoSpace,
		vector<WeaponSlot>& _weaponSlots) :
	image(_image),
	defaultEngine(_defaultEngine),
	thrustOffset(_thrustOffset)
{
	SetName(_name);
	SetDescription(_description);
	SetMass(_mass);
	SetRotationsPerSecond(_rotPerSecond);
	SetMaxSpeed(_maxSpeed);
	SetMSRP(_msrp);
	SetCargoSpace(_cargoSpace);
	SetHullStrength(_hullStrength);
	SetShieldStrength(_shieldStrength);
	ConfigureWeaponSlots(_weaponSlots);
	//((Component*)this)->SetName(_name);
}
	Block::Block(Rules& rules, const sf::Color& color, int health) : Entity(rules) {
		_highlight = false;
		_highlightPhase = 0.0f;

		_drop = false;
		_health = health;
		_decay = 1.0f;
		_rotation = 0.0f;
		_angularVelocity = 0.0f;

		_color = color;

		_blockSprite = ImageManager::Instance().CreateSprite("res/brick.png");
		_blockSprite.Resize(BLOCK_WIDTH, BLOCK_HEIGHT);
		_blockSprite.SetColor(_color);

		SetBBox(MATH::BBox2(MATH::Vector2(0.0f, 0.0f),
			MATH::Vector2(BLOCK_WIDTH, BLOCK_HEIGHT)));

		SetPhysicsModel(PHY_GHOST);
		SetCollisionModel(PHY_SOLID);

		SetAcceleration(1.0f);
		SetVelocity(MATH::Vector2(0.0f, 0.0f));
		SetMass(100000.0f);
	}
Exemple #3
0
cBoat::cBoat(double a_X, double a_Y, double a_Z) :
	super(etBoat, a_X, a_Y, a_Z, 0.98, 0.7)
{
	SetMass(20.f);
	SetMaxHealth(6);
	SetHealth(6);
}
Exemple #4
0
CargoBody::CargoBody(Equip::Type t)
{
	m_type = t;
	SetModel("cargo");
	Init();
	SetMass(1.0);
}
	Ball::Ball(Rules& rules) : Entity(rules) {
		rules.numBalls++;

		_ignited = false;
		_dying = false;

		_scoreSound = SoundManager::Instance().GetSound("res/ding.wav", false);
		_bounceSound = SoundManager::Instance().GetSound("res/bounce.wav", false);

		_ballSprite = ImageManager::Instance().CreateSprite("res/ball3.png");
		_ballSprite.SetColor(sf::Color(232, 243, 255));
		_ballSprite.Resize(BALL_SIZE, BALL_SIZE);

		MATH::Vector2 randomVector(0, -1.0f);
		randomVector = MATH::Rotate(randomVector, sf::Randomizer::Random(-0.1f, 0.1f));
		randomVector = MATH::Normalize(randomVector);

		SetAcceleration(1.0f);
		SetVelocity(randomVector * 300.0f);
		SetMass(1.0f);

		SetPhysicsModel(PHY_TOUCHING | PHY_SOLID | PHY_BOUNCING);
		SetCollisionModel(PHY_SOLID);

		SetBBox(MATH::BBox2(MATH::Vector2(0.0f, 0.0f),
			MATH::Vector2(BALL_SIZE, BALL_SIZE)));
	}
Exemple #6
0
HRESULT CchaffIGC::Initialize(ImissionIGC* pMission, Time now, const void* data, unsigned int dataSize)
{
    TmodelIGC<IchaffIGC>::Initialize(pMission, now, data, dataSize);

    ZRetailAssert (data && (dataSize == sizeof(DataChaffIGC)));
    DataChaffIGC*  dataChaff = (DataChaffIGC*)data;

    m_pChaffTypeData = (DataChaffTypeIGC*)(dataChaff->pchafftype->GetData());

    LoadDecal(m_pChaffTypeData->textureName, NULL,
              Color(1.0f, 1.0f, 1.0f, 1.0f),
              false,
              1.0f,
              c_mtNotPickable | c_mtPredictable);

    Time    time0 = pMission->GetIgcSite()->ClientTimeFromServerTime(dataChaff->time0);

    SetRadius(1.0f);
    SetPosition(dataChaff->p0 + Seconds(now - time0).count() * dataChaff->v0);
    SetVelocity(dataChaff->v0);

    {
        Rotation    r(Vector(0.0f, 0.0f, 1.0f), 2.75f);
        SetRotation(r);
    }

    SetMass(0.0f);

    m_timeExpire = time0 + Seconds(m_pChaffTypeData->lifespan);

    SetCluster(dataChaff->pcluster);

    return S_OK;
}
RigidBody::RigidBody(Rect rect)
{
	float width = (rect.right - rect.left);
	float height = (rect.bottom - rect.top);

	// Create a Rectangle shape - origin middle
	mShape = new Shape();
	mShape->setOrigin(Vector(rect.left + width/2, rect.top + height/2, 0));
	mShape->addPoint(Vector(-width/2, -height/2, 0));	// top - left
	mShape->addPoint(Vector(-width/2, height/2, 0));	// bottom - left
	mShape->addPoint(Vector(width/2, height/2, 0));   // bottom - right
	mShape->addPoint(Vector(width/2, -height/2, 0));	// top - right

	setStatic(false);
	mAlive = true;
	mTexture = NULL;

	SetMass(1);
	SetVelocity(0, 0);
	SetAngularVelocity(0.0f);
	SetForce(Vector(0, 0, 0));
	SetTorque(Vector(0, 0, 0));
	SetMomentum(Vector(0, 0, 0));
	SetFriction(1.0f);
	SetSleeping(false);
}
Exemple #8
0
Missile::Missile(const ShipType::Id &shipId, Body *owner, int power)//: Ship(shipId)
{
	if (power < 0) {
		m_power = 0;
		if (shipId == ShipType::MISSILE_GUIDED) m_power = 1;
		if (shipId == ShipType::MISSILE_SMART) m_power = 2;
		if (shipId == ShipType::MISSILE_NAVAL) m_power = 3;
	} else
		m_power = power;

	m_owner = owner;
	m_type = &ShipType::types[shipId];

	SetMass(m_type->hullMass*1000);

	SetModel(m_type->modelName.c_str());
	SetMassDistributionFromModel();

	SetLabel(Lang::MISSILE);

	Disarm();

	SetFuel(1.0);
	SetFuelReserve(0.0);

	m_curAICmd = 0;
	m_aiMessage = AIERROR_NONE;
	m_decelerating = false;

	Propulsion::Init( this, GetModel(), m_type->fuelTankMass, m_type->effectiveExhaustVelocity, m_type->linThrust, m_type->angThrust );

}
Exemple #9
0
void DynamicBody::SetMassDistributionFromModel()
{
	LmrCollMesh *m = GetLmrCollMesh();
	// XXX totally arbitrarily pick to distribute mass over a half
	// bounding sphere area
	m_massRadius = m->GetBoundingRadius()*0.5f;
	SetMass(m_mass);
}
Exemple #10
0
//-------------------------------------------------------------------------------
// @ Obstacle::Obstacle()
//-------------------------------------------------------------------------------
// Constructor
//-------------------------------------------------------------------------------
Obstacle::Obstacle() : SimObject()
{
    SetTranslate( IvVector3( 0.0f, 3.0f, 0.0f ) );
    
    mElasticity = 0.25f;
    SetMass(20.0f);

}   // End of Obstacle::Obstacle()
Exemple #11
0
cMinecart::cMinecart(ePayload a_Payload, double a_X, double a_Y, double a_Z) :
	super(etMinecart, a_X, a_Y, a_Z, 0.98, 0.7),
	m_Payload(a_Payload),
	m_LastDamage(0)
{
	SetMass(20.f);
	SetMaxHealth(6);
	SetHealth(6);
}
Exemple #12
0
cBoat::cBoat(double a_X, double a_Y, double a_Z) :
	super(etBoat, a_X, a_Y, a_Z, 0.98, 0.7)
{
	SetMass(20.0f);
	SetGravity(-16.0f);
	SetAirDrag(0.05f);
	SetMaxHealth(6);
	SetHealth(6);
}
void CPHMovementControl::Load					(LPCSTR section){

	//capture
	
	//strcpy(m_capture_bone,pSettings->r_string(section,"capture_bone"));
	
	Fbox	bb;

	// m_PhysicMovementControl: BOX
	Fvector	vBOX1_center= pSettings->r_fvector3	(section,"ph_box1_center"	);
	Fvector	vBOX1_size	= pSettings->r_fvector3	(section,"ph_box1_size"		);
	bb.set	(vBOX1_center,vBOX1_center); bb.grow(vBOX1_size);
	SetBox		(1,bb);

	// m_PhysicMovementControl: BOX
	Fvector	vBOX0_center= pSettings->r_fvector3	(section,"ph_box0_center"	);
	Fvector	vBOX0_size	= pSettings->r_fvector3	(section,"ph_box0_size"		);
	bb.set	(vBOX0_center,vBOX0_center); bb.grow(vBOX0_size);
	SetBox		(0,bb);

	//// m_PhysicMovementControl: Foots
	//Fvector	vFOOT_center= pSettings->r_fvector3	(section,"ph_foot_center"	);
	//Fvector	vFOOT_size	= pSettings->r_fvector3	(section,"ph_foot_size"		);
	//bb.set	(vFOOT_center,vFOOT_center); bb.grow(vFOOT_size);
	//SetFoots	(vFOOT_center,vFOOT_size);

	// m_PhysicMovementControl: Crash speed and mass
	float	cs_min		= pSettings->r_float	(section,"ph_crash_speed_min"	);
	float	cs_max		= pSettings->r_float	(section,"ph_crash_speed_max"	);
	float	mass		= pSettings->r_float	(section,"ph_mass"				);
	xr_token retrictor_types[]={
		{ "actor",			CPHCharacter::rtActor},
		{ "medium_monster",	CPHCharacter::rtMonsterMedium},
		{ "stalker",		CPHCharacter::rtStalker	},
		{ "none",			CPHCharacter::rtNone	},
		{ 0,							0}
	};

	if(pSettings->line_exist(section,"actor_restrictor"))
		SetRestrictionType(CPHCharacter::ERestrictionType(pSettings->r_token(section,"actor_restrictor",retrictor_types)));
	fCollisionDamageFactor=READ_IF_EXISTS(pSettings,r_float,section,"ph_collision_damage_factor",fCollisionDamageFactor);
	R_ASSERT3(fCollisionDamageFactor<=1.f,"ph_collision_damage_factor >1.",section);
	SetCrashSpeeds	(cs_min,cs_max);
	SetMass		(mass);


	// m_PhysicMovementControl: Frictions
	//float af, gf, wf;
	//af					= pSettings->r_float	(section,"ph_friction_air"	);
	//gf					= pSettings->r_float	(section,"ph_friction_ground");
	//wf					= pSettings->r_float	(section,"ph_friction_wall"	);
	//SetFriction	(af,wf,gf);

	// BOX activate
//	ActivateBox	(0);
}
CargoBody::CargoBody(const LuaRef& cargo, float selfdestructTimer): m_cargo(cargo)
{
	SetModel("cargo");
	Init();
	SetMass(1.0);
	m_selfdestructTimer = selfdestructTimer; // number of seconds to live

	if (is_zero_exact(selfdestructTimer)) // turn off self destruct
		m_hasSelfdestruct = false;
}
Exemple #15
0
void create(){
    bed::create();
    SetShort("A table");
    SetLong("A table");
    SetMaxSitters(2);
    SetMaxLiers(1);
    SetMaxCarry(500);
    SetMass(1000);
    inventory_visible();
    inventory_accessible();
}
Exemple #16
0
/**\brief Creates an empty Model object.
 */
Model::Model()
	:image(NULL)
	,defaultEngine(NULL)
	,thrustOffset(0)
{
	SetName("");
	SetMass(1.0f);
	SetRotationsPerSecond(0.2f);
	SetHullStrength(100);
	SetShieldStrength(100);
	SetCargoSpace(10);
}
Exemple #17
0
static void create() {
    chair::create();
    SetKeyName("bench");
    SetId("bench");
    SetAdjectives("wooden");
    SetShort("a wooden bench");
    SetLong("This is a typical wooden bench, the sort you might "+
            "see in a park. It appears designed for sitting on.");
    SetMass(1500);
    SetDollarCost(15);
    SetMaxSitters(3);
}
Exemple #18
0
cMinecart::cMinecart(ePayload a_Payload, double a_X, double a_Y, double a_Z) :
    super(etMinecart, a_X, a_Y, a_Z, 0.98, 0.7),
    m_Payload(a_Payload),
    m_LastDamage(0),
    m_DetectorRailPosition(0, 0, 0),
    m_bIsOnDetectorRail(false)
{
    SetMass(20.f);
    SetMaxHealth(6);
    SetHealth(6);
    SetWidth(1);
    SetHeight(0.9);
}
Exemple #19
0
static void create() {
    item::create();

    SetKeyName("portal");
    SetId("portal");
    SetAdjectives("pulsating", "shimmering");
    SetShort("%^YELLOW%^a shimmering portal%^RESET%^");
    SetLong((: eventShowPortal :));
    SetPreventGet("The portal is pure magic and lacks substance.");
    SetPreventPut("The portal is pure magic and lacks substabce.");
    SetMass(0);
    SetValue(0);
}
Exemple #20
0
/**\brief Creates a Model with the given parameters.
 * \param _name Name of the ship
 * \param _image Image of the ship
 * \param _mass Mass of the ship
 * \param _thrustOffset For animation
 * \param _rotPerSecond Rotation per second
 * \param _maxSpeed Maximum speed
 * \param _hullStrength Maximum damage it can take
 * \param _msrp Price
 * \param _cargoSpace Tons of cargo space
 */
Model::Model( string _name, Image* _image, float _mass,
		short int _thrustOffset, float _rotPerSecond, float _maxSpeed, int _hullStrength, int _msrp, int _cargoSpace) :
	image(_image),
	thrustOffset(_thrustOffset)
{
	SetName(_name);
	SetMass(_mass);
	SetRotationsPerSecond(_rotPerSecond);
	SetMaxSpeed(_maxSpeed);
	SetMSRP(_msrp);
	SetCargoSpace(_cargoSpace);
	SetHullStrength(_hullStrength);
	//((Component*)this)->SetName(_name);
}
	ExtraBallItem::ExtraBallItem(Rules& rules) : Entity(rules) {
		_itemSprite = ImageManager::Instance().CreateSprite("res/item_extraball.png");
		_itemSprite.Resize(ITEM_WIDTH, ITEM_HEIGHT);

		SetBBox(MATH::BBox2(MATH::Vector2(0.0f, 0.0f),
			MATH::Vector2(ITEM_WIDTH, ITEM_HEIGHT)));

		SetAcceleration(1.0f);
		SetVelocity(MATH::Vector2(0.0f, 1.0f) * 100.0f);
		SetMass(1.0f);

		SetPhysicsModel(PHY_TOUCHING | PHY_GHOST);
		SetCollisionModel(PHY_GHOST);
	}
Exemple #22
0
static void create() {
    item::create();
    SetKeyName("stick");
    SetId("stick");
    SetAdjectives("wooden");
    SetShort("a wooden stick");
    SetLong("A wooden stick which looks like it might once have been used "
            "as a walking stick, or perhaps as a poor person's club.");
    SetMass(30);
    SetValue(10);
    SetVendorType(VT_WEAPON);
    SetClass(10);
    SetDamageType(BLUNT);
    SetWeaponType("blunt");
}
Exemple #23
0
CPowerUp::CPowerUp()
{
	m_eType = POWERUP;
	m_bIsGrabable = false;

	m_pImage = new CAnimatedTexture("media/scripts/texture_powerups.txt");

	CODEManager* ode = CODEManager::Instance(); 
	ode->CreatePhysicsData(this, &m_oPhysicsData, 30.0f);
	SetMass( 40.0f );
	m_oPhysicsData.m_bAffectedByGravity = false;
	m_oPhysicsData.m_bHasCollision = false;
	SetPosition(-10000, -10000);

}
cArrowEntity::cArrowEntity(cEntity * a_Creator, double a_X, double a_Y, double a_Z, const Vector3d & a_Speed) :
	super(pkArrow, a_Creator, a_X, a_Y, a_Z, 0.5, 0.5),
	m_PickupState(psNoPickup),
	m_DamageCoeff(2),
	m_IsCritical(false)
{
	SetSpeed(a_Speed);
	SetMass(0.1);
	SetRotationFromSpeed();
	SetPitchFromSpeed();
	LOGD("Created arrow %d with speed {%.02f, %.02f, %.02f} and rot {%.02f, %.02f}",
		m_UniqueID, GetSpeedX(), GetSpeedY(), GetSpeedZ(),
		GetRotation(), GetPitch()
	);
}
Exemple #25
0
/**\brief For parsing XML file into fields.
 */
bool Model::FromXMLNode( xmlDocPtr doc, xmlNodePtr node ) {
	xmlNodePtr  attr;
	string value;

	if( (attr = FirstChildNamed(node,"image")) ){
		image = Image::Get( NodeToString(doc,attr) );
		Image::Store(name, image);
		SetPicture(image);
	} else return false;

	if( (attr = FirstChildNamed(node,"mass")) ){
		value = NodeToString(doc,attr);
		SetMass( static_cast<float> (atof( value.c_str() )));
	} else return false;

	if( (attr = FirstChildNamed(node,"rotationsPerSecond")) ){
		value = NodeToString(doc,attr);
		SetRotationsPerSecond( static_cast<float>(atof( value.c_str() )));
	} else return false;

	if( (attr = FirstChildNamed(node,"thrustOffset")) ){
		value = NodeToString(doc,attr);
		thrustOffset = static_cast<short>(atoi( value.c_str() ));
	} else return false;

	if( (attr = FirstChildNamed(node,"maxSpeed")) ){
		value = NodeToString(doc,attr);
		SetMaxSpeed( static_cast<float>(atof( value.c_str() )));
	} else return false;

	if( (attr = FirstChildNamed(node,"msrp")) ){
		value = NodeToString(doc,attr);
		SetMSRP( (short int)atoi( value.c_str() ));
	} else return false;

	if( (attr = FirstChildNamed(node,"cargoSpace")) ){
		value = NodeToString(doc,attr);
		SetCargoSpace( atoi( value.c_str() ));
	} else return false;

	if( (attr = FirstChildNamed(node,"hullStrength")) ){
		value = NodeToString(doc,attr);
		SetHullStrength( (short)atoi( value.c_str() ));
	} else return false;

	return true;
}
void PhysicsBodyComponent::OnEnable() {
    if(mCollisionMaskInUse) // Special treatment due to Bullet internals
        GetNode()->GetScene()->GetPhysicsWorld()->GetBulletWorld()->addRigidBody(mBody, mCollisionGroup, mCollisionMask);
    else
        GetNode()->GetScene()->GetPhysicsWorld()->GetBulletWorld()->addRigidBody(mBody);

    //Re-sychronize the PhysicsBodyComponent with the node.
    btDefaultMotionState* state = new btDefaultMotionState(
        btTransform(BtOgre::Convert::toBullet(GetNode()->GetRotation(Node::SCENE)),
        BtOgre::Convert::toBullet(GetNode()->GetPosition(Node::SCENE))));
    mBody->setMotionState(state);

    SetMass(mMass);

    //Activate it.
    this->Activate();
}
//-----------------------------------------------------------------------------
//  SetTotalMass
//-----------------------------------------------------------------------------
void    CPhysicObj::SetTotalMass (float fMass)
{
    // NOTA: Distribuimos la masa total entre las partes, repartiendola de forma 
    //   proporcional al volumen 

    // Calculamos el volumen total actual
    float fCurTotalVol = m_InitInfo.pPhysicModel->CalcVolume();
    // Necesitamos tener volumen
    assert( fCurTotalVol > 0.f );

    // Distribuimos la masa total porcentualmente entre las partes
    int nNumParts = GetNumParts();
    for (int i = 0; i < nNumParts; i++)
    {
        SetMass (i, fMass * (m_InitInfo.pPhysicModel->CalcVolume(i) / fCurTotalVol));
    }
}
cArrowEntity::cArrowEntity(cEntity * a_Creator, double a_X, double a_Y, double a_Z, const Vector3d & a_Speed) :
	super(pkArrow, a_Creator, a_X, a_Y, a_Z, 0.5, 0.5),
	m_PickupState(psNoPickup),
	m_DamageCoeff(2),
	m_IsCritical(false),
	m_Timer(0),
	m_HitGroundTimer(0),
	m_bIsCollected(false),
	m_HitBlockPos(Vector3i(0, 0, 0))
{
	SetSpeed(a_Speed);
	SetMass(0.1);
	SetYawFromSpeed();
	SetPitchFromSpeed();
	LOGD("Created arrow %d with speed {%.02f, %.02f, %.02f} and rot {%.02f, %.02f}",
		m_UniqueID, GetSpeedX(), GetSpeedY(), GetSpeedZ(),
		GetYaw(), GetPitch()
	);
}
Exemple #29
0
void MoveController::SetUpJumpSensor() {
    sensor = node_->CreateChild("jump_sensor");
    const auto collision = node_->GetDerivedComponent<CollisionBox2D>();
    sensor->SetPosition2D(0.0, -collision->GetSize().y_ / 2);

    const auto rigidBody = sensor->CreateComponent<RigidBody2D>();
    rigidBody->SetAllowSleep(false);
    rigidBody->SetBodyType(BT_DYNAMIC);
    rigidBody->SetMass(0.0);
    rigidBody->SetGravityScale(0.0f);
    rigidBody->SetVolatilePosition(true);

    CollisionBox2D *box = sensor->CreateComponent<CollisionBox2D>();
    box->SetTrigger(true);
    box->SetGroupIndex(-((short) node_->GetID()));
    box->SetSize(collision->GetSize().x_ * 0.7f, 0.01f);

    sensor->SubscribeToEvent(E_PHYSICSBEGINCONTACT2D, URHO3D_HANDLER(MoveController, BeginSense));
    sensor->SubscribeToEvent(E_PHYSICSENDCONTACT2D, URHO3D_HANDLER(MoveController, StopSense));
}
Exemple #30
0
RigidBody::RigidBody(float x, float y, int width, int height)
{
	// Create a Rectangle shape - origin middle
	mShape = new Shape();
	mShape->setOrigin(Vector(x, y, 0));
	mShape->addPoint(Vector(-width/2, -height/2, 0));	// top - left
	mShape->addPoint(Vector(-width/2, height/2, 0));	// bottom - left
	mShape->addPoint(Vector(width/2, height/2, 0));		// bottom - right
	mShape->addPoint(Vector(width/2, -height/2, 0));	// top - right

	SetMass(1);
	SetVelocity(0, 0);
	SetAngularVelocity(0.0f);
	SetForce(Vector(0, 0, 0));
	SetTorque(Vector(0, 0, 0));
	SetFriction(1.0f);
	SetFriction(0.5f),
	SetSimulate(true);
	SetOwner(NULL);
	
}