src/proto2/Physics.hh
author saiam
Sat, 29 Nov 2008 17:59:49 +0000
changeset 135 d5624d698a78
parent 134 d45109cf5e9d
child 136 3a15a5937f7a
permissions -rw-r--r--
Physics.hh rewrite. Documenting and suggesting changes.
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
72
04428c5e548c Enum fix
ekku
parents: 71
diff changeset
     4
#include <vector>
83
cbba9729e92b Integrointia fyssaan, jotain pikkubugausta havaittavissa.
saiam
parents: 79
diff changeset
     5
#include <queue>
50
9e1a6506f5a1 some rough-handed code modifications towards a newer, better, working Physics
terom
parents: 48
diff changeset
     6
#include <ClanLib/core.h>
9e1a6506f5a1 some rough-handed code modifications towards a newer, better, working Physics
terom
parents: 48
diff changeset
     7
135
d5624d698a78 Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents: 134
diff changeset
     8
#include "Vector.hh"
78
bbc21da84813 This is probably better way of representing time
saiam
parents: 77
diff changeset
     9
135
d5624d698a78 Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents: 134
diff changeset
    10
// Forward declares
d5624d698a78 Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents: 134
diff changeset
    11
class PhysicsWorld;
d5624d698a78 Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents: 134
diff changeset
    12
class PhysicsObject;
d5624d698a78 Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents: 134
diff changeset
    13
class PlayerObject;
d5624d698a78 Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents: 134
diff changeset
    14
class ProjectileObject;
d5624d698a78 Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents: 134
diff changeset
    15
class Shape;
d5624d698a78 Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents: 134
diff changeset
    16
struct Derivative;
42
eb1a93a38cde lazy commit that breaks everything, should be a branch
terom
parents:
diff changeset
    17
135
d5624d698a78 Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents: 134
diff changeset
    18
// Type definitions
d5624d698a78 Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents: 134
diff changeset
    19
typedef uint16_t TimeMS;
d5624d698a78 Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents: 134
diff changeset
    20
typedef Vector Force;
d5624d698a78 Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents: 134
diff changeset
    21
d5624d698a78 Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents: 134
diff changeset
    22
// TODO: Random definitions. Should these be somewhere else?
72
04428c5e548c Enum fix
ekku
parents: 71
diff changeset
    23
enum TerrainType {EMPTY, DIRT, ROCK};
71
b5dbb83daa94 En takaa et k??ntyy en?? 8)
ekku
parents: 70
diff changeset
    24
135
d5624d698a78 Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents: 134
diff changeset
    25
// This probably should come from somewhere else
d5624d698a78 Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents: 134
diff changeset
    26
const TimeMS PHYSICS_TICK_MS = 10;
95
10704e1df844 Normal stuff
ekku
parents: 94
diff changeset
    27
135
d5624d698a78 Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents: 134
diff changeset
    28
// Yeah?!?!?! Atleast this could be documented. Contains vectors
d5624d698a78 Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents: 134
diff changeset
    29
// presenting all the 8 directions in a square grid?
d5624d698a78 Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents: 134
diff changeset
    30
const Vector DIRECTIONS[] = { Vector(0,-1), Vector(1,-1), Vector(1,0), 
d5624d698a78 Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents: 134
diff changeset
    31
                              Vector(1,1), Vector(0,1), Vector(-1,1), 
d5624d698a78 Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents: 134
diff changeset
    32
                              Vector(-1,0), Vector(-1,-1) };
50
9e1a6506f5a1 some rough-handed code modifications towards a newer, better, working Physics
terom
parents: 48
diff changeset
    33
135
d5624d698a78 Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents: 134
diff changeset
    34
d5624d698a78 Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents: 134
diff changeset
    35
/**
d5624d698a78 Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents: 134
diff changeset
    36
 * PhysicsWorld class. PhysicsWorld contains PhysicsObjects that are
d5624d698a78 Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents: 134
diff changeset
    37
 * simulated in the PhysicsWorld.
d5624d698a78 Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents: 134
diff changeset
    38
 */
42
eb1a93a38cde lazy commit that breaks everything, should be a branch
terom
parents:
diff changeset
    39
