Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/trunk: more cleanup of the WorldEntity (includes rearanged)

File size: 2.5 KB
RevLine 
[1853]1
2
[4597]3/*
[1853]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.
[1855]12
13   ### File Specific:
14   main-programmer: Patrick Boenzli
15   co-programmer:
[1853]16*/
[5357]17#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_WORLD_ENTITY
[1853]18
19
[5266]20#include "npc2.h"
[5033]21#include "obb_tree.h"
[1853]22
[5266]23#include "shader.h"
[4984]24#include "state.h"
[5064]25#include "list.h"
[5427]26#include "stdlibincl.h"
[5511]27#include "debug.h"
[4984]28
[5511]29
[1858]30using namespace std;
[1853]31
[1858]32
[5266]33NPC2::NPC2()
[1931]34{
[4597]35  this->setClassID(CL_NPC, "NPC");
[4976]36
[5499]37  this->loadModel("models/ships/bolido.obj", 3);
[5333]38  this->shader = NULL;
39  if (likely(Shader::checkShaderAbility()))
40    this->shader = Shader::getShader("shaders/toon.vert", "shaders/toon.frag");
[5059]41
[5266]42  this->obj = gluNewQuadric();
43
[5059]44  this->randomRotAxis = VECTOR_RAND(1);
[1931]45}
[1853]46
[5034]47
[5267]48NPC2::~NPC2 ()
49{
[5363]50  if (this->shader)
51    Shader::unload(this->shader);
[5313]52  gluDeleteQuadric(this->obj);
[5267]53}
[1853]54
[5267]55
[5266]56void NPC2::collidesWith(WorldEntity* entity, const Vector& location)
[5029]57{
[5053]58  if (entity->isA(CL_PROJECTILE))
[5258]59  {
[5065]60    PRINTF(3)("collision %s vs %s @ (%f,%f,%f)\n", this->getName(), entity->getName(), location.x, location.y, location.z);
[5258]61    this->applyForce(Vector(0,0,0)-location*1000);
62  }
[5259]63  else if (entity->isA(CL_PLAYER))
64    this->applyForce(Vector(0,0,0)-location*100);
65  else
[5258]66  {
67    this->setVisibiliy(false);
68   State::getWorldEntityList()->remove(this);
69  }
[1931]70}
71
[5029]72
[5266]73/**
74 *  the entity is drawn onto the screen with this function
75 *
76 * This is a central function of an entity: call it to let the entity painted to the screen.
77 * Just override this function with whatever you want to be drawn.
78 */
[5500]79void NPC2::draw() const
[4984]80{
[5266]81  glMatrixMode(GL_MODELVIEW);
82  glPushMatrix();
83  float matrix[4][4];
84
85  /* translate */
86  glTranslatef (this->getAbsCoor ().x,
87                this->getAbsCoor ().y,
88                this->getAbsCoor ().z);
89  /* rotate */
90  this->getAbsDir ().matrix (matrix);
91  glMultMatrixf((float*)matrix);
92
[5323]93  if (this->shader != NULL && this->shader != Shader::getActiveShader())
94    shader->activateShader();
[5268]95  gluSphere(this->obj, 3, 10, 10);
[5333]96  shader->deactivateShader();
[5266]97
98
99/*  if (this->model)
100    this->model->draw();*/
101  glPopMatrix();
102}
103
104
105void NPC2::tick(float dt)
106{
[5257]107//  Vector direction = (State::getCameraTarget()->getAbsCoor() - this->getAbsCoor());
[2036]108
[4986]109  //if (directin.len() < 100)
[5257]110//  this->shiftCoor(direction *dt * 5 * exp(-direction.len() / 30.0));
[5060]111  this->shiftDir(Quaternion(dt, this->randomRotAxis));
[4986]112
[4984]113}
114
115
[5033]116
Note: See TracBrowser for help on using the repository browser.