2
* Copyright (C) 2005 Terence M. Welsh
3
* Ported to Linux by Tugrul Galatali <tugrul@galatali.com>
5
* This file is part of Hyperspace.
7
* Hyperspace is free software; you can redistribute it and/or modify
8
* it under the terms of the GNU General Public License version 2 as
9
* published by the Free Software Foundation.
11
* Hyperspace is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
* GNU General Public License for more details.
16
* You should have received a copy of the GNU General Public License
17
* along with this program; if not, write to the Free Software
18
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
28
#include "stretchedParticle.h"
32
extern double modelMat[16];
33
extern double projMat[16];
34
extern int viewport[4];
37
stretchedParticle::stretchedParticle(){
38
pos[0] = pos[1] = pos[2] = 0.0f;
39
lastPos[0] = lastPos[1] = lastPos[2] = 0.0f;
40
drawPos[0] = drawPos[1] = drawPos[2] = 0.0f;
43
color[0] = color[1] = color[2] = 1.0f;
47
void stretchedParticle::draw(float* eyepoint){
48
static double winx, winy, winz;
49
gluProject(pos[0], pos[1], pos[2],
50
modelMat, projMat, viewport,
57
drawPos[0] = (pos[0] + lastPos[0]) * 0.5f;
58
drawPos[1] = (pos[1] + lastPos[1]) * 0.5f;
59
drawPos[2] = (pos[2] + lastPos[2]) * 0.5f;
64
float sd[2], pd[3]; // screen difference, position difference
65
sd[0] = float(screenPos[0] - lastScreenPos[0]);
66
sd[1] = float(screenPos[1] - lastScreenPos[1]);
67
pd[0] = eyepoint[0] - drawPos[0];
68
pd[1] = eyepoint[1] - drawPos[1];
69
pd[2] = eyepoint[2] - drawPos[2];
72
bbMat[0] = bbMat[5] = bbMat[10] = bbMat[15] = 1.0f;
73
bbMat[1] = bbMat[2] = bbMat[3] = bbMat[4] =
74
bbMat[6] = bbMat[7] = bbMat[8] = bbMat[9] =
75
bbMat[11] = bbMat[12] = bbMat[13] = bbMat[14] = 0.0f;
76
float n = sqrtf(pd[0] * pd[0] + pd[1] * pd[1] + pd[2] * pd[2]);
79
bbMat[10] = pd[2] / n;
82
bbMat[4] = bbMat[9] * bbMat[2] - bbMat[1] * bbMat[10];
83
bbMat[5] = bbMat[10] * bbMat[0] - bbMat[2] * bbMat[8];
84
bbMat[6] = bbMat[8] * bbMat[1] - bbMat[0] * bbMat[9];
86
float stretch = 0.0015f * sqrtf(sd[0] * sd[0] + sd[1] * sd[1]) * n / radius;
89
if(stretch > 0.5f / radius)
90
stretch = 0.5f / radius;
92
glTranslatef(drawPos[0], drawPos[1], drawPos[2]);
94
glRotatef(57.2957795131f * atan2f(sd[1], sd[0]) + unroll, 0, 0, 1);
95
glScalef(stretch, 1.0f, 1.0f);
96
float darkener = stretch * 0.5f;
100
glColor3f(color[0] / darkener, color[1] / darkener, color[2] / darkener);
101
glBegin(GL_TRIANGLE_STRIP);
102
glTexCoord2f(0.0f, 0.0f);
103
glVertex3f(-radius, -radius, 0.0f);
104
glTexCoord2f(1.0f, 0.0f);
105
glVertex3f(radius, -radius, 0.0f);
106
glTexCoord2f(0.0f, 1.0f);
107
glVertex3f(-radius, radius, 0.0f);
108
glTexCoord2f(1.0f, 1.0f);
109
glVertex3f(radius, radius, 0.0f);
112
glColor3f(1.0f / darkener, 1.0f / darkener, 1.0f / darkener);
113
glBegin(GL_TRIANGLE_STRIP);
114
glTexCoord2f(0.0f, 0.0f);
115
glVertex3f(-radius*0.3f, -radius*0.3f, 0.0f);
116
glTexCoord2f(1.0f, 0.0f);
117
glVertex3f(radius*0.3f, -radius*0.3f, 0.0f);
118
glTexCoord2f(0.0f, 1.0f);
119
glVertex3f(-radius*0.3f, radius*0.3f, 0.0f);
120
glTexCoord2f(1.0f, 1.0f);
121
glVertex3f(radius*0.3f, radius*0.3f, 0.0f);
125
lastScreenPos[0] = screenPos[0];
126
lastScreenPos[1] = screenPos[1];