class PhysicsWorld {
60
26571fd9a8d1 physics is starting to work
terom
parents: 58
diff changeset
    40
    friend class PhysicsObject;
135
d5624d698a78 Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents: 134
diff changeset
    41
70
a5b7499219a4 Some drafts
saiam
parents: 69
diff changeset
    42
private:
a5b7499219a4 Some drafts
saiam
parents: 69
diff changeset
    43
    CL_Timer tick_timer;
135
d5624d698a78 Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents: 134
diff changeset
    44
    uint32_t tick_counter;
105
91e3f3806b31 set UDP sockets as nonblocking
terom
parents: 98
diff changeset
    45
70
a5b7499219a4 Some drafts
saiam
parents: 69
diff changeset
    46
protected:
135
d5624d698a78 Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents: 134
diff changeset
    47
    //std::vector<PlayerObject*> players;
d5624d698a78 Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents: 134
diff changeset
    48
    //std::vector<ProjectileObject*> projectiles;
70
a5b7499219a4 Some drafts
saiam
parents: 69
diff changeset
    49
    std::vector<PhysicsObject*> objects;
135
d5624d698a78 Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents: 134
diff changeset
    50
d5624d698a78 Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents: 134
diff changeset
    51
    // Contains connections between signals and slots
d5624d698a78 Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents: 134
diff changeset
    52
    CL_SlotContainer slots;
d5624d698a78 Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents: 134
diff changeset
    53
d5624d698a78 Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents: 134
diff changeset
    54
    PhysicsWorld(Vector gravity, Vector dimensions);
d5624d698a78 Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents: 134
diff changeset
    55
d5624d698a78 Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents: 134
diff changeset
    56
    // TODO: Should these be somewhere else?
d5624d698a78 Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents: 134
diff changeset
    57
    Vector dimensions;
70
a5b7499219a4 Some drafts
saiam
parents: 69
diff changeset
    58
    Vector gravity;
86
ed31ece6f340 Segfault <3 (mik? oli odotettavaa)
saiam
parents: 85
diff changeset
    59
135
d5624d698a78 Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents: 134
diff changeset
    60
    // TODO: Should this be it's own class?
72
04428c5e548c Enum fix
ekku
parents: 71
diff changeset
    61
    std::vector<std::vector<TerrainType> > terrain;
71
b5dbb83daa94 En takaa et k??ntyy en?? 8)
ekku
parents: 70
diff changeset
    62
86
ed31ece6f340 Segfault <3 (mik? oli odotettavaa)
saiam
parents: 85
diff changeset
    63
public:
135
d5624d698a78 Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents: 134
diff changeset
    64
    // TODO: Replace addObject with these?
d5624d698a78 Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents: 134
diff changeset
    65
    //void addPlayerObject(PlayerObject *object);
d5624d698a78 Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents: 134
diff changeset
    66
    //void addProjectileObject(ProjectileObject *object);
70
a5b7499219a4 Some drafts
saiam
parents: 69
diff changeset
    67
    
123
7efb63402b2b Documenting a little bit
saiam
parents: 122
diff changeset
    68
    /**
135
d5624d698a78 Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents: 134
diff changeset
    69
     * Add object to the PhysicsWorld.
123
7efb63402b2b Documenting a little bit
saiam
parents: 122
diff changeset
    70
     *
135
d5624d698a78 Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents: 134
diff changeset
    71
     * @param object Pointer to the PhysicsObject to add.
123
7efb63402b2b Documenting a little bit
saiam
parents: 122
diff changeset
    72
     */
135
d5624d698a78 Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents: 134
diff changeset
    73
    void addObject(PhysicsObject *object);
d5624d698a78 Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents: 134
diff changeset
    74
123
7efb63402b2b Documenting a little bit
saiam
parents: 122
diff changeset
    75
    /**
7efb63402b2b Documenting a little bit
saiam
parents: 122
diff changeset
    76
     * Advance one time step in physics simulation.
7efb63402b2b Documenting a little bit
saiam
parents: 122
diff changeset
    77
     */
135
d5624d698a78 Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents: 134
diff changeset
    78
    void tick();
d5624d698a78 Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents: 134
diff changeset
    79
123
7efb63402b2b Documenting a little bit
saiam
parents: 122
diff changeset
    80
    /**
7efb63402b2b Documenting a little bit
saiam
parents: 122
diff changeset
    81
     * Get current tick in physics simulation.
135
d5624d698a78 Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents: 134
diff changeset
    82
     *
d5624d698a78 Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents: 134
diff changeset
    83
     * @return tick Current simulation tick.
123
7efb63402b2b Documenting a little bit
saiam
parents: 122
diff changeset
    84
     */
