浏览代码

Merge pull request #763 from stephengold/master

fix issue #762 (WireSphere generates parallels with wrong radii)
Stephen Gold 7 年之前
父节点
当前提交
47a46a8250
共有 1 个文件被更改,包括 11 次插入9 次删除
  1. 11 9
      jme3-core/src/main/java/com/jme3/scene/debug/WireSphere.java

+ 11 - 9
jme3-core/src/main/java/com/jme3/scene/debug/WireSphere.java

@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2009-2012 jMonkeyEngine
+ * Copyright (c) 2009-2017 jMonkeyEngine
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -106,6 +106,9 @@ public class WireSphere extends Mesh {
 //        pb.put(0).put(0).put(radius);
 //        pb.put(0).put(0).put(-radius);
 
+        /*
+         * Update vertex positions for the great circle in the X-Y plane.
+         */
         float rate = FastMath.TWO_PI / (float) samples;
         float angle = 0;
         for (int i = 0; i < samples; i++) {
@@ -114,7 +117,9 @@ public class WireSphere extends Mesh {
             pb.put(x).put(y).put(0);
             angle += rate;
         }
-
+        /*
+         * Update vertex positions for the great circle in the Y-Z plane.
+         */
         angle = 0;
         for (int i = 0; i < samples; i++) {
             float x = radius * FastMath.cos(angle);
@@ -122,23 +127,20 @@ public class WireSphere extends Mesh {
             pb.put(0).put(x).put(y);
             angle += rate;
         }
-
+        /*
+         * Update vertex positions for 'zSamples' parallel circles.
+         */
         float zRate = (radius * 2) / (float) (zSamples);
         float zHeight = -radius + (zRate / 2f);
-
-
         float rb = 1f / zSamples;
         float b = rb / 2f;
-
         for (int k = 0; k < zSamples; k++) {
             angle = 0;
-            float scale = FastMath.sin(b * FastMath.PI);
+            float scale = 2f * FastMath.sqrt(b - b * b);
             for (int i = 0; i < samples; i++) {
                 float x = radius * FastMath.cos(angle);
                 float y = radius * FastMath.sin(angle);
-
                 pb.put(x * scale).put(zHeight).put(y * scale);
-
                 angle += rate;
             }
             zHeight += zRate;