1 | /* |
---|
2 | orxonox - the future of 3D-vertical-scrollers |
---|
3 | |
---|
4 | Copyright (C) 2004 orx |
---|
5 | |
---|
6 | This program is free software; you can redistribute it and/or modify |
---|
7 | it under the terms of the GNU General Public License as published by |
---|
8 | the Free Software Foundation; either version 2, or (at your option) |
---|
9 | any later version. |
---|
10 | |
---|
11 | ### File Specific: |
---|
12 | main-programmer: David Hasenfratz |
---|
13 | co-programmer: ... |
---|
14 | |
---|
15 | this file extends the framework file, so it renders what i want. |
---|
16 | */ |
---|
17 | |
---|
18 | #include "framework.h" |
---|
19 | |
---|
20 | #include "light.h" |
---|
21 | |
---|
22 | #include "texture_sequence.h" |
---|
23 | #include "material.h" |
---|
24 | |
---|
25 | #include "primitive_model.h" |
---|
26 | #include <stdlib.h> |
---|
27 | |
---|
28 | #include "media_container.h" |
---|
29 | |
---|
30 | Model* obj; |
---|
31 | TextureSequence* seq; |
---|
32 | Material* testMat; |
---|
33 | MediaContainer* movie; |
---|
34 | |
---|
35 | int counter = 0; |
---|
36 | float timer = 0; |
---|
37 | float fps; |
---|
38 | |
---|
39 | |
---|
40 | void Framework::moduleInit(int argc, char** argv) |
---|
41 | { |
---|
42 | if( argc <= 2) |
---|
43 | { |
---|
44 | printf("Wrong arguments try following notations:\n"); |
---|
45 | printf("./multitex [media_file] [start_time]\n"); |
---|
46 | exit(0); |
---|
47 | } |
---|
48 | |
---|
49 | movie = new MediaContainer(argv[1]); |
---|
50 | //movie = new MediaContainer(); |
---|
51 | //movie->loadMedia(argv[1]); |
---|
52 | fps = movie->getFPS(); |
---|
53 | |
---|
54 | int start_time = atoi(argv[2]); |
---|
55 | |
---|
56 | // print information about the media file |
---|
57 | movie->printMediaInformation(); |
---|
58 | |
---|
59 | testMat = new Material; |
---|
60 | |
---|
61 | seq = new TextureSequence(); |
---|
62 | |
---|
63 | // get each fram individually |
---|
64 | //while(seq->addFrame(movie->getNextFrame()) != NULL); |
---|
65 | // get a list of frames |
---|
66 | seq->addFrame(movie->getFrame(start_time)); |
---|
67 | seq->addFrameList(movie->getFrameList()); |
---|
68 | |
---|
69 | testMat->setDiffuseMap("maps/radialTransparency.png"); |
---|
70 | |
---|
71 | obj = new PrimitiveModel(PRIM_PLANE, 10.0); |
---|
72 | |
---|
73 | LightManager* lightMan = LightManager::getInstance(); |
---|
74 | lightMan->setAmbientColor(.1,.1,.1); |
---|
75 | (new Light())->setAbsCoor(5.0, 10.0, 40.0); |
---|
76 | (new Light())->setAbsCoor(-10, -20, -100); |
---|
77 | } |
---|
78 | |
---|
79 | void Framework::moduleEventHandler(SDL_Event* event) |
---|
80 | { |
---|
81 | switch (event->type) |
---|
82 | { |
---|
83 | case SDL_KEYDOWN: |
---|
84 | switch (event->key.keysym.sym) |
---|
85 | { |
---|
86 | case SDLK_1: |
---|
87 | obj = new PrimitiveModel(PRIM_CUBE, 10.0); |
---|
88 | break; |
---|
89 | case SDLK_2: |
---|
90 | obj = new PrimitiveModel(PRIM_SPHERE, 10.0); |
---|
91 | break; |
---|
92 | case SDLK_3: |
---|
93 | obj = new PrimitiveModel(PRIM_PLANE, 10.0); |
---|
94 | break; |
---|
95 | // increase fps |
---|
96 | case SDLK_9: |
---|
97 | fps++; |
---|
98 | PRINTF(1)("fps: %f\n", fps); |
---|
99 | break; |
---|
100 | // decrease fps |
---|
101 | case SDLK_8: |
---|
102 | if(fps > 0) |
---|
103 | fps--; |
---|
104 | PRINTF(1)("fps: %f\n", fps); |
---|
105 | break; |
---|
106 | } |
---|
107 | } |
---|
108 | } |
---|
109 | |
---|
110 | void Framework::moduleTick(float dt) |
---|
111 | { |
---|
112 | timer += dt; |
---|
113 | |
---|
114 | if(counter != fps * timer) |
---|
115 | { |
---|
116 | counter = fps * timer; |
---|
117 | |
---|
118 | if (counter > seq->getFrameCount()) |
---|
119 | { |
---|
120 | timer = 0; |
---|
121 | counter = 0; |
---|
122 | } |
---|
123 | |
---|
124 | seq->gotoFrame(counter); |
---|
125 | } |
---|
126 | } |
---|
127 | |
---|
128 | void Framework::moduleDraw(void) const |
---|
129 | { |
---|
130 | testMat->select(); |
---|
131 | glBindTexture(GL_TEXTURE_2D, seq->getTexture()); |
---|
132 | obj->draw(); |
---|
133 | |
---|
134 | LightManager::getInstance()->draw(); |
---|
135 | } |
---|
136 | |
---|
137 | |
---|
138 | void Framework::moduleHelp(void) const |
---|
139 | { |
---|
140 | |
---|
141 | } |
---|