135
d5624d698a78 Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents: 134
diff changeset
    85
    uint32_t getTick();
105
91e3f3806b31 set UDP sockets as nonblocking
terom
parents: 98
diff changeset
    86
135
d5624d698a78 Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents: 134
diff changeset
    87
    // ?!!?!?!?!?!?!
d5624d698a78 Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents: 134
diff changeset
    88
    // TODO: If there were a terrain class, these could it's members.
123
7efb63402b2b Documenting a little bit
saiam
parents: 122
diff changeset
    89
    /**
7efb63402b2b Documenting a little bit
saiam
parents: 122
diff changeset
    90
     * Generate random terrain.
135
d5624d698a78 Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents: 134
diff changeset
    91
     *
d5624d698a78 Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents: 134
diff changeset
    92
     * @param seed Random generator seed.
123
7efb63402b2b Documenting a little bit
saiam
parents: 122
diff changeset
    93
     */
135
d5624d698a78 Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents: 134
diff changeset
    94
    void generateTerrain(int seed);
123
7efb63402b2b Documenting a little bit
saiam
parents: 122
diff changeset
    95
    /**
135
d5624d698a78 Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents: 134
diff changeset
    96
     * Remove ground from the terrain. Removes a circle.
d5624d698a78 Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents: 134
diff changeset
    97
     *
d5624d698a78 Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents: 134
diff changeset
    98
     * @param x Circle x-coordinate
d5624d698a78 Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents: 134
diff changeset
    99
     * @param y Circle y-coordinate
d5624d698a78 Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents: 134
diff changeset
   100
     * @param r Circle radius
d5624d698a78 Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents: 134
diff changeset
   101
     */
d5624d698a78 Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents: 134
diff changeset
   102
    void removeGround(int x, int y, float r);
d5624d698a78 Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents: 134
diff changeset
   103
    /**
d5624d698a78 Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents: 134
diff changeset
   104
     * Remove ground from the terrain. Removes a circle.
d5624d698a78 Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents: 134
diff changeset
   105
     *
d5624d698a78 Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents: 134
diff changeset
   106
     * @param pos Circle location
d5624d698a78 Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents: 134
diff changeset
   107
     * @param r Circle radius
d5624d698a78 Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents: 134
diff changeset
   108
     */
d5624d698a78 Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents: 134
diff changeset
   109
    void removeGround(Vector pos, float r);
d5624d698a78 Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents: 134
diff changeset
   110
    /**
d5624d698a78 Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents: 134
diff changeset
   111
     * Return normal for the wall that has been hit.
123
7efb63402b2b Documenting a little bit
saiam
parents: 122
diff changeset
   112
     *
7efb63402b2b Documenting a little bit
saiam
parents: 122
diff changeset
   113
     * @param hitPoint The point of the wall that has been hit.
7efb63402b2b Documenting a little bit
saiam
parents: 122
diff changeset
   114
     * @param prevPoint The point from where we were coming.
7efb63402b2b Documenting a little bit
saiam
parents: 122
diff changeset
   115
     */
98
606c419e42a7 Ei se viel? k??nny kun on sienestetty.
saiam
parents: 96
diff changeset
   116
    Vector getNormal(Vector hitPoint, Vector prevPoint);
123
7efb63402b2b Documenting a little bit
saiam
parents: 122
diff changeset
   117
    /**
135
d5624d698a78 Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents: 134
diff changeset
   118
     * Return terrain type in given position.
123
7efb63402b2b Documenting a little bit
saiam
parents: 122
diff changeset
   119
     *
135
d5624d698a78 Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents: 134
diff changeset
   120
     * @param x X-coordinate
d5624d698a78 Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents: 134
diff changeset
   121
     * @param y Y-coordinate
123
7efb63402b2b Documenting a little bit
saiam
parents: 122
diff changeset
   122
     */
112
1b9ad61bdf2d added method for removing ground, not used anywhere
nireco
parents: 108
diff changeset
   123
    TerrainType getType(int x, int y) const;
