-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathparastarfield.cpp
More file actions
125 lines (105 loc) · 4.13 KB
/
Copy pathparastarfield.cpp
File metadata and controls
125 lines (105 loc) · 4.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
#include "mastrix.hpp"
Starfield::Starfield()
{
reinit();
}
void Starfield::reinit(void)
{
//Star Densities
numSmallStars = 2000;
numLargeStars = 200;
int screenWidth = graphics.getScreenWidth();
int screenHeight = graphics.getScreenHeight();
//clear the star data out
smallStars.clear();
largeStars.clear();
//resize the vectors to appropriate sizes
smallStars.resize(numSmallStars);
largeStars.resize(numLargeStars);
for (int i = 0; i < numSmallStars; i++) {smallStars[i].x = randFloat(0.0, screenWidth);}
for (int i = 0; i < numSmallStars; i++) {smallStars[i].y = randFloat(0.0, screenHeight);}
for (int i = 0; i < numSmallStars; i++) {
smallStars[i].depth = randFloat(0.1, 0.9);
smallStars[i].bright = (int)(/*randInt(155,235)*/ 255*smallStars[i].depth);
}
//for (int i = 0; i < numSmallStars; i++) {smallStars[i].bright = randInt(135,235);}
for (int i = 0; i < numLargeStars; i++) {largeStars[i].x = randFloat(0, screenWidth);}
for (int i = 0; i < numLargeStars; i++) {largeStars[i].y = randFloat(0, screenHeight);}
for (int i = 0; i < numLargeStars; i++) {
largeStars[i].depth = randFloat(0.1, 1.0);
largeStars[i].bright = (int)(randInt(80,160)*largeStars[i].depth);
}
//for (int i = 0; i < numLargeStars; i++) {largeStars[i].bright = randInt(80,160);}
}
ClientConsoleVar<bool> enableStars("enable_stars", true);
void Starfield::draw(const Position &camera, const ClientViewport *viewport)
{
int modx = graphics.getScreenWidth();
int mody = graphics.getScreenHeight();
float offsetx = camera.getX()*zoom;
float offsety = camera.getY()*zoom;
float viewleft = viewport->left;
float viewright = viewport->right;
float viewtop = viewport->top;
float viewbotm = viewport->bottom;
// flicker offsets
int z, zdim, zbright;
if(!enableStars)
return;
//for drawing the group of points all at once
glPointSize(1.0f);
glBegin(GL_POINTS);
for (int i = 0; i < numSmallStars; i++)
{
float basex = smallStars[i].x-(offsetx*smallStars[i].depth);
float basey = smallStars[i].y-(offsety*smallStars[i].depth);
//int px = (int)(smallStars[i].x-(offsetx*smallStars[i].depth) + (modx<<7))%modx;
//int py = (int)(smallStars[i].y-(offsety*smallStars[i].depth) + (mody<<7))%mody;
float px = basex - modx*floor(basex/modx);
float py = basey - mody*floor(basey/mody);
if (px >= viewleft && px <= viewright && py >= viewtop && py <= viewbotm) {
z = /*randInt(-20, 20) +*/ smallStars[i].bright;
graphics.setColor(Color(z, z, z));
glVertex2f(px, py);
}
}
for (int i = 0; i < numLargeStars; i++)
{
// zdim = randInt(-20, 20) + largeStars[i].bright;
// zbright = (int)(randInt(215,255)*largeStars[i].depth);
zdim = largeStars[i].bright;
zbright = largeStars[i].bright;
//ColorX c(zdim, zdim, zdim);
Color c(zdim, zdim, zdim);
graphics.setColor(c);
int px1 = (int)((largeStars[i].x - 1) - (offsetx*largeStars[i].depth) + (modx<<7)) % modx;
int py1 = (int)((largeStars[i].y - 1) - (offsety*largeStars[i].depth) + (mody<<7)) % mody;
int px2 = (int)((largeStars[i].x + 1) - (offsetx*largeStars[i].depth) + (modx<<7)) % modx;
int py2 = (int)((largeStars[i].y + 1) - (offsety*largeStars[i].depth) + (mody<<7)) % mody;
int px = (int)(largeStars[i].x-(offsetx*largeStars[i].depth) + (modx<<7))%modx;
int py = (int)(largeStars[i].y-(offsety*largeStars[i].depth) + (mody<<7))%mody;
// Dimmer surrounding points
/*
if (px1 >= viewleft && px1 < viewright) {
if (py1 >= viewtop && py1 <= viewbotm)
graphics.drawVertex(px1, py1);
if (py2 >= viewtop && py2 <= viewbotm)
graphics.drawVertex(px1, py2);
}
if (px2 >= viewleft && px2 < viewright) {
if (py1 >= viewtop && py1 <= viewbotm)
graphics.drawVertex(px2, py1);
if (py2 >= viewtop && py2 <= viewbotm)
graphics.drawVertex(px2, py2);
}
*/
// "Core" bright point
if (px >= viewleft && px <= viewright && py >= viewtop && py <= viewbotm) {
//GameX.DrawPoint(ColorX(zbright,zbright,zbright), px, py);
//graphics.drawPoint(Color(zbright, zbright, zbright), px, py);
//graphics.setColor(Color(zbright, zbright, zbright));
//graphics.drawVertex(px, py);
}
}
glEnd(); //GL_POINTS
}