projects
/
xscreensaver
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
From http://www.jwz.org/xscreensaver/xscreensaver-5.30.tar.gz
[xscreensaver]
/
hacks
/
glx
/
sphere.c
diff --git
a/hacks/glx/sphere.c
b/hacks/glx/sphere.c
index eb004b11814a14075f3603cf4fd07e38b3db52dc..ff456cd4316b3ce9a1b5d8ec08d97e62e7614e9e 100644
(file)
--- a/
hacks/glx/sphere.c
+++ b/
hacks/glx/sphere.c
@@
-1,5
+1,5
@@
/* sphere, Copyright (c) 2002 Paul Bourke <pbourke@swin.edu.au>,
/* sphere, Copyright (c) 2002 Paul Bourke <pbourke@swin.edu.au>,
- * Copyright (c) 2010 Jamie Zawinski <jwz@jwz.org>
+ * Copyright (c) 2010
-2014
Jamie Zawinski <jwz@jwz.org>
* Utility function to create a unit sphere in GL.
*
* Permission to use, copy, modify, distribute, and sell this software and its
* Utility function to create a unit sphere in GL.
*
* Permission to use, copy, modify, distribute, and sell this software and its
@@
-24,29
+24,32
@@
# include "config.h"
#endif
# include "config.h"
#endif
-#ifdef HAVE_COCOA
-# include <OpenGL/gl.h>
-#else
+#ifndef HAVE_COCOA
# include <GL/gl.h>
#endif
# include <GL/gl.h>
#endif
+#ifdef HAVE_JWZGLES
+# include "jwzgles.h"
+#endif /* HAVE_JWZGLES */
+
#include "sphere.h"
typedef struct { GLfloat x, y, z; } XYZ;
#include "sphere.h"
typedef struct { GLfloat x, y, z; } XYZ;
-int
-unit_sphere
(int stacks, int slices, int wire
_p)
+
static
int
+unit_sphere
_1 (int stacks, int slices, int wire_p, int half
_p)
{
int polys = 0;
int i,j;
double theta1, theta2, theta3;
XYZ p, n;
{
int polys = 0;
int i,j;
double theta1, theta2, theta3;
XYZ p, n;
- XYZ la = { 0,
0, 0 }, lb = { 0, 0
, 0 };
+ XYZ la = { 0,
-1, 0 }, lb = { 0, -1
, 0 };
XYZ c = {0, 0, 0}; /* center */
double r = 1.0; /* radius */
int stacks2 = stacks * 2;
XYZ c = {0, 0, 0}; /* center */
double r = 1.0; /* radius */
int stacks2 = stacks * 2;
+ int end = (half_p ? stacks/2 : stacks);
- int mode = (wire_p ? GL_LINE_
LOO
P : GL_TRIANGLE_STRIP);
+ int mode = (wire_p ? GL_LINE_
STRI
P : GL_TRIANGLE_STRIP);
int arraysize, out;
struct { XYZ p; XYZ n; GLfloat s, t; } *array;
int arraysize, out;
struct { XYZ p; XYZ n; GLfloat s, t; } *array;
@@
-61,7
+64,6
@@
unit_sphere (int stacks, int slices, int wire_p)
if (! array) abort();
out = 0;
if (! array) abort();
out = 0;
-
if (slices < 4 || stacks < 2 || r <= 0)
{
mode = GL_POINTS;
if (slices < 4 || stacks < 2 || r <= 0)
{
mode = GL_POINTS;
@@
-69,7
+71,7
@@
unit_sphere (int stacks, int slices, int wire_p)
goto END;
}
goto END;
}
- for (j = 0; j <
stacks
; j++)
+ for (j = 0; j <
end
; j++)
{
theta1 = j * (M_PI+M_PI) / stacks2 - M_PI_2;
theta2 = (j + 1) * (M_PI+M_PI) / stacks2 - M_PI_2;
{
theta1 = j * (M_PI+M_PI) / stacks2 - M_PI_2;
theta2 = (j + 1) * (M_PI+M_PI) / stacks2 - M_PI_2;
@@
-78,7
+80,7
@@
unit_sphere (int stacks, int slices, int wire_p)
{
theta3 = i * (M_PI+M_PI) / slices;
{
theta3 = i * (M_PI+M_PI) / slices;
- if (wire_p
&& i != 0
)
+ if (wire_p)
{
array[out++].p = lb; /* vertex */
array[out++].p = la; /* vertex */
{
array[out++].p = lb; /* vertex */
array[out++].p = la; /* vertex */
@@
-135,3
+137,16
@@
unit_sphere (int stacks, int slices, int wire_p)
return polys;
}
return polys;
}
+
+
+int
+unit_sphere (int stacks, int slices, int wire_p)
+{
+ return unit_sphere_1 (stacks, slices, wire_p, 0);
+}
+
+int
+unit_dome (int stacks, int slices, int wire_p)
+{
+ return unit_sphere_1 (stacks, slices, wire_p, 1);
+}