src/proto2/Physics.hh
author terom
Tue, 18 Nov 2008 22:50:29 +0000
changeset 66 1415a2d45686
parent 64 81302d3350eb
child 69 309c11126949
permissions -rw-r--r--
working simple network-physics code
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
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
64
81302d3350eb Pomppimisia.
terom
parents: 60
diff changeset
     8
const uint16_t PHYSICS_TICK_MS = 10;
42
eb1a93a38cde lazy commit that breaks everything, should be a branch
terom
parents:
diff changeset
     9
50
9e1a6506f5a1 some rough-handed code modifications towards a newer, better, working Physics
terom
parents: 48
diff changeset
    10
// forward-declare
9e1a6506f5a1 some rough-handed code modifications towards a newer, better, working Physics
terom
parents: 48
diff changeset
    11
class PhysicsObject;
9e1a6506f5a1 some rough-handed code modifications towards a newer, better, working Physics
terom
parents: 48
diff changeset
    12
42
eb1a93a38cde lazy commit that breaks everything, should be a branch
terom
parents:
diff changeset
    13
class PhysicsWorld {
60
26571fd9a8d1 physics is starting to work
terom
parents: 58
diff changeset
    14
    friend class PhysicsObject;
26571fd9a8d1 physics is starting to work
terom
parents: 58
diff changeset
    15
            
50
9e1a6506f5a1 some rough-handed code modifications towards a newer, better, working Physics
terom
parents: 48
diff changeset
    16
    private:
9e1a6506f5a1 some rough-handed code modifications towards a newer, better, working Physics
terom
parents: 48
diff changeset
    17
        CL_Timer tick_timer;
9e1a6506f5a1 some rough-handed code modifications towards a newer, better, working Physics
terom
parents: 48
diff changeset
    18
42
eb1a93a38cde lazy commit that breaks everything, should be a branch
terom
parents:
diff changeset
    19
    protected:
eb1a93a38cde lazy commit that breaks everything, should be a branch
terom
parents:
diff changeset
    20
        std::vector<PhysicsObject*> objects;
60
26571fd9a8d1 physics is starting to work
terom
parents: 58
diff changeset
    21
        Vector gravity;
42
eb1a93a38cde lazy commit that breaks everything, should be a branch
terom
parents:
diff changeset
    22
        Vector dimensions;
50
9e1a6506f5a1 some rough-handed code modifications towards a newer, better, working Physics
terom
parents: 48
diff changeset
    23
9e1a6506f5a1 some rough-handed code modifications towards a newer, better, working Physics
terom
parents: 48
diff changeset
    24
        CL_SlotContainer slots;
42
eb1a93a38cde lazy commit that breaks everything, should be a branch
terom
parents:
diff changeset
    25
        
60
26571fd9a8d1 physics is starting to work
terom
parents: 58
diff changeset
    26
        PhysicsWorld (Vector gravity, Vector dimensions);
42
eb1a93a38cde lazy commit that breaks everything, should be a branch
terom
parents:
diff changeset
    27
eb1a93a38cde lazy commit that breaks everything, should be a branch
terom
parents:
diff changeset
    28
    public:
eb1a93a38cde lazy commit that breaks everything, should be a branch
terom
parents:
diff changeset
    29
        void addObject (PhysicsObject *object);
eb1a93a38cde lazy commit that breaks everything, should be a branch
terom
parents:
diff changeset
    30
eb1a93a38cde lazy commit that breaks everything, should be a branch
terom
parents:
diff changeset
    31
        void tick (void);
eb1a93a38cde lazy commit that breaks everything, should be a branch
terom
parents:
diff changeset
    32
};
eb1a93a38cde lazy commit that breaks everything, should be a branch
terom
parents:
diff changeset
    33
eb1a93a38cde lazy commit that breaks everything, should be a branch
terom
parents:
diff changeset
    34
class PhysicsObject {
eb1a93a38cde lazy commit that breaks everything, should be a branch
terom
parents:
diff changeset
    35
    protected:
60
26571fd9a8d1 physics is starting to work
terom
parents: 58
diff changeset
    36
        PhysicsWorld &world;
26571fd9a8d1 physics is starting to work
terom
parents: 58
diff changeset
    37
        float mass;
42
eb1a93a38cde lazy commit that breaks everything, should be a branch
terom
parents:
diff changeset
    38
        Vector position;
eb1a93a38cde lazy commit that breaks everything, should be a branch
terom
parents:
diff changeset
    39
        Vector velocity;
eb1a93a38cde lazy commit that breaks everything, should be a branch
terom
parents:
diff changeset
    40
    
60
26571fd9a8d1 physics is starting to work
terom
parents: 58
diff changeset
    41
        PhysicsObject (PhysicsWorld &world, float mass, Vector position, Vector velocity);
42
eb1a93a38cde lazy commit that breaks everything, should be a branch
terom
parents:
diff changeset
    42
    
eb1a93a38cde lazy commit that breaks everything, should be a branch
terom
parents:
diff changeset
    43
    private:
eb1a93a38cde lazy commit that breaks everything, should be a branch
terom
parents:
diff changeset
    44
        void updatePosition (void);
eb1a93a38cde lazy commit that breaks everything, should be a branch
terom
parents:
diff changeset
    45
eb1a93a38cde lazy commit that breaks everything, should be a branch
terom
parents:
diff changeset
    46
    protected:
66
1415a2d45686 working simple network-physics code
terom
parents: 64
diff changeset
    47
        virtual void applyForce (Vector force, uint16_t dt);
60
26571fd9a8d1 physics is starting to work
terom
parents: 58
diff changeset
    48
        void updatePhysics (Vector position, Vector velocity);
42
eb1a93a38cde lazy commit that breaks everything, should be a branch
terom
parents:
diff changeset
    49
    
eb1a93a38cde lazy commit that breaks everything, should be a branch
terom
parents:
diff changeset
    50
    public:
eb1a93a38cde lazy commit that breaks everything, should be a branch
terom
parents:
diff changeset
    51
        Vector getPosition (void);
eb1a93a38cde lazy commit that breaks everything, should be a branch
terom
parents:
diff changeset
    52
eb1a93a38cde lazy commit that breaks everything, should be a branch
terom
parents:
diff changeset
    53
        void tick (void);
eb1a93a38cde lazy commit that breaks everything, should be a branch
terom
parents:
diff changeset
    54
};
eb1a93a38cde lazy commit that breaks everything, should be a branch
terom
parents:
diff changeset
    55
eb1a93a38cde lazy commit that breaks everything, should be a branch
terom
parents:
diff changeset
    56
#endif