Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/network/src/world_entities/npc2.cc @ 5516

Last change on this file since 5516 was 5500, checked in by bensch, 19 years ago

orxonox/trunk: all the WorldEntities now have a const function to draw themselves

File size: 2.5 KB
Line 
1
2
3/*
4   orxonox - the future of 3D-vertical-scrollers
5
6   Copyright (C) 2004 orx
7
8   This program is free software; you can redistribute it and/or modify
9   it under the terms of the GNU General Public License as published by
10   the Free Software Foundation; either version 2, or (at your option)
11   any later version.
12
13   ### File Specific:
14   main-programmer: Patrick Boenzli
15   co-programmer:
16*/
17#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_WORLD_ENTITY
18
19
20#include "npc2.h"
21#include "obb_tree.h"
22
23#include "shader.h"
24#include "state.h"
25#include "list.h"
26#include "stdlibincl.h"
27
28using namespace std;
29
30
31NPC2::NPC2()
32{
33  this->setClassID(CL_NPC, "NPC");
34
35  this->loadModel("models/ships/bolido.obj", 3);
36  this->shader = NULL;
37  if (likely(Shader::checkShaderAbility()))
38    this->shader = Shader::getShader("shaders/toon.vert", "shaders/toon.frag");
39
40  this->obj = gluNewQuadric();
41
42  this->randomRotAxis = VECTOR_RAND(1);
43}
44
45
46NPC2::~NPC2 ()
47{
48  if (this->shader)
49    Shader::unload(this->shader);
50  gluDeleteQuadric(this->obj);
51}
52
53
54void NPC2::collidesWith(WorldEntity* entity, const Vector& location)
55{
56  if (entity->isA(CL_PROJECTILE))
57  {
58    PRINTF(3)("collision %s vs %s @ (%f,%f,%f)\n", this->getName(), entity->getName(), location.x, location.y, location.z);
59    this->applyForce(Vector(0,0,0)-location*1000);
60  }
61  else if (entity->isA(CL_PLAYER))
62    this->applyForce(Vector(0,0,0)-location*100);
63  else
64  {
65    this->setVisibiliy(false);
66   State::getWorldEntityList()->remove(this);
67  }
68}
69
70
71/**
72 *  the entity is drawn onto the screen with this function
73 *
74 * This is a central function of an entity: call it to let the entity painted to the screen.
75 * Just override this function with whatever you want to be drawn.
76 */
77void NPC2::draw() const
78{
79  glMatrixMode(GL_MODELVIEW);
80  glPushMatrix();
81  float matrix[4][4];
82
83  /* translate */
84  glTranslatef (this->getAbsCoor ().x,
85                this->getAbsCoor ().y,
86                this->getAbsCoor ().z);
87  /* rotate */
88  this->getAbsDir ().matrix (matrix);
89  glMultMatrixf((float*)matrix);
90
91  if (this->shader != NULL && this->shader != Shader::getActiveShader())
92    shader->activateShader();
93  gluSphere(this->obj, 3, 10, 10);
94  shader->deactivateShader();
95
96
97/*  if (this->model)
98    this->model->draw();*/
99  glPopMatrix();
100}
101
102
103void NPC2::tick(float dt)
104{
105//  Vector direction = (State::getCameraTarget()->getAbsCoor() - this->getAbsCoor());
106
107  //if (directin.len() < 100)
108//  this->shiftCoor(direction *dt * 5 * exp(-direction.len() / 30.0));
109  this->shiftDir(Quaternion(dt, this->randomRotAxis));
110
111}
112
113
114
Note: See TracBrowser for help on using the repository browser.