From 3328f2a3a7b9f4bde9a9057ceba236acfff3bc9f Mon Sep 17 00:00:00 2001 From: Stephen Gold Date: Sat, 4 Nov 2017 16:54:50 -0700 Subject: [PATCH] fix issue #762 (WireSphere generates parallels with wrong radii) --- .../java/com/jme3/scene/debug/WireSphere.java | 20 ++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/jme3-core/src/main/java/com/jme3/scene/debug/WireSphere.java b/jme3-core/src/main/java/com/jme3/scene/debug/WireSphere.java index 04338eac6..cf0244355 100644 --- a/jme3-core/src/main/java/com/jme3/scene/debug/WireSphere.java +++ b/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;