[4744] | 1 | /* |
---|
[1853] | 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. |
---|
[1855] | 10 | |
---|
| 11 | ### File Specific: |
---|
[4779] | 12 | main-programmer: Benjamin Grauer |
---|
[1855] | 13 | co-programmer: ... |
---|
[1853] | 14 | */ |
---|
| 15 | |
---|
[3955] | 16 | //#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_ |
---|
[1853] | 17 | |
---|
[4779] | 18 | #include "crosshair.h" |
---|
[4780] | 19 | #include "event_handler.h" |
---|
[4781] | 20 | |
---|
| 21 | #include "graphics_engine.h" |
---|
| 22 | #include "glincl.h" |
---|
| 23 | #include "p_node.h" |
---|
| 24 | #include "state.h" |
---|
| 25 | |
---|
[1856] | 26 | using namespace std; |
---|
[1853] | 27 | |
---|
[1856] | 28 | |
---|
[3245] | 29 | /** |
---|
| 30 | \brief standard constructor |
---|
| 31 | */ |
---|
[4779] | 32 | Crosshair::Crosshair () |
---|
[3365] | 33 | { |
---|
[4779] | 34 | this->setClassID(CL_CROSSHAIR, "Crosshair"); |
---|
| 35 | this->setName("Crosshair"); |
---|
[4320] | 36 | |
---|
[4780] | 37 | EventHandler::getInstance()->subscribe(this, ES_GAME, EV_MOUSE_MOTION); |
---|
| 38 | |
---|
[3365] | 39 | } |
---|
[1853] | 40 | |
---|
| 41 | |
---|
[3245] | 42 | /** |
---|
| 43 | \brief standard deconstructor |
---|
| 44 | */ |
---|
[4779] | 45 | Crosshair::~Crosshair () |
---|
[3543] | 46 | { |
---|
| 47 | // delete what has to be deleted here |
---|
| 48 | } |
---|
[4779] | 49 | |
---|
| 50 | void Crosshair::process(const Event &event) |
---|
| 51 | { |
---|
[4781] | 52 | if (event.type == EV_MOUSE_MOTION) |
---|
| 53 | { |
---|
| 54 | this->position2D[0] = event.x; |
---|
| 55 | this->position2D[1] = event.y; |
---|
| 56 | } |
---|
[4779] | 57 | |
---|
| 58 | } |
---|
[4781] | 59 | |
---|
| 60 | |
---|
| 61 | void 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 | } |
---|