123
7efb63402b2b Documenting a little bit
saiam
parents: 122
diff changeset
   124
    /**
135
d5624d698a78 Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents: 134
diff changeset
   125
     * Return terrain type in given position.
123
7efb63402b2b Documenting a little bit
saiam
parents: 122
diff changeset
   126
     *
135
d5624d698a78 Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents: 134
diff changeset
   127
     * @param pos Coordinate vector
123
7efb63402b2b Documenting a little bit
saiam
parents: 122
diff changeset
   128
     */
77
98dc9008d15f changed collision detection, remove old if content with new
nireco
parents: 75
diff changeset
   129
    TerrainType getType(Vector pos) const;
112
1b9ad61bdf2d added method for removing ground, not used anywhere
nireco
parents: 108
diff changeset
   130
42
eb1a93a38cde lazy commit that breaks everything, should be a branch
terom
parents:
diff changeset
   131
};
eb1a93a38cde lazy commit that breaks everything, should be a branch
terom
parents:
diff changeset
   132
135
d5624d698a78 Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents: 134
diff changeset
   133
/**
d5624d698a78 Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents: 134
diff changeset
   134
 * PhysicObject class. A basic PhysicsObject class.
d5624d698a78 Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents: 134
diff changeset
   135
 */
42
eb1a93a38cde lazy commit that breaks everything, should be a branch
terom
parents:
diff changeset
   136
