Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/trunk: Shaders get loaded in the release now

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