Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/orxonox/trunk/src/world_entities/weapons/crosshair.cc @ 4781

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

orxonox/trunk: the mighty useless crosshair…

File size: 2.2 KB
Line 
1/*
2   orxonox - the future of 3D-vertical-scrollers
3
4   Copyright (C) 2004 orx
5
6   This program is free software; you can redistribute it and/or modify
7   it under the terms of the GNU General Public License as published by
8   the Free Software Foundation; either version 2, or (at your option)
9   any later version.
10
11   ### File Specific:
12   main-programmer: Benjamin Grauer
13   co-programmer: ...
14*/
15
16//#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_
17
18#include "crosshair.h"
19#include "event_handler.h"
20
21#include "graphics_engine.h"
22#include "glincl.h"
23#include "p_node.h"
24#include "state.h"
25
26using namespace std;
27
28
29/**
30   \brief standard constructor
31*/
32Crosshair::Crosshair ()
33{
34  this->setClassID(CL_CROSSHAIR, "Crosshair");
35  this->setName("Crosshair");
36
37  EventHandler::getInstance()->subscribe(this, ES_GAME, EV_MOUSE_MOTION);
38
39}
40
41
42/**
43   \brief standard deconstructor
44*/
45Crosshair::~Crosshair ()
46{
47  // delete what has to be deleted here
48}
49
50void Crosshair::process(const Event &event)
51{
52  if  (event.type == EV_MOUSE_MOTION)
53  {
54    this->position2D[0] = event.x;
55    this->position2D[1] = event.y;
56  }
57
58}
59
60
61void Crosshair::draw() const
62{
63  const PNode* camera = State::getInstance()->getCamera();  //!< \todo MUST be different
64  Vector cameraPos = camera->getAbsCoor();
65  Vector cameraTargetPos = State::getInstance()->getCameraTarget()->getAbsCoor();
66  Vector view = cameraTargetPos - cameraPos;
67  Vector up = Vector(0, 1, 0);
68  up = camera->getAbsDir().apply(up);
69  Vector h = up.cross(view);
70  Vector v = h.cross(view);
71  h.normalize();
72  v.normalize();
73
74  float px = (position2D[0]-GraphicsEngine::getInstance()->getResolutionX()/2)*.05;
75  float py = -(position2D[1]-GraphicsEngine::getInstance()->getResolutionY()/2)*.05;
76
77
78
79  glBegin(GL_TRIANGLES);
80  glVertex3f(cameraTargetPos.x - h.x*px - v.x*py,
81             cameraTargetPos.y - h.y*px - v.y*py,
82             cameraTargetPos.z - h.z*px - v.z*py);
83
84  glVertex3f(cameraTargetPos.x - h.x*(px+1) - v.x*py,
85             cameraTargetPos.y - h.y*(px+1) - v.y*py,
86             cameraTargetPos.z - h.z*(px+1) - v.z*py);
87
88  glVertex3f(cameraTargetPos.x - h.x*px - v.x*(py+1),
89             cameraTargetPos.y - h.y*px - v.y*(py+1),
90             cameraTargetPos.z - h.z*px - v.z*(py+1));
91
92  glEnd();
93
94}
Note: See TracBrowser for help on using the repository browser.