class PhysicsObject {
70
a5b7499219a4 Some drafts
saiam
parents: 69
diff changeset
   137
protected:
135
d5624d698a78 Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents: 134
diff changeset
   138
    // This probably shouldn't be done this way.
70
a5b7499219a4 Some drafts
saiam
parents: 69
diff changeset
   139
    PhysicsWorld &world;
135
d5624d698a78 Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents: 134
diff changeset
   140
70
a5b7499219a4 Some drafts
saiam
parents: 69
diff changeset
   141
    Vector position;
a5b7499219a4 Some drafts
saiam
parents: 69
diff changeset
   142
    Vector velocity;
135
d5624d698a78 Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents: 134
diff changeset
   143
    float mass;
128
890ac82cdcc0 Documenting more, cleaning variables. This code needs some serious
saiam
parents: 123
diff changeset
   144
    bool inAir; // Is the object "on the ground"
83
cbba9729e92b Integrointia fyssaan, jotain pikkubugausta havaittavissa.
saiam
parents: 79
diff changeset
   145
135
d5624d698a78 Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents: 134
diff changeset
   146
    // Attributes for players
d5624d698a78 Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents: 134
diff changeset
   147
    float aim; // Aim direction (half circle)
d5624d698a78 Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents: 134
diff changeset
   148
    bool facingRight; // Player facing
d5624d698a78 Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents: 134
diff changeset
   149
d5624d698a78 Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents: 134
diff changeset
   150
    PhysicsObject(PhysicsWorld &world, float mass, Vector position, 
d5624d698a78 Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents: 134
diff changeset
   151
                  Vector velocity);
d5624d698a78 Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents: 134
diff changeset
   152
    ~PhysicsObject() {}
d5624d698a78 Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents: 134
diff changeset
   153
108
1b93045a5b0a T?ht?in lis?tty, tosin se piirret??n tosi rumasti.
saiam
parents: 107
diff changeset
   154
96
4a801210096c fix movement physics+network code to some degree, jumping is now buggy?
terom
parents: 95
diff changeset
   155
    /**
135
d5624d698a78 Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents: 134
diff changeset
   156
     * Add force to the force queue to be applied on next tick.
108
1b93045a5b0a T?ht?in lis?tty, tosin se piirret??n tosi rumasti.
saiam
parents: 107
diff changeset
   157
     *
135
d5624d698a78 Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents: 134
diff changeset
   158
     * @param force Force vector
108
1b93045a5b0a T?ht?in lis?tty, tosin se piirret??n tosi rumasti.
saiam
parents: 107
diff changeset
   159
     */
135
d5624d698a78 Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents: 134
diff changeset
   160
    void applyForce(Force force);
96
4a801210096c fix movement physics+network code to some degree, jumping is now buggy?
terom
parents: 95
diff changeset
   161
4a801210096c fix movement physics+network code to some degree, jumping is now buggy?
terom
parents: 95
diff changeset
   162
    /**
135
d5624d698a78 Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents: 134
diff changeset
   163
     * Change player aim
129
b1ae79a2d2f0 More documentation
saiam
parents: 128
diff changeset
   164
     *
b1ae79a2d2f0 More documentation
saiam
parents: 128
diff changeset
   165
     * @param da Aim angle change
108
1b93045a5b0a T?ht?in lis?tty, tosin se piirret??n tosi rumasti.
saiam
parents: 107
diff changeset
   166
     */
1b93045a5b0a T?ht?in lis?tty, tosin se piirret??n tosi rumasti.
saiam
parents: 107
diff changeset
   167
    void changeAim(float da);
135
d5624d698a78 Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents: 134
diff changeset
   168
   
108
1b93045a5b0a T?ht?in lis?tty, tosin se piirret??n tosi rumasti.
saiam
parents: 107
diff changeset
   169
    /**
1b93045a5b0a T?ht?in lis?tty, tosin se piirret??n tosi rumasti.
saiam
parents: 107
diff changeset
   170
     * Set player facing.
129
b1ae79a2d2f0 More documentation
saiam
parents: 128
diff changeset
   171
     *
b1ae79a2d2f0 More documentation
saiam
parents: 128
diff changeset
   172
     * @param facingRight True if player is facing right.
135
d5624d698a78 Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents: 134
diff changeset
   173
     */
129
b1ae79a2d2f0 More documentation
saiam
parents: 128
diff changeset
   174
    void setFacing(bool facingRight);
108
1b93045a5b0a T?ht?in lis?tty, tosin se piirret??n tosi rumasti.
saiam
parents: 107
diff changeset
   175
1b93045a5b0a T?ht?in lis?tty, tosin se piirret??n tosi rumasti.
saiam
parents: 107
diff changeset
   176
    /**
96
4a801210096c fix movement physics+network code to some degree, jumping is now buggy?
terom
parents: 95
diff changeset
   177
     * Handle ground-jumping
4a801210096c fix movement physics+network code to some degree, jumping is now buggy?
terom
parents: 95
diff changeset
   178
     */
135
d5624d698a78 Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents: 134
diff changeset
   179
    void jump();
98
606c419e42a7 Ei se viel? k??nny kun on sienestetty.
saiam
parents: 96
diff changeset
   180
135
d5624d698a78 Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents: 134
diff changeset
   181
    /** 
98
606c419e42a7 Ei se viel? k??nny kun on sienestetty.
saiam
parents: 96
diff changeset
   182
     * Handle ground-bounce
129
b1ae79a2d2f0 More documentation
saiam
parents: 128
diff changeset
   183
     *
b1ae79a2d2f0 More documentation
saiam
parents: 128
diff changeset
   184
     * @param normal Normal vector relative to which to bounce
98
606c419e42a7 Ei se viel? k??nny kun on sienestetty.
saiam
parents: 96
diff changeset
   185
     */
135
d5624d698a78 Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents: 134
diff changeset
   186
    void bounce(Vector normal);
d5624d698a78 Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents: 134
diff changeset
   187
d5624d698a78 Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents: 134
diff changeset
   188
    /**
d5624d698a78 Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents: 134
diff changeset
   189
     * Called on network clients to sync state from server
d5624d698a78 Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents: 134
diff changeset
   190
     *
d5624d698a78 Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents: 134
diff changeset
   191
     * @param position New position
d5624d698a78 Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents: 134
diff changeset
   192
     * @param velocity New velocity
d5624d698a78 Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents: 134
diff changeset
   193
     * @param inAir New inAir value
d5624d698a78 Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents: 134
diff changeset
   194
     */
d5624d698a78 Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents: 134
diff changeset
   195
    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
   196
70
a5b7499219a4 Some drafts
saiam
parents: 69
diff changeset
   197
private:
135
d5624d698a78 Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents: 134
diff changeset
   198
    // TODO: I'd be tempted to use some already made ClanLib structure
d5624d698a78 Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents: 134
diff changeset
   199
    // here.  
d5624d698a78 Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents: 134
diff changeset
   200
    // Shape of the object. Edge points of the shape polygon.
d5624d698a78 Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents: 134
diff changeset
   201
    std::vector<Vector> shape;
129
b1ae79a2d2f0 More documentation
saiam
parents: 128
diff changeset
   202
135
d5624d698a78 Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents: 134
diff changeset
   203
    // TODO: Should these operations be moved to PhysicsWorld?
d5624d698a78 Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents: 134
diff changeset
   204
    // Force queue that is emptied on every tick
d5624d698a78 Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents: 134
diff changeset
   205
    std::queue<Force> forceq;
d5624d698a78 Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents: 134
diff changeset
   206
    // Helper variables for integration
d5624d698a78 Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents: 134
diff changeset
   207
    Vector posAfterTick;
d5624d698a78 Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents: 134
diff changeset
   208
    Vector velAfterTick;
69
309c11126949 little cleanup
saiam
parents: 66
diff changeset
   209
70
a5b7499219a4 Some drafts
saiam
parents: 69
diff changeset
   210
    /**
135
d5624d698a78 Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents: 134
diff changeset
   211
     * Handle player movement and apply forces.
d5624d698a78 Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents: 134
diff changeset
   212
     */
d5624d698a78 Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents: 134
diff changeset
   213
    void updatePosition();
d5624d698a78 Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents: 134
diff changeset
   214
d5624d698a78 Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents: 134
diff changeset
   215
    // TODO: Should these be moved to PhysicsWorld?
d5624d698a78 Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents: 134
diff changeset
   216
    /**
d5624d698a78 Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents: 134
diff changeset
   217
     * Use RK4 to integrate the effects of force over a time interwall.
129
b1ae79a2d2f0 More documentation
saiam
parents: 128
diff changeset
   218
     *
b1ae79a2d2f0 More documentation
saiam
parents: 128
diff changeset
   219
     * @param force Force to integrate
b1ae79a2d2f0 More documentation
saiam
parents: 128
diff changeset
   220
     * @param dt Time intervall
70
a5b7499219a4 Some drafts
saiam
parents: 69
diff changeset
   221
     */
85
351cb6b69c04 Making things simpler. More to come soon.
saiam
parents: 83
diff changeset
   222
    void integrate(Force force, TimeMS dt);
129
b1ae79a2d2f0 More documentation
saiam
parents: 128
diff changeset
   223
b1ae79a2d2f0 More documentation
saiam
parents: 128
diff changeset
   224
    /**
b1ae79a2d2f0 More documentation
saiam
parents: 128
diff changeset
   225
     * Evaluate the value of the derivative at given time
b1ae79a2d2f0 More documentation
saiam
parents: 128
diff changeset
   226
     *
b1ae79a2d2f0 More documentation
saiam
parents: 128
diff changeset
   227
     * @param force Force
b1ae79a2d2f0 More documentation
saiam
parents: 128
diff changeset
   228
     * @param dt Time
135
d5624d698a78 Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents: 134
diff changeset
   229
     * @param d Previous derivative
129
b1ae79a2d2f0 More documentation
saiam
parents: 128
diff changeset
   230
     */
85
351cb6b69c04 Making things simpler. More to come soon.
saiam
parents: 83
diff changeset
   231
    Derivative evaluate(Force force, TimeMS dt, Derivative &d);
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 acceleration with given force.
b1ae79a2d2f0 More documentation
saiam
parents: 128
diff changeset
   235
     *
b1ae79a2d2f0 More documentation
saiam
parents: 128
diff changeset
   236
     * @param force Force
135
d5624d698a78 Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents: 134
diff changeset
   237
     * @return Acceleration
129
b1ae79a2d2f0 More documentation
saiam
parents: 128
diff changeset
   238
     */
85
351cb6b69c04 Making things simpler. More to come soon.
saiam
parents: 83
diff changeset
   239
    Vector acceleration(const Force &force);
83
cbba9729e92b Integrointia fyssaan, jotain pikkubugausta havaittavissa.
saiam
parents: 79
diff changeset
   240
135
d5624d698a78 Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents: 134
diff changeset
   241
    // TODO: If integration is moved to PhysicsWorld then this should
d5624d698a78 Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents: 134
diff changeset
   242
    // also move there.
134
d45109cf5e9d Moved unnecessarily protected function to private
saiam
parents: 133
diff changeset
   243
    /**
135
d5624d698a78 Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents: 134
diff changeset
   244
     * Handle ground movement.
134
d45109cf5e9d Moved unnecessarily protected function to private
saiam
parents: 133
diff changeset
   245
     *
d45109cf5e9d Moved unnecessarily protected function to private
saiam
parents: 133
diff changeset
   246
     * @param right Boolean describing the movement direction.
135
d5624d698a78 Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents: 134
diff changeset
   247
     * @return New position
134
d45109cf5e9d Moved unnecessarily protected function to private
saiam
parents: 133
diff changeset
   248
     */
135
d5624d698a78 Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents: 134
diff changeset
   249
    Vector walk(bool right);
134
d45109cf5e9d Moved unnecessarily protected function to private
saiam
parents: 133
diff changeset
   250
129
b1ae79a2d2f0 More documentation
saiam
parents: 128
diff changeset
   251
    /*
135
d5624d698a78 Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents: 134
diff changeset
   252
     * Handle collision. TODO: This is not used. It probably should
d5624d698a78 Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents: 134
diff changeset
   253
     * be?
129
b1ae79a2d2f0 More documentation
saiam
parents: 128
diff changeset
   254
     */
116
0d36aade845e some stuff, don't remember what
nireco
parents: 113
diff changeset
   255
    virtual void onCollision() {}
0d36aade845e some stuff, don't remember what
nireco
parents: 113
diff changeset
   256
135
d5624d698a78 Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents: 134
diff changeset
   257
    /*
d5624d698a78 Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents: 134
diff changeset
   258
     * TODO: This probably does some kind of collision
d5624d698a78 Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents: 134
diff changeset
   259
     * detection. Could be named/documented better.
d5624d698a78 Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents: 134
diff changeset
   260
     */
d5624d698a78 Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents: 134
diff changeset
   261
    bool possibleLocation(Vector loc);
132
957c3c184ea0 Changed some variables that were protected to private from PhysicsObject
saiam
parents: 131
diff changeset
   262
70
a5b7499219a4 Some drafts
saiam
parents: 69
diff changeset
   263
public:
129
b1ae79a2d2f0 More documentation
saiam
parents: 128
diff changeset
   264
    /**
b1ae79a2d2f0 More documentation
saiam
parents: 128
diff changeset
   265
     * Get current object position.
135
d5624d698a78 Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents: 134
diff changeset
   266
     *
d5624d698a78 Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents: 134
diff changeset
   267
     * @return Position vector
129
b1ae79a2d2f0 More documentation
saiam
parents: 128
diff changeset
   268
     */
135
d5624d698a78 Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents: 134
diff changeset
   269
    Vector getPosition();
129
b1ae79a2d2f0 More documentation
saiam
parents: 128
diff changeset
   270
b1ae79a2d2f0 More documentation
saiam
parents: 128
diff changeset
   271
    /**
b1ae79a2d2f0 More documentation
saiam
parents: 128
diff changeset
   272
     * Return object shape.
b1ae79a2d2f0 More documentation
saiam
parents: 128
diff changeset
   273
     *
b1ae79a2d2f0 More documentation
saiam
parents: 128
diff changeset
   274
     * @return Polygon points
b1ae79a2d2f0 More documentation
saiam
parents: 128
diff changeset
   275
     */
135
d5624d698a78 Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents: 134
diff changeset
   276
    std::vector<Vector>& getShape();
129
b1ae79a2d2f0 More documentation
saiam
parents: 128
diff changeset
   277
b1ae79a2d2f0 More documentation
saiam
parents: 128
diff changeset
   278
    /**
b1ae79a2d2f0 More documentation
saiam
parents: 128
diff changeset
   279
     * Set object shape.
b1ae79a2d2f0 More documentation
saiam
parents: 128
diff changeset
   280
     *
135
d5624d698a78 Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents: 134
diff changeset
   281
     * @param shape Vector containing polygon poinst
129
b1ae79a2d2f0 More documentation
saiam
parents: 128
diff changeset
   282
     */
135
d5624d698a78 Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents: 134
diff changeset
   283
    void setShape(std::vector<Vector> shape);
108
1b93045a5b0a T?ht?in lis?tty, tosin se piirret??n tosi rumasti.
saiam
parents: 107
diff changeset
   284
129
b1ae79a2d2f0 More documentation
saiam
parents: 128
diff changeset
   285
    /**
b1ae79a2d2f0 More documentation
saiam
parents: 128
diff changeset
   286
     * Return object facing.
b1ae79a2d2f0 More documentation
saiam
parents: 128
diff changeset
   287
     *
135
d5624d698a78 Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents: 134
diff changeset
   288
     * @return Object facing (true if facing right)
129
b1ae79a2d2f0 More documentation
saiam
parents: 128
diff changeset
   289
     */
135
d5624d698a78 Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents: 134
diff changeset
   290
    bool getFacing();
129
b1ae79a2d2f0 More documentation
saiam
parents: 128
diff changeset
   291
b1ae79a2d2f0 More documentation
saiam
parents: 128
diff changeset
   292
    /**
b1ae79a2d2f0 More documentation
saiam
parents: 128
diff changeset
   293
     * Return object aim angle.
b1ae79a2d2f0 More documentation
saiam
parents: 128
diff changeset
   294
     *
b1ae79a2d2f0 More documentation
saiam
parents: 128
diff changeset
   295
     * @return Object aim angle
b1ae79a2d2f0 More documentation
saiam
parents: 128
diff changeset
   296
     */
135
d5624d698a78 Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents: 134
diff changeset
   297
    float getAim();
108
1b93045a5b0a T?ht?in lis?tty, tosin se piirret??n tosi rumasti.
saiam
parents: 107
diff changeset
   298
129
b1ae79a2d2f0 More documentation
saiam
parents: 128
diff changeset
   299
    /**
b1ae79a2d2f0 More documentation
saiam
parents: 128
diff changeset
   300
     * Update object in physics simulation.
b1ae79a2d2f0 More documentation
saiam
parents: 128
diff changeset
   301
     */
135
d5624d698a78 Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents: 134
diff changeset
   302
    void tick();
42
eb1a93a38cde lazy commit that breaks everything, should be a branch
terom
parents:
diff changeset
   303
};
eb1a93a38cde lazy commit that breaks everything, should be a branch
terom
parents:
diff changeset
   304
