src/proto2/Physics.hh
author saiam
Sat, 29 Nov 2008 17:37:51 +0000
changeset 134 d45109cf5e9d
parent 133 c05e84ccc4b3
child 135 d5624d698a78
permissions -rw-r--r--
Moved unnecessarily protected function to private
42
eb1a93a38cde lazy commit that breaks everything, should be a branch
terom
parents:
diff changeset
     1
#ifndef PHYSICS_HH
eb1a93a38cde lazy commit that breaks everything, should be a branch
terom
parents:
diff changeset
     2
#define PHYSICS_HH
eb1a93a38cde lazy commit that breaks everything, should be a branch
terom
parents:
diff changeset
     3
eb1a93a38cde lazy commit that breaks everything, should be a branch
terom
parents:
diff changeset
     4
#include "Vector.hh"
eb1a93a38cde lazy commit that breaks everything, should be a branch
terom
parents:
diff changeset
     5
72
04428c5e548c Enum fix
ekku
parents: 71
diff changeset
     6
#include <vector>
83
cbba9729e92b Integrointia fyssaan, jotain pikkubugausta havaittavissa.
saiam
parents: 79
diff changeset
     7
#include <queue>
50
9e1a6506f5a1 some rough-handed code modifications towards a newer, better, working Physics
terom
parents: 48
diff changeset
     8
#include <ClanLib/core.h>
9e1a6506f5a1 some rough-handed code modifications towards a newer, better, working Physics
terom
parents: 48
diff changeset
     9
79
295ecb26d8ff jotain mik? hajottaa kaiken
ekku
parents: 78
diff changeset
    10
typedef uint16_t TimeMS;
78
bbc21da84813 This is probably better way of representing time
saiam
parents: 77
diff changeset
    11
79
295ecb26d8ff jotain mik? hajottaa kaiken
ekku
parents: 78
diff changeset
    12
const TimeMS PHYSICS_TICK_MS = 10;
42
eb1a93a38cde lazy commit that breaks everything, should be a branch
terom
parents:
diff changeset
    13
72
04428c5e548c Enum fix
ekku
parents: 71
diff changeset
    14
enum TerrainType {EMPTY, DIRT, ROCK};
71
b5dbb83daa94 En takaa et k??ntyy en?? 8)
ekku
parents: 70
diff changeset
    15
95
10704e1df844 Normal stuff
ekku
parents: 94
diff changeset
    16
const Vector DIRECTIONS[] = { Vector(0,-1), Vector(1,-1), Vector(1,0), Vector(1,1),
10704e1df844 Normal stuff
ekku
parents: 94
diff changeset
    17
							Vector(0,1), Vector(-1,1), Vector(-1,0), Vector(-1,-1) };
10704e1df844 Normal stuff
ekku
parents: 94
diff changeset
    18
50
9e1a6506f5a1 some rough-handed code modifications towards a newer, better, working Physics
terom
parents: 48
diff changeset
    19
// forward-declare
9e1a6506f5a1 some rough-handed code modifications towards a newer, better, working Physics
terom
parents: 48
diff changeset
    20
class PhysicsObject;
85
351cb6b69c04 Making things simpler. More to come soon.
saiam
parents: 83
diff changeset
    21
typedef Vector Force;
83
cbba9729e92b Integrointia fyssaan, jotain pikkubugausta havaittavissa.
saiam
parents: 79
diff changeset
    22
struct Derivative;
50
9e1a6506f5a1 some rough-handed code modifications towards a newer, better, working Physics
terom
parents: 48
diff changeset
    23
42
eb1a93a38cde lazy commit that breaks everything, should be a branch
terom
parents:
diff changeset
    24
