pmc/main.cc
author Emilio Largo <largo@largo.homelinux.org>
Thu, 16 Apr 2009 12:49:12 +0200
changeset 45 7197576fedcf
parent 42 83b8151b966d
child 46 4b9e1ac40246
permissions -rw-r--r--
pmc: namespace algebra for vector -> the namespace prevents clashes with std::vector -> std::vector and algebra::Vector with capital V. md5: a md5 replacement ncurses: keypad function added committer: Markus Bröker <mbroeker@largo.homelinux.org>
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
9
c3fecc82ade6 standard tags for git projects
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 4
diff changeset
     1
/**
c3fecc82ade6 standard tags for git projects
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 4
diff changeset
     2
 * test/demos/pmc/main.cc
c3fecc82ade6 standard tags for git projects
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 4
diff changeset
     3
 * Copyright (C) 2008 Markus Broeker
4
236f8f747073 pimp my code, a small xdemo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
     4
 */
236f8f747073 pimp my code, a small xdemo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
     5
42
83b8151b966d Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 9
diff changeset
     6
#include <surface.h>
83b8151b966d Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 9
diff changeset
     7
#include <rectangle.h>
4
236f8f747073 pimp my code, a small xdemo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
     8
#include <cube.h>
236f8f747073 pimp my code, a small xdemo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
     9
42
83b8151b966d Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 9
diff changeset
    10
#include <cstdio>
83b8151b966d Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 9
diff changeset
    11
#include <cstdlib>
4
236f8f747073 pimp my code, a small xdemo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    12
236f8f747073 pimp my code, a small xdemo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    13
#ifndef STEP
236f8f747073 pimp my code, a small xdemo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    14
#define STEP 1
236f8f747073 pimp my code, a small xdemo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    15
#endif
236f8f747073 pimp my code, a small xdemo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    16
42
83b8151b966d Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 9
diff changeset
    17
#define MAX 3
83b8151b966d Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 9
diff changeset
    18
45
7197576fedcf pmc: namespace algebra for vector
Emilio Largo <largo@largo.homelinux.org>
parents: 42
diff changeset
    19
using namespace algebra;
7197576fedcf pmc: namespace algebra for vector
Emilio Largo <largo@largo.homelinux.org>
parents: 42
diff changeset
    20