135
d5624d698a78 Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents: 134
diff changeset
   305
// TODO: This could probably be moved somewhere else or removed
d5624d698a78 Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents: 134
diff changeset
   306
// completely.
83
cbba9729e92b Integrointia fyssaan, jotain pikkubugausta havaittavissa.
saiam
parents: 79
diff changeset
   307
struct Derivative {
cbba9729e92b Integrointia fyssaan, jotain pikkubugausta havaittavissa.
saiam
parents: 79
diff changeset
   308
    Vector dx; // Velocity
cbba9729e92b Integrointia fyssaan, jotain pikkubugausta havaittavissa.
saiam
parents: 79
diff changeset
   309
    Vector dv; // Acceleration
cbba9729e92b Integrointia fyssaan, jotain pikkubugausta havaittavissa.
saiam
parents: 79
diff changeset
   310
};
cbba9729e92b Integrointia fyssaan, jotain pikkubugausta havaittavissa.
saiam
parents: 79
diff changeset
   311
cbba9729e92b Integrointia fyssaan, jotain pikkubugausta havaittavissa.
saiam
parents: 79
diff changeset
   312
135
d5624d698a78 Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents: 134
diff changeset
   313
// TODO: These are drafts
d5624d698a78 Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents: 134
diff changeset
   314
