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: Benjamin Grauer |
---|
13 | co-programmer: ... |
---|
14 | */ |
---|
15 | |
---|
16 | #define DEBUG_SPECIAL_MODULE DEBUG_MODULE_WORLD_ENTITY |
---|
17 | |
---|
18 | #include "turret_power_up.h" |
---|
19 | #include "util/loading/factory.h" |
---|
20 | #include "network_game_manager.h" |
---|
21 | #include "state.h" |
---|
22 | |
---|
23 | #include "primitive_model.h" |
---|
24 | |
---|
25 | |
---|
26 | #include "class_id_DEPRECATED.h" |
---|
27 | ObjectListDefinitionID(TurretPowerUp, CL_TURRET_POWER_UP); |
---|
28 | CREATE_FACTORY(TurretPowerUp); |
---|
29 | |
---|
30 | TurretPowerUp::TurretPowerUp(const TiXmlElement* root) : PowerUp(0.0, 1.0, 0.0) |
---|
31 | { |
---|
32 | this->init(); |
---|
33 | |
---|
34 | if( root != NULL) |
---|
35 | this->loadParams(root); |
---|
36 | } |
---|
37 | |
---|
38 | |
---|
39 | TurretPowerUp::~TurretPowerUp () |
---|
40 | { |
---|
41 | delete this->sphereModel; |
---|
42 | delete this->sphereMaterial; |
---|
43 | } |
---|
44 | |
---|
45 | |
---|
46 | void TurretPowerUp::init() |
---|
47 | { |
---|
48 | this->registerObject(this, TurretPowerUp::_objectList); |
---|
49 | this->loadModel("models/guns/turret1.obj", 2.0); |
---|
50 | |
---|
51 | this->sphereModel = new PrimitiveModel(PRIM_SPHERE, 7, 5); |
---|
52 | this->sphereMaterial = new Material; |
---|
53 | this->sphereMaterial->setTransparency(.1); |
---|
54 | this->sphereMaterial->setDiffuse(.1, .1, .8); |
---|
55 | |
---|
56 | this->rotation = Vector(0,1,0); |
---|
57 | this->cycle = (float)rand()/RAND_MAX*M_2_PI; |
---|
58 | this->shiftDir(Quaternion((float)rand()/RAND_MAX*M_2_PI, this->rotation)); |
---|
59 | } |
---|
60 | |
---|
61 | |
---|
62 | void TurretPowerUp::loadParams(const TiXmlElement* root) |
---|
63 | { |
---|
64 | PowerUp::loadParams(root); |
---|
65 | |
---|
66 | } |
---|
67 | |
---|
68 | |
---|
69 | /** |
---|
70 | * this function is called, when two entities collide |
---|
71 | * @param entity: the world entity with whom it collides |
---|
72 | * |
---|
73 | * Implement behaviour like damage application or other miscellaneous collision stuff in this function |
---|
74 | */ |
---|
75 | void TurretPowerUp::collidesWith(WorldEntity* entity, const Vector& location) |
---|
76 | { |
---|
77 | // PRINTF(3)("collision %s vs %s @ (%f,%f,%f)\n", this->getClassCName(), entity->getClassCName(), location.x, location.y, location.z); |
---|
78 | if (entity->isA(CL_PLAYABLE)) |
---|
79 | this->toList(OM_DEAD); |
---|
80 | } |
---|
81 | |
---|
82 | /** |
---|
83 | * this method is called every frame |
---|
84 | * @param time: the time in seconds that has passed since the last tick |
---|
85 | * |
---|
86 | * Handle all stuff that should update with time inside this method (movement, animation, etc.) |
---|
87 | */ |
---|
88 | void TurretPowerUp::tick(float dt) |
---|
89 | { |
---|
90 | this->shiftDir(Quaternion(dt, this->rotation)); |
---|
91 | this->cycle+=dt; |
---|
92 | |
---|
93 | } |
---|
94 | |
---|
95 | /** |
---|
96 | * the entity is drawn onto the screen with this function |
---|
97 | * |
---|
98 | * This is a central function of an entity: call it to let the entity painted to the screen. |
---|
99 | * Just override this function with whatever you want to be drawn. |
---|
100 | */ |
---|
101 | void TurretPowerUp::draw() const |
---|
102 | { |
---|
103 | glMatrixMode(GL_MODELVIEW); |
---|
104 | glPushMatrix(); |
---|
105 | /* translate */ |
---|
106 | glTranslatef (this->getAbsCoor ().x, |
---|
107 | this->getAbsCoor ().y + cos(this->cycle*3.0)*2.0, |
---|
108 | this->getAbsCoor ().z); |
---|
109 | /* rotate */ |
---|
110 | Vector tmpRot = this->getAbsDir().getSpacialAxis(); |
---|
111 | glRotatef (this->getAbsDir().getSpacialAxisAngle(), tmpRot.x, tmpRot.y, tmpRot.z ); |
---|
112 | this->getModel()->draw(); |
---|
113 | |
---|
114 | this->sphereMaterial->select(); |
---|
115 | this->sphereModel->draw(); |
---|
116 | glPopMatrix(); |
---|
117 | } |
---|