class PhysicsWorld {
60
26571fd9a8d1 physics is starting to work
terom
parents: 58
diff changeset
    25
    friend class PhysicsObject;
70
a5b7499219a4 Some drafts
saiam
parents: 69
diff changeset
    26
    
a5b7499219a4 Some drafts
saiam
parents: 69
diff changeset
    27
private:
a5b7499219a4 Some drafts
saiam
parents: 69
diff changeset
    28
    CL_Timer tick_timer;
105
91e3f3806b31 set UDP sockets as nonblocking
terom
parents: 98
diff changeset
    29
91e3f3806b31 set UDP sockets as nonblocking
terom
parents: 98
diff changeset
    30
    uint32_t tick_counter;
70
a5b7499219a4 Some drafts
saiam
parents: 69
diff changeset
    31
    
a5b7499219a4 Some drafts
saiam
parents: 69
diff changeset
    32
protected:
a5b7499219a4 Some drafts
saiam
parents: 69
diff changeset
    33
    std::vector<PhysicsObject*> objects;
a5b7499219a4 Some drafts
saiam
parents: 69
diff changeset
    34
    Vector gravity;
86
ed31ece6f340 Segfault <3 (mik? oli odotettavaa)
saiam
parents: 85
diff changeset
    35
    Vector dimensions;
ed31ece6f340 Segfault <3 (mik? oli odotettavaa)
saiam
parents: 85
diff changeset
    36
ed31ece6f340 Segfault <3 (mik? oli odotettavaa)
saiam
parents: 85
diff changeset
    37
72
04428c5e548c Enum fix
ekku
parents: 71
diff changeset
    38
    std::vector<std::vector<TerrainType> > terrain;
71
b5dbb83daa94 En takaa et k??ntyy en?? 8)
ekku
parents: 70
diff changeset
    39
70
a5b7499219a4 Some drafts
saiam
parents: 69
diff changeset
    40
    CL_SlotContainer slots;
a5b7499219a4 Some drafts
saiam
parents: 69
diff changeset
    41
    
a5b7499219a4 Some drafts
saiam
parents: 69
diff changeset
    42
    PhysicsWorld (Vector gravity, Vector dimensions);
86
ed31ece6f340 Segfault <3 (mik? oli odotettavaa)
saiam
parents: 85
diff changeset
    43
ed31ece6f340 Segfault <3 (mik? oli odotettavaa)
saiam
parents: 85
diff changeset
    44
ed31ece6f340 Segfault <3 (mik? oli odotettavaa)
saiam
parents: 85
diff changeset
    45
public:
70
a5b7499219a4 Some drafts
saiam
parents: 69
diff changeset
    46
    
123
7efb63402b2b Documenting a little bit
saiam
parents: 122
diff changeset
    47
    /**
7efb63402b2b Documenting a little bit
saiam
parents: 122
diff changeset
    48
     * Adds objects to the physicsworld.
7efb63402b2b Documenting a little bit
saiam
parents: 122
diff changeset
    49
     *
7efb63402b2b Documenting a little bit
saiam
parents: 122
diff changeset
    50
     * @param object Pointer to PhysicsObject to add.
7efb63402b2b Documenting a little bit
saiam
parents: 122
diff changeset
    51
     */
70
a5b7499219a4 Some drafts
saiam
parents: 69
diff changeset
    52
    void addObject (PhysicsObject *object);
123
7efb63402b2b Documenting a little bit
saiam
parents: 122
diff changeset
    53
    
7efb63402b2b Documenting a little bit
saiam
parents: 122
diff changeset
    54
    /**
7efb63402b2b Documenting a little bit
saiam
parents: 122
diff changeset
    55
     * Advance one time step in physics simulation.
7efb63402b2b Documenting a little bit
saiam
parents: 122
diff changeset
    56
     */
70
a5b7499219a4 Some drafts
saiam
parents: 69
diff changeset
    57
    void tick (void);
123
7efb63402b2b Documenting a little bit
saiam
parents: 122
diff changeset
    58
    /**
7efb63402b2b Documenting a little bit
saiam
parents: 122
diff changeset
    59
     * Get current tick in physics simulation.
7efb63402b2b Documenting a little bit
saiam
parents: 122
diff changeset
    60
     */
105
91e3f3806b31 set UDP sockets as nonblocking
terom
parents: 98
diff changeset
    61
    uint32_t getTick (void);
91e3f3806b31 set UDP sockets as nonblocking
terom
parents: 98
diff changeset
    62
123
7efb63402b2b Documenting a little bit
saiam
parents: 122
diff changeset
    63
  
7efb63402b2b Documenting a little bit
saiam
parents: 122
diff changeset
    64
    /**
7efb63402b2b Documenting a little bit
saiam
parents: 122
diff changeset
    65
     * Generate random terrain.
7efb63402b2b Documenting a little bit
saiam
parents: 122
diff changeset
    66
     */
74
279788e460fd changed some tabs from Physics.hh
nireco
parents: 73
diff changeset
    67
    void generateTerrain (int seed);
77
98dc9008d15f changed collision detection, remove old if content with new
nireco
parents: 75
diff changeset
    68