/**
d5624d698a78 Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents: 134
diff changeset
   315
 * PlayerObject class. Represents a player in the physics engine.
d5624d698a78 Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents: 134
diff changeset
   316
 */
d5624d698a78 Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents: 134
diff changeset
   317
//class PlayerObject : public PhysicsObject {
d5624d698a78 Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents: 134
diff changeset
   318
d5624d698a78 Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents: 134
diff changeset
   319
//};
d5624d698a78 Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents: 134
diff changeset
   320
d5624d698a78 Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents: 134
diff changeset
   321
/**
d5624d698a78 Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents: 134
diff changeset
   322
 * ProjectileObject class. Represents different projectiles in the
d5624d698a78 Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents: 134
diff changeset
   323
 * physics (i.e. not players) in the physics engine.
d5624d698a78 Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents: 134
diff changeset
   324
 */
d5624d698a78 Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents: 134
diff changeset
   325
//class ProjectileObject : public PhysicsObject {
d5624d698a78 Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents: 134
diff changeset
   326
d5624d698a78 Physics.hh rewrite. Documenting and suggesting changes.
saiam
parents: 134
diff changeset
   327
//};
83
cbba9729e92b Integrointia fyssaan, jotain pikkubugausta havaittavissa.
saiam
parents: 79
diff changeset
   328
42
eb1a93a38cde lazy commit that breaks everything, should be a branch
terom
parents:
diff changeset
   329
#endif