Well it's not going to be a copy of asteroids it'll be quite different and I just don't like the idea of teleportation.
I've noticed that increasing the radius of a body's shape reduces the speed of the object's movement and rotation/
This is the code I use for the creation of the b2Body, its drawing and the changing of its properties(moving). I understand what you're saying although I don't know how to implement it :S.
Object is a class that contains all the data concerning the game objects. 'object_body' is a pointer to a b2Body and a member of the object class. Sprite_instance is a member of the object class containing the a pointer to the texture and the size of the texture being drawn.
Code:
//Body creation
b2Body* Game::create_body(b2Vec2 position, float rotation, float mass, float size)
{
//Define body
b2BodyDef bodyDef;
//Properties
bodyDef.position.Set(position.x, position.y); //body's position
bodyDef.angle = rotation * b2_pi; //body's angle in radians(?)
bodyDef.massData.mass = 2.0; //body's mass in kg
//Defaults
bodyDef.massData.center.SetZero(); //center of mass in local coordinates
bodyDef.massData.I = 3.0f; //rotational inertia in kg*m^2
bodyDef.linearDamping = 0.0;
bodyDef.angularDamping = 0.01f;
bodyDef.allowSleep = true;
bodyDef.isSleeping = false;
bodyDef.isBullet = false;
//Create body
b2Body* body = world->CreateBody(&bodyDef);
//Define shape
b2CircleDef shapeDef;
//Properties
shapeDef.restitution = 1.0f;
shapeDef.radius = 1.0f;
shapeDef.localPosition.SetZero();
//Default
shapeDef.density = 1.0f;
shapeDef.friction = 0.3f;
//Create shape
body->CreateShape(&shapeDef);
body->SetMassFromShapes();
return body;
}
//Body creation call
void Game::create_ship(b2Vec2 position, float rotation)
{
Object *object_pointer = new Ship(*application);
object_pointer->object_body = create_body(position, rotation, 3.0f, 1.5f);
add_queue.push_back(object_pointer);
}
//Drawing function
void Direct3D::draw_sprite(Object &object)
{
SpriteInstance sprite_instance = object.get_sprite_instance();
LPDIRECT3DTEXTURE9 texture = sprite_instance.get_sprite()->get_texture();
D3DXVECTOR2 scaling = get_scaling();
D3DXVECTOR2 center = get_center((float)sprite_instance.get_size() / 2);
float rotation = object.object_body->GetAngle();
D3DXVECTOR2 position;
position.x = object.object_body->GetPosition().x;
position.y = object.object_body->GetPosition().y;
RECT frame = get_frame(sprite_instance);
D3DXMATRIX mat;
D3DXMatrixTransformation2D(&mat,
NULL,
NULL,
&scaling,
¢er,
rotation,
&position);
d3d_sprite->SetTransform(&mat);
d3d_sprite->Draw(texture, &frame, NULL, NULL, 0xFFFFFFFF);
}
//Move function
void Object::move(float magnitude)
{
b2Vec2 direction;
direction.x = sin(-object_body->GetAngle()) * magnitude;
direction.y = cos(-object_body->GetAngle()) * magnitude;
object_body->WakeUp();
object_body->ApplyForce(direction, object_body->GetPosition());
}
//Object update function
void Ship::update(Game &game)
{
if(game.get_application()->input.is_down(MOVE_FORWARD))
{
move(-200);
}
}