123
7efb63402b2b Documenting a little bit
saiam
parents: 122
diff changeset
    69
    /**
7efb63402b2b Documenting a little bit
saiam
parents: 122
diff changeset
    70
     * Return a normal for the wall that has been hit.
7efb63402b2b Documenting a little bit
saiam
parents: 122
diff changeset
    71
     *
7efb63402b2b Documenting a little bit
saiam
parents: 122
diff changeset
    72
     * @param hitPoint The point of the wall that has been hit.
7efb63402b2b Documenting a little bit
saiam
parents: 122
diff changeset
    73
     * @param prevPoint The point from where we were coming.
7efb63402b2b Documenting a little bit
saiam
parents: 122
diff changeset
    74
     */
98
606c419e42a7 Ei se viel? k??nny kun on sienestetty.
saiam
parents: 96
diff changeset
    75
    Vector getNormal(Vector hitPoint, Vector prevPoint);
606c419e42a7 Ei se viel? k??nny kun on sienestetty.
saiam
parents: 96
diff changeset
    76
123
7efb63402b2b Documenting a little bit
saiam
parents: 122
diff changeset
    77
    /**
7efb63402b2b Documenting a little bit
saiam
parents: 122
diff changeset
    78
     * Return terrain type in specific position.
7efb63402b2b Documenting a little bit
saiam
parents: 122
diff changeset
    79
     *
7efb63402b2b Documenting a little bit
saiam
parents: 122
diff changeset
    80
     * @param x x-coordinate
7efb63402b2b Documenting a little bit
saiam
parents: 122
diff changeset
    81
     * @param y y-coordinate
7efb63402b2b Documenting a little bit
saiam
parents: 122
diff changeset
    82
     */
112
1b9ad61bdf2d added method for removing ground, not used anywhere
nireco
parents: 108
diff changeset
    83
    TerrainType getType(int x, int y) const;
123
7efb63402b2b Documenting a little bit
saiam
parents: 122
diff changeset
    84
    /**
7efb63402b2b Documenting a little bit
saiam
parents: 122
diff changeset
    85
     * Return terrain type in specific position.
7efb63402b2b Documenting a little bit
saiam
parents: 122
diff changeset
    86
     *
7efb63402b2b Documenting a little bit
saiam
parents: 122
diff changeset
    87
     * @param pos Position vector
7efb63402b2b Documenting a little bit
saiam
parents: 122
diff changeset
    88
     */
77
98dc9008d15f changed collision detection, remove old if content with new
nireco
parents: 75
diff changeset
    89
    TerrainType getType(Vector pos) const;
112
1b9ad61bdf2d added method for removing ground, not used anywhere
nireco
parents: 108
diff changeset
    90
128
890ac82cdcc0 Documenting more, cleaning variables. This code needs some serious
saiam
parents: 123
diff changeset
    91
    /**
890ac82cdcc0 Documenting more, cleaning variables. This code needs some serious
saiam
parents: 123
diff changeset
    92
     * Remove ground from the terrain. Removes a circle with given
890ac82cdcc0 Documenting more, cleaning variables. This code needs some serious
saiam
parents: 123
diff changeset
    93
     * radius.
890ac82cdcc0 Documenting more, cleaning variables. This code needs some serious
saiam
parents: 123
diff changeset
    94
     *
890ac82cdcc0 Documenting more, cleaning variables. This code needs some serious
saiam
parents: 123
diff changeset
    95
     * @param x center x coordinate
890ac82cdcc0 Documenting more, cleaning variables. This code needs some serious
saiam
parents: 123
diff changeset
    96
     * @param y center y coordinate
890ac82cdcc0 Documenting more, cleaning variables. This code needs some serious
saiam
parents: 123
diff changeset
    97
     * @param r circle radius
890ac82cdcc0 Documenting more, cleaning variables. This code needs some serious
saiam
parents: 123
diff changeset
    98
     */
112
1b9ad61bdf2d added method for removing ground, not used anywhere
nireco
parents: 108
diff changeset
    99
    void removeGround(int x, int y, float r);
128
890ac82cdcc0 Documenting more, cleaning variables. This code needs some serious
saiam
parents: 123
diff changeset
   100
    
