Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/trunk: sync

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