1
0
Fork 0
blockofighter/src/object.h

129 lines
3.2 KiB
C
Raw Permalink Normal View History

2014-02-16 14:32:28 +00:00
#ifndef __OBJECT_H_INCLUDED__
#define __OBJECT_H_INCLUDED__
class Object;
#define EPSILON 1.0e-20
#include <stdlib.h>
#include "shape.h"
#include "appearance.h"
2015-06-03 12:29:34 +00:00
struct objectlist {
Object *object;
objectlist *next;
2014-02-16 14:32:28 +00:00
};
2015-06-03 12:29:34 +00:00
class Object {
2014-02-16 14:32:28 +00:00
public:
2015-06-03 12:29:34 +00:00
float invmass;
2014-02-16 14:32:28 +00:00
2015-06-03 12:29:34 +00:00
/* Linear movement:
* position <-> paikka (x)
* velocity <-> nopeus (v)
* momentum <-> liikemäärä (p)
* force <-> voima (F)
* x' = v
* p' = F
* p = mv
* F = ma
* v' = a
*/
2014-02-16 14:32:28 +00:00
2015-06-03 12:29:34 +00:00
float position[3];
// derivative: velocity = momentum / mass
2014-02-16 14:32:28 +00:00
2015-06-03 12:29:34 +00:00
float momentum[3]; //, oldmomentum[3];
// derivative: force
2014-02-16 14:32:28 +00:00
2015-06-03 12:29:34 +00:00
// float force[3]; //Temporary properties
// float externalforce[3];
2014-02-16 14:32:28 +00:00
2015-06-03 12:29:34 +00:00
/* Angular movement:
* rotation <-> orientaatio (R)
* angular velocity <-> kulmanopeus (w)
* angular momentum <-> pyörimisliikemäärä, vääntömomentti (L)
* torque <-> voiman momentti (M,T)
* moment of inertia <-> hitausmomentti (J,I)
* angular acceleration <-> kulmakiihtyvyys (a)
* L = J*w
* R' = Star(L) * R
* T = J*a
* w' = a
* L' = T
*/
2014-02-16 14:32:28 +00:00
2015-06-03 12:29:34 +00:00
float invmomentofinertia;
2014-02-16 14:32:28 +00:00
2015-06-03 12:29:34 +00:00
float rotation[9];
// derivative: StarOperation(angularvelocity) * rotation
2014-02-16 14:32:28 +00:00
2015-06-03 12:29:34 +00:00
float angularmomentum[3];
// angular momentum = angular velocity * moment of inertia
// derivative: torque = angular acceleration * moment of inertia
2014-02-16 14:32:28 +00:00
2015-06-03 12:29:34 +00:00
// float torque[3]; //Temporary property
2014-02-16 14:32:28 +00:00
2015-06-03 12:29:34 +00:00
void moveStep(float dt);
// void applyForces(float dt);
2014-02-16 14:32:28 +00:00
2015-06-03 12:29:34 +00:00
void calculateStateVariables(void);
2014-02-16 14:32:28 +00:00
2015-06-03 12:29:34 +00:00
int collisiongroup;
2014-02-16 14:32:28 +00:00
2015-06-03 12:29:34 +00:00
void addImpulse(float *impulse, float *contactpoint);
2014-02-16 14:32:28 +00:00
2015-06-03 12:29:34 +00:00
Appearance *appearance;
Shape *geometry;
2014-02-16 14:32:28 +00:00
2015-06-03 12:29:34 +00:00
bool gravity;
2014-02-16 14:32:28 +00:00
2015-06-03 12:29:34 +00:00
Object(void);
2014-02-16 14:32:28 +00:00
2015-06-03 12:29:34 +00:00
virtual void prepare(void);
virtual void move(void);
virtual void draw(void);
2014-02-16 14:32:28 +00:00
2015-06-03 12:29:34 +00:00
void setPosition(float x, float y, float z);
void getPosition(float *position);
2014-02-16 14:32:28 +00:00
2015-06-03 12:29:34 +00:00
// Gets velocity from object and return it in "velocity"
void getVelocity(float *velocity);
2014-02-16 14:32:28 +00:00
2015-06-03 12:29:34 +00:00
// Gets velocity from object for point "point" with
// tangential speed and return it in "velocity"
void getVelocity(float *velocity, float *point);
2014-02-16 14:32:28 +00:00
2015-06-03 12:29:34 +00:00
void getTangentialVelocity(float *target, float *point);
2014-02-16 14:32:28 +00:00
2015-06-03 12:29:34 +00:00
void getMomentum(float *momentum);
// void getForce(float *force);
void setMass(float mass);
float getMass(void);
void setCollisionGroup(int group);
int getCollisionGroup(void);
2014-02-16 14:32:28 +00:00
2015-06-03 12:29:34 +00:00
void transformPoint(float *newpoint, float *oldpoint);
void unTransformPoint(float *newpoint, float *oldpoint);
void transformVector(float *newvector, float *oldvector);
void unTransformVector(float *newvector, float *oldvector);
2014-02-16 14:32:28 +00:00
2015-06-03 12:29:34 +00:00
void addExternalForce(float *force);
2014-02-16 14:32:28 +00:00
2015-06-03 12:29:34 +00:00
void setGravity(bool enabled);
2014-02-16 14:32:28 +00:00
2015-06-03 12:29:34 +00:00
virtual void hitForce(float speed, float *speed2, Object *source);
2014-02-16 14:32:28 +00:00
2015-06-03 12:29:34 +00:00
friend class ObjectLink;
// friend void collide(Object *source, Object *target, float *normal, float
// *contactpoint);
friend bool checkCollisions(Object *object, float *contactnormal);
2014-02-16 14:32:28 +00:00
2015-06-03 12:29:34 +00:00
// Temporary state variables
float velocity[3];
float angularvelocity[3];
2014-02-16 14:32:28 +00:00
};
#endif