Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/trunk: merged branches/network back to the trunk.
merged with command:
svn merge https://svn.orxonox.net/orxonox/branches/network . -r6774:HEAD

no conflicts…
thats what i call orthogonal work

File size: 4.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 "network_game_manager.h"
21#include "state.h"
22
23#include "primitive_model.h"
24
25using namespace std;
26
27CREATE_FACTORY(TurretPowerUp, CL_TURRET_POWER_UP);
28
29TurretPowerUp::TurretPowerUp () : PowerUp(0.0, 1.0, 0.0)
30{
31  this->init();
32}
33
34TurretPowerUp::TurretPowerUp(const TiXmlElement* root) : PowerUp(0.0, 1.0, 0.0)
35{
36  this->init();
37
38  if( root != NULL)
39    this->loadParams(root);
40}
41
42
43TurretPowerUp::~TurretPowerUp ()
44{
45  delete this->sphereModel;
46  delete this->sphereMaterial;
47}
48
49
50void TurretPowerUp::init()
51{
52  this->setClassID(CL_TURRET_POWER_UP, "TurretPowerUp");
53  this->loadModel("models/guns/turret1.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(.1, .1, .8);
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 TurretPowerUp::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 TurretPowerUp::collidesWith(WorldEntity* entity, const Vector& location)
80{
81 // PRINTF(3)("collision %s vs %s @ (%f,%f,%f)\n", this->getClassName(), entity->getClassName(), 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 TurretPowerUp::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 TurretPowerUp::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
124
125
126/********************************************************************************************
127 NETWORK STUFF
128 ********************************************************************************************/
129
130
131int TurretPowerUp::writeBytes( const byte * data, int length, int sender )
132{
133  setRequestedSync( false );
134  setIsOutOfSync( false );
135
136  SYNCHELP_READ_BEGIN();
137
138  SYNCHELP_READ_FKT( PowerUp::writeState, NWT_TPU_WE_STATE );
139
140  return SYNCHELP_READ_N;
141}
142
143
144int TurretPowerUp::readBytes( byte * data, int maxLength, int * reciever )
145{
146  if ( isOutOfSync() && !requestedSync() && this->getHostID()!=this->getOwner() )
147  {
148    (NetworkGameManager::getInstance())->sync( this->getUniqueID(), this->getOwner() );
149    setRequestedSync( true );
150  }
151
152  int rec = this->getRequestSync();
153  if ( rec > 0 )
154  {
155    *reciever = rec;
156
157    SYNCHELP_WRITE_BEGIN();
158
159    SYNCHELP_WRITE_FKT( PowerUp::readState, NWT_TPU_WE_STATE );
160
161    return SYNCHELP_WRITE_N;
162  }
163
164  *reciever = 0;
165  return 0;
166}
Note: See TracBrowser for help on using the repository browser.