890ac82cdcc0 Documenting more, cleaning variables. This code needs some serious
saiam
parents: 123
diff changeset
   101
    /**
890ac82cdcc0 Documenting more, cleaning variables. This code needs some serious
saiam
parents: 123
diff changeset
   102
     * Remove ground from the terrain. Removes a circle with given
890ac82cdcc0 Documenting more, cleaning variables. This code needs some serious
saiam
parents: 123
diff changeset
   103
     * radius.
890ac82cdcc0 Documenting more, cleaning variables. This code needs some serious
saiam
parents: 123
diff changeset
   104
     *
890ac82cdcc0 Documenting more, cleaning variables. This code needs some serious
saiam
parents: 123
diff changeset
   105
     * @param pos circle center
890ac82cdcc0 Documenting more, cleaning variables. This code needs some serious
saiam
parents: 123
diff changeset
   106
     * @param r circle radius
890ac82cdcc0 Documenting more, cleaning variables. This code needs some serious
saiam
parents: 123
diff changeset
   107
     */
112
1b9ad61bdf2d added method for removing ground, not used anywhere
nireco
parents: 108
diff changeset
   108
    void removeGround(Vector pos, float r);
42
eb1a93a38cde lazy commit that breaks everything, should be a branch
terom
parents:
diff changeset
   109
};
eb1a93a38cde lazy commit that breaks everything, should be a branch
terom
parents:
diff changeset
   110
eb1a93a38cde lazy commit that breaks everything, should be a branch
terom
parents:
diff changeset
   111
