1 | |
---|
2 | |
---|
3 | /* |
---|
4 | orxonox - the future of 3D-vertical-scrollers |
---|
5 | |
---|
6 | Copyright (C) 2004 orx |
---|
7 | |
---|
8 | This program is free software; you can redistribute it and/or modify |
---|
9 | it under the terms of the GNU General Public License as published by |
---|
10 | the Free Software Foundation; either version 2, or (at your option) |
---|
11 | any later version. |
---|
12 | |
---|
13 | ### File Specific |
---|
14 | main-programmer: Patrick Boenzli |
---|
15 | co-programmer: |
---|
16 | */ |
---|
17 | |
---|
18 | |
---|
19 | #include "environment.h" |
---|
20 | #include "stdincl.h" |
---|
21 | #include "world_entity.h" |
---|
22 | #include "vector.h" |
---|
23 | #include "objModel.h" |
---|
24 | |
---|
25 | using namespace std; |
---|
26 | |
---|
27 | |
---|
28 | CREATE_FACTORY(Environment); |
---|
29 | |
---|
30 | Environment::Environment () : WorldEntity() |
---|
31 | { |
---|
32 | this->model = new OBJModel("../data/models/fighter.obj"); |
---|
33 | } |
---|
34 | |
---|
35 | Environment::Environment ( TiXmlElement* root) |
---|
36 | { |
---|
37 | assert( root != NULL); |
---|
38 | |
---|
39 | char* temp; |
---|
40 | const char* string = grabParameter( root, "name"); |
---|
41 | |
---|
42 | if( string == NULL) |
---|
43 | { |
---|
44 | PRINTF0("Environment is missing a proper 'name'\n"); |
---|
45 | string = "Unknown"; |
---|
46 | this->setName( string); |
---|
47 | } |
---|
48 | else |
---|
49 | { |
---|
50 | this->setName( string); |
---|
51 | } |
---|
52 | |
---|
53 | this->model = NULL; |
---|
54 | string = grabParameter( root, "model"); |
---|
55 | if( string != NULL) |
---|
56 | this->model = new OBJModel( string); |
---|
57 | else |
---|
58 | { |
---|
59 | PRINTF0("Environment is missing a proper 'model'\n"); |
---|
60 | this->model = new OBJModel( "../data/models/reaplow.obj"); |
---|
61 | } |
---|
62 | if( this->model == NULL) |
---|
63 | { |
---|
64 | PRINTF0("Environment model '%s' could not be loaded\n", string); |
---|
65 | } |
---|
66 | |
---|
67 | double buff[3]; |
---|
68 | |
---|
69 | string = grabParameter( root, "position"); |
---|
70 | if( string != NULL && sscanf( string, "%lf,%lf,%lf", &(buff[0]), &(buff[1]), &(buff[2])) == 3) |
---|
71 | { |
---|
72 | Vector* es = new Vector( buff[0], buff[1], buff[2]); |
---|
73 | this->setAbsCoor(es); |
---|
74 | delete es; |
---|
75 | } |
---|
76 | else |
---|
77 | { |
---|
78 | PRINTF0("Environment is missing a proper 'position'\n"); |
---|
79 | Vector* es = new Vector(); |
---|
80 | this->setAbsCoor(es); |
---|
81 | delete es; |
---|
82 | } |
---|
83 | |
---|
84 | string = grabParameter( root, "orientation"); |
---|
85 | if( string != NULL && sscanf( string, "%lf,%lf,%lf", &(buff[0]), &(buff[1]), &(buff[2])) == 3) |
---|
86 | { |
---|
87 | Quaternion* qs = new Quaternion( buff[0], buff[1], buff[2]); |
---|
88 | this->setAbsDir(qs); |
---|
89 | delete qs; |
---|
90 | } |
---|
91 | else |
---|
92 | { |
---|
93 | PRINTF0("Environment is missing a proper 'orientation'\n"); |
---|
94 | Quaternion* qs = new Quaternion (); |
---|
95 | this->setAbsDir(qs); |
---|
96 | delete qs; |
---|
97 | } |
---|
98 | } |
---|
99 | |
---|
100 | Environment::~Environment () |
---|
101 | { |
---|
102 | |
---|
103 | } |
---|
104 | |
---|
105 | void Environment::tick (float time) {} |
---|
106 | |
---|
107 | void Environment::hit (WorldEntity* weapon, Vector* loc) {} |
---|
108 | |
---|
109 | void Environment::destroy () {} |
---|
110 | |
---|
111 | void Environment::collide (WorldEntity* other, Uint32 ownhitflags, Uint32 otherhitflags) {} |
---|
112 | |
---|
113 | void Environment::draw () |
---|
114 | { |
---|
115 | glMatrixMode(GL_MODELVIEW); |
---|
116 | glPushMatrix(); |
---|
117 | float matrix[4][4]; |
---|
118 | |
---|
119 | glTranslatef (this->getAbsCoor ().x, this->getAbsCoor ().y, this->getAbsCoor ().z); |
---|
120 | //rotate |
---|
121 | this->getAbsDir().matrix (matrix); |
---|
122 | glMultMatrixf((float*)matrix); |
---|
123 | |
---|
124 | this->model->draw(); |
---|
125 | |
---|
126 | glPopMatrix(); |
---|
127 | } |
---|
128 | |
---|