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: Christoph Renner |
---|
13 | co-programmer: |
---|
14 | */ |
---|
15 | |
---|
16 | #define DEBUG_SPECIAL_MODULE DEBUG_MODULE_WORLD_ENTITY |
---|
17 | |
---|
18 | #include "loading/factory.h" |
---|
19 | #include "debug.h" |
---|
20 | #include "loading/load_param.h" |
---|
21 | #include "util/loading/load_param_xml.h" |
---|
22 | #include "state.h" |
---|
23 | #include "player.h" |
---|
24 | #include "playable.h" |
---|
25 | |
---|
26 | #include "actionbox_enemy.h" |
---|
27 | |
---|
28 | ObjectListDefinition(ActionboxEnemy); |
---|
29 | CREATE_FACTORY(ActionboxEnemy); |
---|
30 | |
---|
31 | ActionboxEnemy::ActionboxEnemy(const TiXmlElement* root) |
---|
32 | { |
---|
33 | PRINTF(0)("ActionboxEnemy\n"); |
---|
34 | |
---|
35 | this->registerObject(this, ActionboxEnemy::_objectList); |
---|
36 | this->toList(OM_GROUP_00); |
---|
37 | |
---|
38 | this->isActive = true; |
---|
39 | |
---|
40 | //TODO init to zero for non-debug |
---|
41 | this->pitch = 0.0f; |
---|
42 | this->dPitch = PI; |
---|
43 | |
---|
44 | if ( root ) |
---|
45 | this->loadParams( root ); |
---|
46 | } |
---|
47 | |
---|
48 | ActionboxEnemy::~ActionboxEnemy() |
---|
49 | { |
---|
50 | } |
---|
51 | |
---|
52 | void ActionboxEnemy::loadParams(const TiXmlElement* root) |
---|
53 | { |
---|
54 | WorldEntity::loadParams( root ); |
---|
55 | } |
---|
56 | |
---|
57 | void ActionboxEnemy::tick( float dt ) |
---|
58 | { |
---|
59 | this->pitch += this->dPitch*dt; |
---|
60 | |
---|
61 | moveTowardsBox( NULL, dt ); |
---|
62 | return; |
---|
63 | |
---|
64 | if ( isActive && State::getActionBox() ) |
---|
65 | { |
---|
66 | ActionBox* box = State::getActionBox(); |
---|
67 | if ( box->isPointInBox( this->getAbsCoor() ) ) |
---|
68 | { |
---|
69 | attackPlayer( box, dt ); |
---|
70 | } |
---|
71 | else |
---|
72 | { |
---|
73 | moveTowardsBox( box, dt ); |
---|
74 | } |
---|
75 | } |
---|
76 | } |
---|
77 | |
---|
78 | void ActionboxEnemy::attackPlayer( ActionBox * box, float dt ) |
---|
79 | { |
---|
80 | } |
---|
81 | |
---|
82 | void ActionboxEnemy::moveTowardsBox( ActionBox * box, float dt ) |
---|
83 | { |
---|
84 | Vector targetPos = State::getPlayer()->getPlayable()->getAbsCoor(); |
---|
85 | |
---|
86 | Vector fw = this->getAbsDir().apply( Vector( 0, 0, -1 ) ); |
---|
87 | fw.normalize(); |
---|
88 | |
---|
89 | Vector dv = targetPos - this->getAbsCoor(); |
---|
90 | dv.normalize(); |
---|
91 | |
---|
92 | Vector up = fw.cross( dv )*-1; |
---|
93 | |
---|
94 | Quaternion rot(up, 10.0*dt); |
---|
95 | rot.normalize(); |
---|
96 | Quaternion cur = this->getAbsDir(); |
---|
97 | Quaternion ne = rot * cur; |
---|
98 | this->setAbsDir( ne ); |
---|
99 | |
---|
100 | // 1, 0, 0 |
---|
101 | // 0, 1, 0 |
---|
102 | return; |
---|
103 | Vector k = ne.apply( Vector( 1, 0, 0 ) ); |
---|
104 | k.normalize(); |
---|
105 | |
---|
106 | Vector vr = k.cross( Vector( 0, 1, 0) ); |
---|
107 | |
---|
108 | rot = Quaternion(vr, 10.0*dt); |
---|
109 | rot.normalize(); |
---|
110 | cur = ne; |
---|
111 | ne = rot * cur; |
---|
112 | ne.normalize(); |
---|
113 | |
---|
114 | this->setAbsDir( ne ); |
---|
115 | } |
---|
116 | |
---|
117 | void ActionboxEnemy::draw( ) const |
---|
118 | { |
---|
119 | Vector fw = this->getAbsDir().apply( Vector( 1, 0, 0 ) ); |
---|
120 | fw.normalize(); |
---|
121 | fw = fw * 100; |
---|
122 | |
---|
123 | Vector mp = this->getAbsCoor(); |
---|
124 | Vector op = mp + fw; |
---|
125 | |
---|
126 | Vector targetPos = State::getPlayer()->getPlayable()->getAbsCoor(); |
---|
127 | Vector dv = targetPos - this->getAbsCoor(); |
---|
128 | dv.normalize(); |
---|
129 | dv *= 100; |
---|
130 | dv += mp; |
---|
131 | |
---|
132 | Vector up = fw.cross( dv )*-1; |
---|
133 | up += mp; |
---|
134 | |
---|
135 | //PRINTF(0)("DEBUG\n"); |
---|
136 | //mp.debug(); |
---|
137 | //op.debug(); |
---|
138 | |
---|
139 | glMatrixMode(GL_MODELVIEW); |
---|
140 | glPushMatrix(); |
---|
141 | |
---|
142 | glPushAttrib(GL_ENABLE_BIT); |
---|
143 | |
---|
144 | glDisable(GL_LIGHTING); |
---|
145 | glDisable(GL_TEXTURE_2D); |
---|
146 | glDisable(GL_BLEND); |
---|
147 | glLineWidth(2.0); |
---|
148 | glColor3f(1.0, 0.0, 0.0 ); |
---|
149 | |
---|
150 | |
---|
151 | glBegin(GL_LINE_STRIP); |
---|
152 | glVertex3f(mp.x, mp.y, mp.z); |
---|
153 | glVertex3f(op.x, op.y, op.z); |
---|
154 | glEnd(); |
---|
155 | |
---|
156 | glBegin(GL_LINE_STRIP); |
---|
157 | glVertex3f(mp.x, mp.y, mp.z); |
---|
158 | glVertex3f(dv.x, dv.y, dv.z); |
---|
159 | glEnd(); |
---|
160 | |
---|
161 | glBegin(GL_LINE_STRIP); |
---|
162 | glVertex3f(mp.x, mp.y, mp.z); |
---|
163 | glVertex3f(up.x, up.y, up.z); |
---|
164 | glEnd(); |
---|
165 | |
---|
166 | glPopMatrix(); |
---|
167 | |
---|
168 | WorldEntity::draw(); |
---|
169 | } |
---|