4
236f8f747073 pimp my code, a small xdemo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    21
int main (int argc, char **argv)
236f8f747073 pimp my code, a small xdemo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    22
{
42
83b8151b966d Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 9
diff changeset
    23
    Surface *surface;
83b8151b966d Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 9
diff changeset
    24
    SDL_Event event;
83b8151b966d Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 9
diff changeset
    25
    Drawable *d[MAX];
4
236f8f747073 pimp my code, a small xdemo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    26
42
83b8151b966d Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 9
diff changeset
    27
    int height;
4
236f8f747073 pimp my code, a small xdemo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    28
236f8f747073 pimp my code, a small xdemo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    29
    if (argc != 2) {
42
83b8151b966d Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 9
diff changeset
    30
        fprintf (stderr, "Usage: %s <HEIGHT>\n", argv[0]);
83b8151b966d Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 9
diff changeset
    31
        height = 250;
83b8151b966d Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 9
diff changeset
    32
    } else
83b8151b966d Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 9
diff changeset
    33
        height = atoi (argv[1]);
4
236f8f747073 pimp my code, a small xdemo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    34
42
83b8151b966d Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 9
diff changeset
    35
    if ((height < 10) || (height >= 360))
83b8151b966d Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 9
diff changeset
    36
        height = 200;
4
236f8f747073 pimp my code, a small xdemo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    37
42
83b8151b966d Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 9
diff changeset
    38
    Vector p1 (0, 0);
83b8151b966d Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 9
diff changeset
    39
    Vector p2 (height, 0);
83b8151b966d Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 9
diff changeset
    40
    Vector p3 (height, height);
83b8151b966d Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 9
diff changeset
    41
    Vector p4 (0, height);
4
236f8f747073 pimp my code, a small xdemo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    42
42
83b8151b966d Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 9
diff changeset
    43
    surface = new Surface (1024, 768, 16);
4
236f8f747073 pimp my code, a small xdemo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    44
42
83b8151b966d Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 9
diff changeset
    45
    d[0] = new Rectangle (surface, p1, p2, p3, p4);
83b8151b966d Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 9
diff changeset
    46
    d[1] = new Cube (surface);
83b8151b966d Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 9
diff changeset
    47
    d[2] = new Cube (surface, p1, p2, p3, p4, height);
4
236f8f747073 pimp my code, a small xdemo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    48
236f8f747073 pimp my code, a small xdemo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    49
    bool running = true;
45
7197576fedcf pmc: namespace algebra for vector
Emilio Largo <largo@largo.homelinux.org>
parents: 42
diff changeset
    50
    int i, x, y;
4
236f8f747073 pimp my code, a small xdemo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    51
42
83b8151b966d Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 9
diff changeset
    52
    x = y = 0;
83b8151b966d Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 9
diff changeset
    53
83b8151b966d Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 9
diff changeset
    54
    d[1]->move (Vector (25, 25));
83b8151b966d Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 9
diff changeset
    55
    d[2]->move (Vector (290, 0));
4
236f8f747073 pimp my code, a small xdemo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    56
236f8f747073 pimp my code, a small xdemo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    57
    while (running) {
236f8f747073 pimp my code, a small xdemo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    58
        SDL_PollEvent (&event);
236f8f747073 pimp my code, a small xdemo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    59
236f8f747073 pimp my code, a small xdemo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    60
        if (event.type == SDL_QUIT)
236f8f747073 pimp my code, a small xdemo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    61
            running = false;
236f8f747073 pimp my code, a small xdemo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    62
236f8f747073 pimp my code, a small xdemo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    63
        if (event.type == SDL_KEYDOWN) {
42
83b8151b966d Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 9
diff changeset
    64
            surface->setColor (Surface::BLACK);
45
7197576fedcf pmc: namespace algebra for vector
Emilio Largo <largo@largo.homelinux.org>
parents: 42
diff changeset
    65
            for (i = 0; i < MAX; i++)
42
83b8151b966d Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 9
diff changeset
    66
                d[i]->show ();
83b8151b966d Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 9
diff changeset
    67
            surface->setColor (Surface::RED);
4
236f8f747073 pimp my code, a small xdemo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    68
236f8f747073 pimp my code, a small xdemo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    69
            switch (event.key.keysym.sym) {
236f8f747073 pimp my code, a small xdemo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    70
            case SDLK_ESCAPE:
236f8f747073 pimp my code, a small xdemo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    71
                running = false;
236f8f747073 pimp my code, a small xdemo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    72
                break;
236f8f747073 pimp my code, a small xdemo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    73
236f8f747073 pimp my code, a small xdemo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    74
            case SDLK_UP:
45
7197576fedcf pmc: namespace algebra for vector
Emilio Largo <largo@largo.homelinux.org>
parents: 42
diff changeset
    75
                for (i = 0; i < MAX; i++)
42
83b8151b966d Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 9
diff changeset
    76
                    d[i]->move ((Vector (x, y - STEP)));
4
236f8f747073 pimp my code, a small xdemo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    77
                break;
236f8f747073 pimp my code, a small xdemo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    78
236f8f747073 pimp my code, a small xdemo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    79
            case SDLK_DOWN:
45
7197576fedcf pmc: namespace algebra for vector
Emilio Largo <largo@largo.homelinux.org>
parents: 42
diff changeset
    80
                for (i = 0; i < MAX; i++)
42
83b8151b966d Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 9
diff changeset
    81
                    d[i]->move ((Vector (x, y + STEP)));
4
236f8f747073 pimp my code, a small xdemo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    82
                break;
236f8f747073 pimp my code, a small xdemo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    83
236f8f747073 pimp my code, a small xdemo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    84
            case SDLK_LEFT:
45
7197576fedcf pmc: namespace algebra for vector
Emilio Largo <largo@largo.homelinux.org>
parents: 42
diff changeset
    85
                for (i = 0; i < MAX; i++)
42
83b8151b966d Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 9
diff changeset
    86
                    d[i]->move ((Vector (x - STEP, y)));
4
236f8f747073 pimp my code, a small xdemo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    87
                break;
236f8f747073 pimp my code, a small xdemo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    88
236f8f747073 pimp my code, a small xdemo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    89
            case SDLK_RIGHT:
45
7197576fedcf pmc: namespace algebra for vector
Emilio Largo <largo@largo.homelinux.org>
parents: 42
diff changeset
    90
                for (i = 0; i < MAX; i++)
42
83b8151b966d Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 9
diff changeset
    91
                    d[i]->move ((Vector (x + STEP, y)));
4
236f8f747073 pimp my code, a small xdemo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    92
                break;
236f8f747073 pimp my code, a small xdemo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    93
            default:
236f8f747073 pimp my code, a small xdemo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    94
                break;
236f8f747073 pimp my code, a small xdemo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    95
            }
236f8f747073 pimp my code, a small xdemo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    96
45
7197576fedcf pmc: namespace algebra for vector
Emilio Largo <largo@largo.homelinux.org>
parents: 42
diff changeset
    97
            for (i = 0; i < MAX; i++) {
42
83b8151b966d Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 9
diff changeset
    98
                d[i]->show ();
83b8151b966d Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 9
diff changeset
    99
            }
83b8151b966d Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 9
diff changeset
   100
83b8151b966d Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 9
diff changeset
   101
            surface->flip ();
4
236f8f747073 pimp my code, a small xdemo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   102
        }
236f8f747073 pimp my code, a small xdemo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   103
    }
236f8f747073 pimp my code, a small xdemo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   104
45
7197576fedcf pmc: namespace algebra for vector
Emilio Largo <largo@largo.homelinux.org>
parents: 42
diff changeset
   105
    for (i = 0; i < MAX; i++)
42
83b8151b966d Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 9
diff changeset
   106
        delete d[i];
4
236f8f747073 pimp my code, a small xdemo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   107
42
83b8151b966d Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 9
diff changeset
   108
    delete surface;
4
236f8f747073 pimp my code, a small xdemo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   109
42
83b8151b966d Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 9
diff changeset
   110
    return EXIT_SUCCESS;
4
236f8f747073 pimp my code, a small xdemo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   111
}