Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/trunk/src/world_entities/npc2.cc @ 5357

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

orxonox/trunk: some minor cleanup, of the mess i made with AutoMake-sh

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
27using namespace std;
28
29
30NPC2::NPC2()
31{
32  this->setClassID(CL_NPC, "NPC");
33
34  this->loadModelWithScale("models/ships/bolido.obj", 3);
35  this->shader = NULL;
36  if (likely(Shader::checkShaderAbility()))
37    this->shader = Shader::getShader("shaders/toon.vert", "shaders/toon.frag");
38
39  this->obj = gluNewQuadric();
40
41  this->randomRotAxis = VECTOR_RAND(1);
42}
43
44
45NPC2::~NPC2 ()
46{
47  Shader::unload(this->shader);
48  gluDeleteQuadric(this->obj);
49}
50
51
52void NPC2::collidesWith(WorldEntity* entity, const Vector& location)
53{
54  if (entity->isA(CL_PROJECTILE))
55  {
56    PRINTF(3)("collision %s vs %s @ (%f,%f,%f)\n", this->getName(), entity->getName(), location.x, location.y, location.z);
57    this->applyForce(Vector(0,0,0)-location*1000);
58  }
59  else if (entity->isA(CL_PLAYER))
60    this->applyForce(Vector(0,0,0)-location*100);
61  else
62  {
63    this->setVisibiliy(false);
64   State::getWorldEntityList()->remove(this);
65  }
66}
67
68
69/**
70 *  the entity is drawn onto the screen with this function
71 *
72 * This is a central function of an entity: call it to let the entity painted to the screen.
73 * Just override this function with whatever you want to be drawn.
74 */
75void NPC2::draw()
76{
77  glMatrixMode(GL_MODELVIEW);
78  glPushMatrix();
79  float matrix[4][4];
80
81  /* translate */
82  glTranslatef (this->getAbsCoor ().x,
83                this->getAbsCoor ().y,
84                this->getAbsCoor ().z);
85  /* rotate */
86  this->getAbsDir ().matrix (matrix);
87  glMultMatrixf((float*)matrix);
88
89  if (this->shader != NULL && this->shader != Shader::getActiveShader())
90    shader->activateShader();
91  gluSphere(this->obj, 3, 10, 10);
92  shader->deactivateShader();
93
94
95/*  if (this->model)
96    this->model->draw();*/
97  glPopMatrix();
98}
99
100
101void NPC2::tick(float dt)
102{
103//  Vector direction = (State::getCameraTarget()->getAbsCoor() - this->getAbsCoor());
104
105  //if (directin.len() < 100)
106//  this->shiftCoor(direction *dt * 5 * exp(-direction.len() / 30.0));
107  this->shiftDir(Quaternion(dt, this->randomRotAxis));
108
109}
110
111
112
Note: See TracBrowser for help on using the repository browser.