class PhysicsObject {
70
a5b7499219a4 Some drafts
saiam
parents: 69
diff changeset
   112
protected:
a5b7499219a4 Some drafts
saiam
parents: 69
diff changeset
   113
    PhysicsWorld &world;
83
cbba9729e92b Integrointia fyssaan, jotain pikkubugausta havaittavissa.
saiam
parents: 79
diff changeset
   114
    
70
a5b7499219a4 Some drafts
saiam
parents: 69
diff changeset
   115
    float mass;
a5b7499219a4 Some drafts
saiam
parents: 69
diff changeset
   116
    Vector position;
a5b7499219a4 Some drafts
saiam
parents: 69
diff changeset
   117
    Vector velocity;
128
890ac82cdcc0 Documenting more, cleaning variables. This code needs some serious
saiam
parents: 123
diff changeset
   118
    float aim; // Aim direction (half circle)
890ac82cdcc0 Documenting more, cleaning variables. This code needs some serious
saiam
parents: 123
diff changeset
   119
    bool facingRight; // Player facing
890ac82cdcc0 Documenting more, cleaning variables. This code needs some serious
saiam
parents: 123
diff changeset
   120
    bool inAir; // Is the object "on the ground"
83
cbba9729e92b Integrointia fyssaan, jotain pikkubugausta havaittavissa.
saiam
parents: 79
diff changeset
   121
129
b1ae79a2d2f0 More documentation
saiam
parents: 128
diff changeset
   122
     PhysicsObject (PhysicsWorld &world, float mass, Vector position, Vector velocity);
113
1b8ade19eedd PhysicsObject now has virtual destructor
nireco
parents: 112
diff changeset
   123
    ~PhysicsObject() {}   
108
1b93045a5b0a T?ht?in lis?tty, tosin se piirret??n tosi rumasti.
saiam
parents: 107
diff changeset
   124
96
4a801210096c fix movement physics+network code to some degree, jumping is now buggy?
terom
parents: 95
diff changeset
   125
    /**
108
1b93045a5b0a T?ht?in lis?tty, tosin se piirret??n tosi rumasti.
saiam
parents: 107
diff changeset
   126
     * Adds force to the force queue. Force queue is emptied on each
1b93045a5b0a T?ht?in lis?tty, tosin se piirret??n tosi rumasti.
saiam
parents: 107
diff changeset
   127
     * tick. Forces that last over one tick are also handled. This
1b93045a5b0a T?ht?in lis?tty, tosin se piirret??n tosi rumasti.
saiam
parents: 107
diff changeset
   128
     * function is only used to handle in air movement.
1b93045a5b0a T?ht?in lis?tty, tosin se piirret??n tosi rumasti.
saiam
parents: 107
diff changeset
   129
     *
1b93045a5b0a T?ht?in lis?tty, tosin se piirret??n tosi rumasti.
saiam
parents: 107
diff changeset
   130
     * @param force Force vector.  
1b93045a5b0a T?ht?in lis?tty, tosin se piirret??n tosi rumasti.
saiam
parents: 107
diff changeset
   131
     */
133
c05e84ccc4b3 Made unnecessarily virtual function PhysicsObject::applyForce nonvirtual
saiam
parents: 132
diff changeset
   132
    void applyForce (Force force);
96
4a801210096c fix movement physics+network code to some degree, jumping is now buggy?
terom
parents: 95
diff changeset
   133
4a801210096c fix movement physics+network code to some degree, jumping is now buggy?
terom
parents: 95
diff changeset
   134
    /**
108
1b93045a5b0a T?ht?in lis?tty, tosin se piirret??n tosi rumasti.
saiam
parents: 107
diff changeset
   135
     * Changes player aim
129
b1ae79a2d2f0 More documentation
saiam
parents: 128
diff changeset
   136
     *
b1ae79a2d2f0 More documentation
saiam
parents: 128
diff changeset
   137
     * @param da Aim angle change
108
1b93045a5b0a T?ht?in lis?tty, tosin se piirret??n tosi rumasti.
saiam
parents: 107
diff changeset
   138
     */
1b93045a5b0a T?ht?in lis?tty, tosin se piirret??n tosi rumasti.
saiam
parents: 107
diff changeset
   139
    void changeAim(float da);
1b93045a5b0a T?ht?in lis?tty, tosin se piirret??n tosi rumasti.
saiam
parents: 107
diff changeset
   140
1b93045a5b0a T?ht?in lis?tty, tosin se piirret??n tosi rumasti.
saiam
parents: 107
diff changeset
   141
    /**
1b93045a5b0a T?ht?in lis?tty, tosin se piirret??n tosi rumasti.
saiam
parents: 107
diff changeset
   142
     * Set player facing.
129
b1ae79a2d2f0 More documentation
saiam
parents: 128
diff changeset
   143
     *
b1ae79a2d2f0 More documentation
saiam
parents: 128
diff changeset
   144
     * @param facingRight True if player is facing right.
108
1b93045a5b0a T?ht?in lis?tty, tosin se piirret??n tosi rumasti.
saiam
parents: 107
diff changeset
   145
     */ 
129
b1ae79a2d2f0 More documentation
saiam
parents: 128
diff changeset
   146
    void setFacing(bool facingRight);
108
1b93045a5b0a T?ht?in lis?tty, tosin se piirret??n tosi rumasti.
saiam
parents: 107
diff changeset
   147
1b93045a5b0a T?ht?in lis?tty, tosin se piirret??n tosi rumasti.
saiam
parents: 107
diff changeset
   148
    /**
96
4a801210096c fix movement physics+network code to some degree, jumping is now buggy?
terom
parents: 95
diff changeset
   149
     * Called on network clients to sync state from server
4a801210096c fix movement physics+network code to some degree, jumping is now buggy?
terom
parents: 95
diff changeset
   150
     */
107
505bfa531496 send inAir attribute as part of NETWORK_PLAYER_POSITION...
terom
parents: 105
diff changeset
   151
    void updatePhysics (Vector position, Vector velocity, bool inAir);
96
4a801210096c fix movement physics+network code to some degree, jumping is now buggy?
terom
parents: 95
diff changeset
   152
4a801210096c fix movement physics+network code to some degree, jumping is now buggy?
terom
parents: 95
diff changeset
   153
    /**
4a801210096c fix movement physics+network code to some degree, jumping is now buggy?
terom
parents: 95
diff changeset
   154
     * Handle ground-jumping
4a801210096c fix movement physics+network code to some degree, jumping is now buggy?
terom
parents: 95
diff changeset
   155
     */
98
606c419e42a7 Ei se viel? k??nny kun on sienestetty.
saiam
parents: 96
diff changeset
   156
    void jump (void);
606c419e42a7 Ei se viel? k??nny kun on sienestetty.
saiam
parents: 96
diff changeset
   157
606c419e42a7 Ei se viel? k??nny kun on sienestetty.
saiam
parents: 96
diff changeset
   158
    /**
606c419e42a7 Ei se viel? k??nny kun on sienestetty.
saiam
parents: 96
diff changeset
   159
     * Handle ground-bounce
129
b1ae79a2d2f0 More documentation
saiam
parents: 128
diff changeset
   160
     *
b1ae79a2d2f0 More documentation
saiam
parents: 128
diff changeset
   161
     * @param normal Normal vector relative to which to bounce
98
606c419e42a7 Ei se viel? k??nny kun on sienestetty.
saiam
parents: 96
diff changeset
   162
     */
606c419e42a7 Ei se viel? k??nny kun on sienestetty.
saiam
parents: 96
diff changeset
   163
    void bounce (Vector normal);
96
4a801210096c fix movement physics+network code to some degree, jumping is now buggy?
terom
parents: 95
diff changeset
   164
70
a5b7499219a4 Some drafts
saiam
parents: 69
diff changeset
   165
private:
129
b1ae79a2d2f0 More documentation
saiam
parents: 128
diff changeset
   166
    /**
b1ae79a2d2f0 More documentation
saiam
parents: 128
diff changeset
   167
     * Handle player movement and applying forces.
b1ae79a2d2f0 More documentation
saiam
parents: 128
diff changeset
   168
     */
70
a5b7499219a4 Some drafts
saiam
parents: 69
diff changeset
   169
    void updatePosition (void);
129
b1ae79a2d2f0 More documentation
saiam
parents: 128
diff changeset
   170
b1ae79a2d2f0 More documentation
saiam
parents: 128
diff changeset
   171
    /*
b1ae79a2d2f0 More documentation
saiam
parents: 128
diff changeset
   172
     * TODO: Documentation
b1ae79a2d2f0 More documentation
saiam
parents: 128
diff changeset
   173
     */
b1ae79a2d2f0 More documentation
saiam
parents: 128
diff changeset
   174
    bool possibleLocation (Vector loc);
69
309c11126949 little cleanup
saiam
parents: 66
diff changeset
   175
70
a5b7499219a4 Some drafts
saiam
parents: 69
diff changeset
   176
    /**
a5b7499219a4 Some drafts
saiam
parents: 69
diff changeset
   177
     * Use RK4 to integrate the effects of force over a time intervall.
129
b1ae79a2d2f0 More documentation
saiam
parents: 128
diff changeset
   178
     *
b1ae79a2d2f0 More documentation
saiam
parents: 128
diff changeset
   179
     * @param force Force to integrate
b1ae79a2d2f0 More documentation
saiam
parents: 128
diff changeset
   180
     * @param dt Time intervall
70
a5b7499219a4 Some drafts
saiam
parents: 69
diff changeset
   181
     */
85
351cb6b69c04 Making things simpler. More to come soon.
saiam
parents: 83
diff changeset
   182
    void integrate(Force force, TimeMS dt);
129
b1ae79a2d2f0 More documentation
saiam
parents: 128
diff changeset
   183
b1ae79a2d2f0 More documentation
saiam
parents: 128
diff changeset
   184
    /**
b1ae79a2d2f0 More documentation
saiam
parents: 128
diff changeset
   185
     * Evaluate the value of the derivative at given time
b1ae79a2d2f0 More documentation
saiam
parents: 128
diff changeset
   186
     *
b1ae79a2d2f0 More documentation
saiam
parents: 128
diff changeset
   187
     * @param force Force
b1ae79a2d2f0 More documentation
saiam
parents: 128
diff changeset
   188
     * @param dt Time
b1ae79a2d2f0 More documentation
saiam
parents: 128
diff changeset
   189
     * @param d Last derivative
b1ae79a2d2f0 More documentation
saiam
parents: 128
diff changeset
   190
     */
85
351cb6b69c04 Making things simpler. More to come soon.
saiam
parents: 83
diff changeset
   191
    Derivative evaluate(Force force, TimeMS dt, Derivative &d);
129
b1ae79a2d2f0 More documentation
saiam
parents: 128
diff changeset
   192
b1ae79a2d2f0 More documentation
saiam
parents: 128
diff changeset
   193
    /**
b1ae79a2d2f0 More documentation
saiam
parents: 128
diff changeset
   194
     * Return object acceleration with given force.
b1ae79a2d2f0 More documentation
saiam
parents: 128
diff changeset
   195
     *
b1ae79a2d2f0 More documentation
saiam
parents: 128
diff changeset
   196
     * @param force Force
b1ae79a2d2f0 More documentation
saiam
parents: 128
diff changeset
   197
     * @return acceleration
b1ae79a2d2f0 More documentation
saiam
parents: 128
diff changeset
   198
     */
85
351cb6b69c04 Making things simpler. More to come soon.
saiam
parents: 83
diff changeset
   199
    Vector acceleration(const Force &force);
83
cbba9729e92b Integrointia fyssaan, jotain pikkubugausta havaittavissa.
saiam
parents: 79
diff changeset
   200
134
d45109cf5e9d Moved unnecessarily protected function to private
saiam
parents: 133
diff changeset
   201
    /**
d45109cf5e9d Moved unnecessarily protected function to private
saiam
parents: 133
diff changeset
   202
     * Handle ground movement
d45109cf5e9d Moved unnecessarily protected function to private
saiam
parents: 133
diff changeset
   203
     *
d45109cf5e9d Moved unnecessarily protected function to private
saiam
parents: 133
diff changeset
   204
     * @param right Boolean describing the movement direction.
d45109cf5e9d Moved unnecessarily protected function to private
saiam
parents: 133
diff changeset
   205
     * @return new position
d45109cf5e9d Moved unnecessarily protected function to private
saiam
parents: 133
diff changeset
   206
     */
d45109cf5e9d Moved unnecessarily protected function to private
saiam
parents: 133
diff changeset
   207
    Vector walk (bool right);
d45109cf5e9d Moved unnecessarily protected function to private
saiam
parents: 133
diff changeset
   208
129
b1ae79a2d2f0 More documentation
saiam
parents: 128
diff changeset
   209
    /*
b1ae79a2d2f0 More documentation
saiam
parents: 128
diff changeset
   210
     * Handle collision. TODO: This is not used. It probably should be?
b1ae79a2d2f0 More documentation
saiam
parents: 128
diff changeset
   211
     */
116
0d36aade845e some stuff, don't remember what
nireco
parents: 113
diff changeset
   212
    virtual void onCollision() {}
0d36aade845e some stuff, don't remember what
nireco
parents: 113
diff changeset
   213
132
957c3c184ea0 Changed some variables that were protected to private from PhysicsObject
saiam
parents: 131
diff changeset
   214
    // Shape of the object. The vector contains the polygon edge
957c3c184ea0 Changed some variables that were protected to private from PhysicsObject
saiam
parents: 131
diff changeset
   215
    // points relative to the object location.
957c3c184ea0 Changed some variables that were protected to private from PhysicsObject
saiam
parents: 131
diff changeset
   216
    std::vector<Vector> shape;
957c3c184ea0 Changed some variables that were protected to private from PhysicsObject
saiam
parents: 131
diff changeset
   217
    
957c3c184ea0 Changed some variables that were protected to private from PhysicsObject
saiam
parents: 131
diff changeset
   218
    // Force queue that is emptied on every tick
957c3c184ea0 Changed some variables that were protected to private from PhysicsObject
saiam
parents: 131
diff changeset
   219
    std::queue<Force> forceq;
957c3c184ea0 Changed some variables that were protected to private from PhysicsObject
saiam
parents: 131
diff changeset
   220
    // Helper variables for integration (TODO: should these be
957c3c184ea0 Changed some variables that were protected to private from PhysicsObject
saiam
parents: 131
diff changeset
   221
    // somewhere else?)
957c3c184ea0 Changed some variables that were protected to private from PhysicsObject
saiam
parents: 131
diff changeset
   222
    Vector posAfterTick;
957c3c184ea0 Changed some variables that were protected to private from PhysicsObject
saiam
parents: 131
diff changeset
   223
    Vector velAfterTick;
957c3c184ea0 Changed some variables that were protected to private from PhysicsObject
saiam
parents: 131
diff changeset
   224
70
a5b7499219a4 Some drafts
saiam
parents: 69
diff changeset
   225
public:
129
b1ae79a2d2f0 More documentation
saiam
parents: 128
diff changeset
   226
    /**
b1ae79a2d2f0 More documentation
saiam
parents: 128
diff changeset
   227
     * Get current object position.
b1ae79a2d2f0 More documentation
saiam
parents: 128
diff changeset
   228
b1ae79a2d2f0 More documentation
saiam
parents: 128
diff changeset
   229
     * @return position vector
b1ae79a2d2f0 More documentation
saiam
parents: 128
diff changeset
   230
     */
70
a5b7499219a4 Some drafts
saiam
parents: 69
diff changeset
   231
    Vector getPosition (void);
129
b1ae79a2d2f0 More documentation
saiam
parents: 128
diff changeset
   232
b1ae79a2d2f0 More documentation
saiam
parents: 128
diff changeset
   233
    /**
b1ae79a2d2f0 More documentation
saiam
parents: 128
diff changeset
   234
     * Return object shape.
b1ae79a2d2f0 More documentation
saiam
parents: 128
diff changeset
   235
     *
b1ae79a2d2f0 More documentation
saiam
parents: 128
diff changeset
   236
     * @return Polygon points
b1ae79a2d2f0 More documentation
saiam
parents: 128
diff changeset
   237
     */
108
1b93045a5b0a T?ht?in lis?tty, tosin se piirret??n tosi rumasti.
saiam
parents: 107
diff changeset
   238
    std::vector<Vector>& getShape(void);
129
b1ae79a2d2f0 More documentation
saiam
parents: 128
diff changeset
   239
b1ae79a2d2f0 More documentation
saiam
parents: 128
diff changeset
   240
    /**
b1ae79a2d2f0 More documentation
saiam
parents: 128
diff changeset
   241
     * Set object shape.
b1ae79a2d2f0 More documentation
saiam
parents: 128
diff changeset
   242
     *
b1ae79a2d2f0 More documentation
saiam
parents: 128
diff changeset
   243
     * @param shape Vector containing polygon points
b1ae79a2d2f0 More documentation
saiam
parents: 128
diff changeset
   244
     */
108
1b93045a5b0a T?ht?in lis?tty, tosin se piirret??n tosi rumasti.
saiam
parents: 107
diff changeset
   245
    void setShape (std::vector<Vector> shape);
1b93045a5b0a T?ht?in lis?tty, tosin se piirret??n tosi rumasti.
saiam
parents: 107
diff changeset
   246
129
b1ae79a2d2f0 More documentation
saiam
parents: 128
diff changeset
   247
    /**
b1ae79a2d2f0 More documentation
saiam
parents: 128
diff changeset
   248
     * Return object facing.
b1ae79a2d2f0 More documentation
saiam
parents: 128
diff changeset
   249
     *
b1ae79a2d2f0 More documentation
saiam
parents: 128
diff changeset
   250
     * @return Object facing (true if facing is right)
b1ae79a2d2f0 More documentation
saiam
parents: 128
diff changeset
   251
     */
108
1b93045a5b0a T?ht?in lis?tty, tosin se piirret??n tosi rumasti.
saiam
parents: 107
diff changeset
   252
    bool getFacing(void);
129
b1ae79a2d2f0 More documentation
saiam
parents: 128
diff changeset
   253
b1ae79a2d2f0 More documentation
saiam
parents: 128
diff changeset
   254
    /**
b1ae79a2d2f0 More documentation
saiam
parents: 128
diff changeset
   255
     * Return object aim angle.
b1ae79a2d2f0 More documentation
saiam
parents: 128
diff changeset
   256
     *
b1ae79a2d2f0 More documentation
saiam
parents: 128
diff changeset
   257
     * @return Object aim angle
b1ae79a2d2f0 More documentation
saiam
parents: 128
diff changeset
   258
     */
108
1b93045a5b0a T?ht?in lis?tty, tosin se piirret??n tosi rumasti.
saiam
parents: 107
diff changeset
   259
    float getAim(void);
1b93045a5b0a T?ht?in lis?tty, tosin se piirret??n tosi rumasti.
saiam
parents: 107
diff changeset
   260
129
b1ae79a2d2f0 More documentation
saiam
parents: 128
diff changeset
   261
    /**
b1ae79a2d2f0 More documentation
saiam
parents: 128
diff changeset
   262
     * Update object in physics simulation.
b1ae79a2d2f0 More documentation
saiam
parents: 128
diff changeset
   263
     */
70
a5b7499219a4 Some drafts
saiam
parents: 69
diff changeset
   264
    void tick (void);
42
eb1a93a38cde lazy commit that breaks everything, should be a branch
terom
parents:
diff changeset
   265
};
eb1a93a38cde lazy commit that breaks everything, should be a branch
terom
parents:
diff changeset
   266
83
cbba9729e92b Integrointia fyssaan, jotain pikkubugausta havaittavissa.
saiam
parents: 79
diff changeset
   267
struct Derivative {
cbba9729e92b Integrointia fyssaan, jotain pikkubugausta havaittavissa.
saiam
parents: 79
diff changeset
   268
    Vector dx; // Velocity
cbba9729e92b Integrointia fyssaan, jotain pikkubugausta havaittavissa.
saiam
parents: 79
diff changeset
   269
    Vector dv; // Acceleration
cbba9729e92b Integrointia fyssaan, jotain pikkubugausta havaittavissa.
saiam
parents: 79
diff changeset
   270
};
cbba9729e92b Integrointia fyssaan, jotain pikkubugausta havaittavissa.
saiam
parents: 79
diff changeset
   271
cbba9729e92b Integrointia fyssaan, jotain pikkubugausta havaittavissa.
saiam
parents: 79
diff changeset
   272
cbba9729e92b Integrointia fyssaan, jotain pikkubugausta havaittavissa.
saiam
parents: 79
diff changeset
   273
42
eb1a93a38cde lazy commit that breaks everything, should be a branch
terom
parents:
diff changeset
   274
#endif