[Change] Improved mouse control.
[Add] Added a few shiptypes. Don't yell at me for pathetic names.
This commit is contained in:
parent
68b4ba57da
commit
e43c75060f
@ -174,14 +174,14 @@ void L3D::MainLoop(void) {
|
||||
earth_frame->SetPosition(vector3d(149598000000.0, 0, 0));
|
||||
earth_frame->SetRadius(2*380000000); /* 2 moon orbital radii. */
|
||||
|
||||
player = new Player();
|
||||
player = new Player(ShipType::SLEEK);
|
||||
player->SetLabel("Me");
|
||||
player->SetFrame(earth_frame);
|
||||
player->SetPosition(vector3d(100, 0, 0));
|
||||
Space::AddBody(player);
|
||||
|
||||
for(int i = 0; i < 4; i++) {
|
||||
Ship* body = new Ship();
|
||||
Ship* body = new Ship(ShipType::LADYBIRD);
|
||||
char buf[64];
|
||||
snprintf(buf, sizeof(buf), "X%c-0%02d", "A"+i, i);
|
||||
body->SetLabel(buf);
|
||||
|
@ -8,9 +8,10 @@
|
||||
|
||||
#define DEG_2_RAD 0.0174532925
|
||||
|
||||
Player::Player(void) : Ship() {
|
||||
Player::Player(ShipType::Type shipType) : Ship(shipType) {
|
||||
m_external_view_rotx = m_external_view_roty = 0;
|
||||
m_external_view_dist = 200;
|
||||
m_mouseCMov[0] = m_mouseCMov[1] = 0;
|
||||
}
|
||||
|
||||
void Player::Render(const Frame* camFrame) {
|
||||
@ -49,7 +50,8 @@ void Player::ApplyExternalViewRotation(void) {
|
||||
glRotatef(-m_external_view_roty, 0, 1, 0);
|
||||
}
|
||||
|
||||
#define MOUSE_ACCEL 400
|
||||
#define MOUSE_CTRL_AREA 10.0f
|
||||
#define MOUSE_RESTITUTION 0.9f
|
||||
|
||||
void Player::AITurn(void) {
|
||||
int mouseMotion[2];
|
||||
@ -63,10 +65,18 @@ void Player::AITurn(void) {
|
||||
if(time_step == 0) return;
|
||||
if(GetDockedWith()) return;
|
||||
|
||||
L3D::GetMouseMotion(mouseMotion);
|
||||
float mx, my;
|
||||
mx = -mouseMotion[0]*time_step*MOUSE_ACCEL;
|
||||
my = mouseMotion[1]*time_step*MOUSE_ACCEL;
|
||||
|
||||
{
|
||||
float restitution = powf(MOUSE_RESTITUTION, time_step);
|
||||
L3D::GetMouseMotion(mouseMotion);
|
||||
m_mouseCMov[0] += mouseMotion[0];
|
||||
m_mouseCMov[1] += mouseMotion[1];
|
||||
m_mouseCMov[0] = CLAMP(m_mouseCMov[0]*restitution, -MOUSE_CTRL_AREA, MOUSE_CTRL_AREA);
|
||||
m_mouseCMov[1] = CLAMP(m_mouseCMov[1]*restitution, -MOUSE_CTRL_AREA, MOUSE_CTRL_AREA);
|
||||
mx = -m_mouseCMov[0] / MOUSE_CTRL_AREA;
|
||||
my = m_mouseCMov[1] / MOUSE_CTRL_AREA;
|
||||
}
|
||||
|
||||
ClearThrusterState();
|
||||
if(L3D::KeyState(SDLK_w)) SetThrusterState(ShipType::THRUSTER_REAR, 1.0f);
|
||||
@ -87,11 +97,10 @@ void Player::AITurn(void) {
|
||||
*/
|
||||
mx /= ts2;
|
||||
my /= ts2;
|
||||
if(L3D::MouseButtonState(3) && (mouseMotion[0] || mouseMotion[1])) {
|
||||
if(L3D::MouseButtonState(3)) {
|
||||
SetAngThrusterState(1, mx);
|
||||
SetAngThrusterState(0, my);
|
||||
} else if(L3D::GetCamType() != L3D::CAM_EXTERNAL) {
|
||||
float tq = 100/ts2;
|
||||
float ax = 0;
|
||||
float ay = 0;
|
||||
if(L3D::KeyState(SDLK_LEFT)) ay += 1;
|
||||
|
@ -4,7 +4,7 @@
|
||||
|
||||
class Player : public Ship {
|
||||
public:
|
||||
Player(void);
|
||||
Player(ShipType::Type shipType);
|
||||
virtual void AITurn();
|
||||
virtual void Render(const Frame* camFrame);
|
||||
void DrawHUD(const Frame* cam_frame);
|
||||
@ -12,6 +12,7 @@ public:
|
||||
vector3d GetExternalViewTranslation(void);
|
||||
void ApplyExternalViewRotation(void);
|
||||
private:
|
||||
float m_mouseCMov[2];
|
||||
float m_external_view_rotx, m_external_view_roty;
|
||||
float m_external_view_dist;
|
||||
};
|
||||
|
@ -6,10 +6,10 @@
|
||||
#include "sbre/sbre.h"
|
||||
#include "space.h"
|
||||
|
||||
Ship::Ship(void) : RigidBody() {
|
||||
Ship::Ship(ShipType::Type shipType) : RigidBody() {
|
||||
m_dockedWith = 0;
|
||||
m_mesh = 0;
|
||||
m_shipType = ShipType::COBRA3;
|
||||
m_shipType = shipType;
|
||||
m_angThrusters[0] = m_angThrusters[1] = m_angThrusters[2] = 0;
|
||||
m_laserCollisionObj.owner = this;
|
||||
for(int i = 0; i < ShipType::GUNMOUNT_MAX; i++) {
|
||||
@ -127,6 +127,7 @@ static ObjParams params = {
|
||||
};
|
||||
|
||||
void Ship::Render(const Frame* camFrame) {
|
||||
const ShipType& stype = GetShipType();
|
||||
params.angthrust[0] = m_angThrusters[0];
|
||||
params.angthrust[1] = m_angThrusters[1];
|
||||
params.angthrust[2] = m_angThrusters[2];
|
||||
@ -135,6 +136,6 @@ void Ship::Render(const Frame* camFrame) {
|
||||
params.linthrust[2] = m_thrusters[ShipType::THRUSTER_REAR] - m_thrusters[ShipType::THRUSTER_FRONT];
|
||||
strncpy(params.pText[0], GetLabel().c_str(), sizeof(params.pText));
|
||||
|
||||
RenderSbreModel(camFrame, 10, ¶ms);
|
||||
RenderSbreModel(camFrame, stype.sbreModel, ¶ms);
|
||||
}
|
||||
|
||||
|
@ -7,7 +7,7 @@ class SpaceStation;
|
||||
|
||||
class Ship : public RigidBody {
|
||||
public:
|
||||
Ship(void);
|
||||
Ship(ShipType::Type shipType);
|
||||
virtual void AITurn(void);
|
||||
virtual Object::Type GetType(void) { return Object::SHIP; }
|
||||
virtual void SetDockedWith(SpaceStation*);
|
||||
|
@ -1,7 +1,35 @@
|
||||
#include "ship_type.h"
|
||||
|
||||
const ShipType ShipType::types[1] = {
|
||||
const ShipType ShipType::types[] = {
|
||||
{
|
||||
/*
|
||||
* Besides running a wicked corporatist regime in the sirius system,
|
||||
* Sirius corporation make a range of lovely ships!
|
||||
*/
|
||||
"Sirius Interdictor", 10,
|
||||
{ 250, -250, 50, -50, -50, 50 },
|
||||
700.0,
|
||||
{
|
||||
{ vector3f(0, -0.5, 0), vector3f(0, 0, -1) },
|
||||
{ vector3f(0, 0, 0), vector3f(0, 0, 1) }
|
||||
}
|
||||
},
|
||||
{
|
||||
/*
|
||||
* I should outsource name choosing, or this happens..
|
||||
*/
|
||||
"Ladybird Starfighter",
|
||||
13,
|
||||
{ 250, -250, 50, -50, -50, 50 },
|
||||
500.0,
|
||||
{
|
||||
{ vector3f(0, -0.5, 0), vector3f(0, 0, -1) },
|
||||
{ vector3f(0, 0, 0), vector3f(0, 0, 1) }
|
||||
}
|
||||
},
|
||||
{
|
||||
"Flowerfairy Heavy Trader",
|
||||
14,
|
||||
{ 250, -250, 50, -50, -50, 50 },
|
||||
500.0,
|
||||
{
|
||||
|
@ -6,10 +6,12 @@ struct ShipType {
|
||||
public:
|
||||
enum Thruster { THRUSTER_FRONT, THRUSTER_REAR, THRUSTER_TOP, THRUSTER_BOTTOM,
|
||||
THRUSTER_LEFT, THRUSTER_RIGHT, THRUSTER_MAX };
|
||||
enum Type { COBRA3 };
|
||||
enum Type { SLEEK, LADYBIRD, FLOWERFAIRY };
|
||||
enum { GUNMOUNT_MAX = 2 };
|
||||
|
||||
/*******************************/
|
||||
const char* name;
|
||||
int sbreModel;
|
||||
float linThrust[THRUSTER_MAX];
|
||||
float angThrust;
|
||||
struct GunMount {
|
||||
@ -18,6 +20,6 @@ public:
|
||||
} gunMount[GUNMOUNT_MAX];
|
||||
/*******************************/
|
||||
|
||||
static const ShipType types[1];
|
||||
static const ShipType types[];
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user