Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/trunk/src/world_entities/power_ups/turret_power_up.cc @ 6222

Last change on this file since 6222 was 6222, checked in by bensch, 18 years ago

orxonox/trunk: merged the christmas branche to the trunk
merged with command:
svn merge -r6165:HEAD christmas_branche/ ../trunk/
no conflicts

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