~ubuntu-branches/ubuntu/precise/rss-glx/precise

« back to all changes in this revision

Viewing changes to src/stretchedParticle.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Steve Langasek
  • Date: 2009-06-03 18:41:32 UTC
  • mfrom: (1.1.5 upstream) (2.2.1 squeeze)
  • Revision ID: james.westby@ubuntu.com-20090603184132-znjy66pq9xom7hac
Tags: 0.9.0-2ubuntu1
* Merge from debian unstable, remaining changes:
  - Drop dependency on openal. It is not enabled by default anyway, and
    allows openal to migrate to universe.
  - src/skyrocket.{cpp,xml}: Disable sound by default.
  - Add --disable-sound configure flag to debian/rules, as we don't keep 
    the dependencies on openal nor freeglut (both universe packages).
* Dropped changes, merged upstream:
  - other_src/Makefile.am: fix the upstream build rules to actually use
    the ImageMagick CFLAGS returned by pkg-config.
  - Move the unconditional ImageMagick check up in configure.in so that
    our first PKG_CHECK_MODULES() call isn't hidden behind a shell
    conditional.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright (C) 2005  Terence M. Welsh
 
3
 * Ported to Linux by Tugrul Galatali <tugrul@galatali.com>
 
4
 *
 
5
 * This file is part of Hyperspace.
 
6
 *
 
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.
 
10
 *
 
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.
 
15
 *
 
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
 
19
 */
 
20
 
 
21
 
 
22
#include <stdio.h>
 
23
#include <math.h>
 
24
#include <GL/gl.h>
 
25
#include <GL/glu.h>
 
26
 
 
27
 
 
28
#include "stretchedParticle.h"
 
29
 
 
30
 
 
31
extern float unroll;
 
32
extern double modelMat[16];
 
33
extern double projMat[16];
 
34
extern int viewport[4];
 
35
 
 
36
 
 
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;
 
41
        
 
42
        radius = 0.03f;
 
43
        color[0] = color[1] = color[2] = 1.0f;
 
44
}
 
45
 
 
46
 
 
47
void stretchedParticle::draw(float* eyepoint){
 
48
        static double winx, winy, winz;
 
49
        gluProject(pos[0], pos[1], pos[2],
 
50
                modelMat, projMat, viewport,
 
51
                &winx, &winy, &winz);
 
52
        if(winz > 0.0f){
 
53
                screenPos[0] = winx;
 
54
                screenPos[1] = winy;
 
55
        }
 
56
 
 
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;
 
60
        lastPos[0] = pos[0];
 
61
        lastPos[1] = pos[1];
 
62
        lastPos[2] = pos[2];
 
63
 
 
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];
 
70
 
 
71
        float bbMat[16];
 
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]);
 
77
        bbMat[8] = pd[0] / n;
 
78
        bbMat[9] = pd[1] / n;
 
79
        bbMat[10] = pd[2] / n;
 
80
        bbMat[0] = bbMat[10];
 
81
        bbMat[2] = -bbMat[8];
 
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];
 
85
 
 
86
        float stretch = 0.0015f * sqrtf(sd[0] * sd[0] + sd[1] * sd[1]) * n / radius;
 
87
        if(stretch < 1.0f)
 
88
                stretch = 1.0f;
 
89
        if(stretch > 0.5f / radius)
 
90
                stretch = 0.5f / radius;
 
91
        glPushMatrix();
 
92
                glTranslatef(drawPos[0], drawPos[1], drawPos[2]);
 
93
                glMultMatrixf(bbMat);
 
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;
 
97
                if(darkener < 1.0f)
 
98
                        darkener = 1.0f;
 
99
                // draw colored aura
 
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);
 
110
                glEnd();
 
111
                // draw white center
 
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);
 
122
                glEnd();
 
123
        glPopMatrix();
 
124
        
 
125
        lastScreenPos[0] = screenPos[0];
 
126
        lastScreenPos[1] = screenPos[1];
 
127
}