Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 4824 was 4824, checked in by bensch, 20 years ago

orxonox/trunk: cleaned out the crosshair of the Player

File size: 3.3 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  EventHandler::getInstance()->unsubscribe(this);
49}
50
51void Crosshair::process(const Event &event)
52{
53  if  (event.type == EV_MOUSE_MOTION)
54  {
55    this->position2D[0] = event.x;
56    this->position2D[1] = event.y;
57  }
58
59  /*
60  GLdouble z;
61  GLdouble objX, objY, objZ;
62  glReadPixels (event.x, event.y, 1, 1, GL_DEPTH_COMPONENT, GL_DOUBLE, &z);
63
64
65  if (gluUnProject(event.x,
66      event.y,
67      10,
68      GraphicsEngine::modMat,
69      GraphicsEngine::projMat,
70      GraphicsEngine::viewPort,
71      &objX,
72      &objY,
73      &objZ ))
74    PRINT(0)("screen %d %d -> obj(%f/%f/%f)\n", event.x, event.y, objX, objY, objZ);
75  else
76    PRINT(0)("shit\n");
77*/
78}
79
80
81void Crosshair::draw() const
82{
83  /*
84  const PNode* camera = State::getInstance()->getCamera();  //!< \todo MUST be different
85  Vector cameraPos = camera->getAbsCoor();
86  Vector cameraTargetPos = State::getInstance()->getCameraTarget()->getAbsCoor();
87  Vector view = cameraTargetPos - cameraPos;
88  Vector up = Vector(0, 1, 0);
89  up = camera->getAbsDir().apply(up);
90  Vector h = up.cross(view);
91  Vector v = h.cross(view);
92  h.normalize();
93  v.normalize();
94
95  float px = (position2D[0]-GraphicsEngine::getInstance()->getResolutionX()/2)*.05;
96  float py = -(position2D[1]-GraphicsEngine::getInstance()->getResolutionY()/2)*.05;
97
98  glBegin(GL_TRIANGLES);
99  glVertex3f(cameraTargetPos.x - h.x*px - v.x*py,
100  cameraTargetPos.y - h.y*px - v.y*py,
101  cameraTargetPos.z - h.z*px - v.z*py);
102
103  glVertex3f(cameraTargetPos.x - h.x*(px+1) - v.x*py,
104  cameraTargetPos.y - h.y*(px+1) - v.y*py,
105  cameraTargetPos.z - h.z*(px+1) - v.z*py);
106
107  glVertex3f(cameraTargetPos.x - h.x*px - v.x*(py+1),
108  cameraTargetPos.y - h.y*px - v.y*(py+1),
109  cameraTargetPos.z - h.z*px - v.z*(py+1));
110
111  glEnd();
112
113  */
114
115  GraphicsEngine::storeMatrices();
116
117  GLfloat z;
118  glReadPixels ((int)position2D[0], GraphicsEngine::getInstance()->getResolutionY()-(int)position2D[1], 1, 1, GL_DEPTH_COMPONENT, GL_DOUBLE, &z);
119
120  printf("%p:: %d %d %f\n",this, (int)position2D[0], (int)position2D[1], z);
121
122  GLdouble objX, objY, objZ;
123  if (gluUnProject(position2D[0],
124      GraphicsEngine::getInstance()->getResolutionY()-position2D[1],
125      z,
126      GraphicsEngine::modMat,
127      GraphicsEngine::projMat,
128      GraphicsEngine::viewPort,
129      &objX,
130      &objY,
131      &objZ ));
132  /*
133  glBegin(GL_TRIANGLES);
134  glColor3f(1,0,0);
135  glVertex3f(objX, objY, objZ);
136  glVertex3f(objX, objY+1, objZ);
137  glVertex3f(objX, objY, objZ+1);
138  glEnd();
139  */
140}
Note: See TracBrowser for help on using the repository browser.