本文整理汇总了C++中Body::SetVelocity方法的典型用法代码示例。如果您正苦于以下问题:C++ Body::SetVelocity方法的具体用法?C++ Body::SetVelocity怎么用?C++ Body::SetVelocity使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Body
的用法示例。
在下文中一共展示了Body::SetVelocity方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Reset
void BilliardsDemo::Reset()
{
Model* model;
Body* body;
// Balls
float r, g, b;
for (int i = 0; i < 5; i++)
{
for (int j = 0; j < i + 1; j++)
{
r = glm::linearRand(0.0f, 1.0f);
g = glm::linearRand(0.0f, 1.0f);
b = glm::linearRand(0.0f, 1.0f);
model = new Sphere(glm::vec3(r, g, b));
glm::vec3 scale = glm::vec3(1);
glm::vec3 position = glm::vec3((-i + 2 * j), 3, -1.73*i);
glm::quat orientation = glm::quat(1, 0, 0, 0);
body = new Body(position, orientation, scale);
body->SetCollider(new SphereCollider(body, scale.x));
objects.push_back(new Object(model, body));
}
}
model = new Sphere(glm::vec3(1));
glm::vec3 scale = glm::vec3(1);
glm::vec3 position = glm::vec3(0, 3, 16);
glm::quat orientation = glm::quat(1, 0, 0, 0);
body = new Body(position, orientation, scale);
body->SetMass(125);
body->SetCollider(new SphereCollider(body, scale.x));
body->SetVelocity(glm::vec3(0, 0, -50));
objects.push_back(new Object(model, body));
}
示例2: l_space_spawn_ship_near
/*
* Function: SpawnShipNear
*
* Create a ship and place it in space near the given <Body>.
*
* > ship = Space.SpawnShip(type, body, min, max, hyperspace)
*
* Parameters:
*
* type - the name of the ship
*
* body - the <Body> near which the ship should be spawned
*
* min - minimum distance from the body to place the ship, in Km
*
* max - maximum distance to place the ship
*
* hyperspace - optional table containing hyperspace entry information. If
* this is provided the ship will not spawn directly. Instead,
* a hyperspace cloud will be created that the ship will exit
* from. The table contains two elements, a <SystemPath> for
* the system the ship is travelling from, and the due
* date/time that the ship should emerge from the cloud.
*
* Return:
*
* ship - a <Ship> object for the new ship
*
* Example:
*
* > -- spawn a ship 10km from the player
* > local ship = Ship.SpawnNear("viper_police_craft", Game.player, 10, 10)
*
* Availability:
*
* alpha 10
*
* Status:
*
* experimental
*/
static int l_space_spawn_ship_near(lua_State *l)
{
if (!Pi::game)
luaL_error(l, "Game is not started");
LUA_DEBUG_START(l);
const char *type = luaL_checkstring(l, 1);
if (! ShipType::Get(type))
luaL_error(l, "Unknown ship type '%s'", type);
Body *nearbody = LuaObject<Body>::CheckFromLua(2);
float min_dist = luaL_checknumber(l, 3);
float max_dist = luaL_checknumber(l, 4);
SystemPath *path = 0;
double due = -1;
_unpack_hyperspace_args(l, 5, path, due);
Ship *ship = new Ship(type);
assert(ship);
Body *thing = _maybe_wrap_ship_with_cloud(ship, path, due);
// XXX protect against spawning inside the body
Frame * newframe = nearbody->GetFrame();
const vector3d newPosition = (MathUtil::RandomPointOnSphere(min_dist, max_dist)* 1000.0) + nearbody->GetPosition();
// If the frame is rotating and the chosen position is too far, use non-rotating parent.
// Otherwise the ship will be given a massive initial velocity when it's bumped out of the
// rotating frame in the next update
if (newframe->IsRotFrame() && newframe->GetRadius() < newPosition.Length()) {
assert(newframe->GetParent());
newframe = newframe->GetParent();
}
thing->SetFrame(newframe);;
thing->SetPosition(newPosition);
thing->SetVelocity(vector3d(0,0,0));
Pi::game->GetSpace()->AddBody(thing);
LuaObject<Ship>::PushToLua(ship);
LUA_DEBUG_END(l, 1);
return 1;
}
示例3: l_space_spawn_ship
/*
* Function: SpawnShip
*
* Create a ship and place it somewhere in space.
*
* > ship = Space.SpawnShip(type, min, max, hyperspace)
*
* Parameters:
*
* type - the name of the ship
*
* min - minimum distance from the system centre (usually the primary star)
* to place the ship, in AU
*
* max - maximum distance to place the ship
*
* hyperspace - optional table containing hyperspace entry information. If
* this is provided the ship will not spawn directly. Instead,
* a hyperspace cloud will be created that the ship will exit
* from. The table contains two elements, a <SystemPath> for
* the system the ship is travelling from, and the due
* date/time that the ship should emerge from the cloud.
* In this case min and max arguments are ignored.
*
* Return:
*
* ship - a <Ship> object for the new ship
*
* Examples:
*
* > -- spawn a ship 5-6AU from the system centre
* > local ship = Ship.Spawn("eagle_lrf", 5, 6)
*
* > -- spawn a ship in the ~11AU hyperspace area and make it appear that it
* > -- came from Sol and will arrive in ten minutes
* > local ship = Ship.Spawn(
* > "flowerfairy", 9, 11,
* > { SystemPath:New(0,0,0), Game.time + 600 }
* > )
*
* Availability:
*
* alpha 10
*
* Status:
*
* experimental
*/
static int l_space_spawn_ship(lua_State *l)
{
if (!Pi::game)
luaL_error(l, "Game is not started");
LUA_DEBUG_START(l);
const char *type = luaL_checkstring(l, 1);
if (! ShipType::Get(type))
luaL_error(l, "Unknown ship type '%s'", type);
float min_dist = luaL_checknumber(l, 2);
float max_dist = luaL_checknumber(l, 3);
SystemPath *path = NULL;
double due = -1;
_unpack_hyperspace_args(l, 4, path, due);
Ship *ship = new Ship(type);
assert(ship);
Body *thing = _maybe_wrap_ship_with_cloud(ship, path, due);
// XXX protect against spawning inside the body
thing->SetFrame(Pi::game->GetSpace()->GetRootFrame());
if (path == NULL)
thing->SetPosition(MathUtil::RandomPointOnSphere(min_dist, max_dist)*AU);
else
// XXX broken. this is ignoring min_dist & max_dist. otoh, what's the
// correct behaviour given there's now a fixed hyperspace exit point?
thing->SetPosition(Pi::game->GetSpace()->GetHyperspaceExitPoint(*path));
thing->SetVelocity(vector3d(0,0,0));
Pi::game->GetSpace()->AddBody(thing);
LuaShip::PushToLua(ship);
LUA_DEBUG_END(l, 1);
return 1;
}