Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/test/src/world_entities/power_ups/laser_power_up.cc

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

orxonox/trunk: merged the new_class_id branche back to the trunk.
merged with command:
svn merge https://svn.orxonox.net/orxonox/branches/new_class_id trunk -r9683:HEAD
no conflicts… puh..

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