Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 9129 was 7954, checked in by patrick, 18 years ago

trunk: merged the network branche back to trunk.

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