Point Sprites

A forum for discussing development work on the Ardor3D core systems. Basically, anything that is in the ardor3d-core, math or savable modules.
Forum rules
Developer discussions only. Newbie questions belong in the HELP! forum. This is a forum for discussing development work on the Ardor3D core systems. Basically, anything that is in the ardor3d-core, math or savable modules.

Re: Point Sprites

Postby renanse » Tue Nov 02, 2010 8:08 pm

obi, the modifications to Point appear to be missing from the patch?
Gratitude is a mark of a noble soul and a refined character.
User avatar
renanse
Site Admin
 
Posts: 2955
Joined: Tue Oct 28, 2008 6:49 pm
Location: Austin, TX

Re: Point Sprites

Postby obi » Tue Nov 02, 2010 8:19 pm

woot! How did that happen. Wierd.

Code: Select all
### Eclipse Workspace Patch 1.0
#P ardor3d-core
Index: src/main/java/com/ardor3d/scenegraph/Point.java
===================================================================
--- src/main/java/com/ardor3d/scenegraph/Point.java   (revision 1439)
+++ src/main/java/com/ardor3d/scenegraph/Point.java   (working copy)
@@ -23,19 +23,42 @@
import com.ardor3d.util.geom.BufferUtils;

/**
- * <code>Point</code> defines a collection of vertices that are rendered as single points.
+ * <code>Point</code> defines a collection of vertices that are rendered as single points or textured sprites depending
+ * on PointType.
  */
public class Point extends Mesh {

     private static final long serialVersionUID = 1L;

+    public enum PointType {
+        Point, PointSprite;
+    };
+
+    private PointType _pointType;
+
     private float _pointSize = 1.0f;
     private boolean _antialiased = false;

+    /**
+     * Distance Attenuation fields.
+     */
+    // XXX: LWJGL requires 4 floats, but only 3 coefficients are mentioned in the specification?
+    // JOGL works fine with 3.
+    private FloatBuffer _attenuationCoefficients = BufferUtils
+            .createFloatBuffer(new float[] { 0.0f, 0f, 0.000004f, 0f });
+    private float _minPointSize = 1.0f;
+    private float _maxPointSize = 64.0f;
+    private boolean _useDistanceAttenuation = false;
+
     public Point() {
         this("point", null, null, null, (FloatBufferData) null);
     }

+    public Point(final PointType type) {
+        this();
+        _pointType = type;
+    }
+
     /**
      * Constructor instantiates a new <code>Point</code> object with a given set of data. Any data may be null, except
      * the vertex array. If this is null an exception is thrown.
@@ -97,7 +120,48 @@
         _meshData.setTextureCoords(coords, 0);
     }

+    public boolean isPointSprite() {
+        return _pointType == PointType.PointSprite;
+    }
+
     /**
+     * Default attenuation coefficient is calculated to work best with pointSize = 1.
+     *
+     * @param bool
+     */
+    public void enableDistanceAttenuation(final boolean bool) {
+        _useDistanceAttenuation = bool;
+    }
+
+    /**
+     * Distance Attenuation Equation:<br>
+     * x = distance from the eye<br>
+     * Derived Size = clamp( pointSize * sqrt( attenuation(x) ) )<br>
+     * attenuation(x) = 1 / (a + b*x + c*x^2)
+     * <p>
+     * Default coefficients used are(they should work best with pointSize=1):<br>
+     * a = 0, b = 0, c = 0.000004f<br>
+     * This should give(without taking regards to the max,min pointSize clamping):<br>
+     * 1. A size of 1 pixel at distance of 500 units.<br>
+     * Derived Size = 1/(0.000004*500^2) = 1<br>
+     * 2. A size of 25 pixel at distance of 100 units.<br>
+     * 3. A size of 2500 at a distance of 10 units.<br>
+     *
+     * @see <a href="http://www.opengl.org/registry/specs/ARB/point_parameters.txt">OpenGL specification</a>
+     * @param a
+     *            constant term in the attenuation equation
+     * @param b
+     *            linear term in the attenuation equation
+     * @param c
+     *            quadratic term in the attenuation equation
+     */
+    public void setDistanceAttenuationCoefficients(final float a, final float b, final float c) {
+        _attenuationCoefficients.put(0, a);
+        _attenuationCoefficients.put(1, b);
+        _attenuationCoefficients.put(2, c);
+    }
+
+    /**
      * @return true if points are to be drawn antialiased
      */
     public boolean isAntialiased() {
@@ -116,6 +180,14 @@
         _antialiased = antialiased;
     }

+    public PointType getPointType() {
+        return _pointType;
+    }
+
+    public void setPointType(final PointType pointType) {
+        _pointType = pointType;
+    }
+
     /**
      * @return the pixel size of each point.
      */
@@ -135,6 +207,42 @@
     }

     /**
+     * When DistanceAttenuation is enabled, the points maximum size will get clamped to this value.
+     *
+     * @param maxSize
+     */
+    public void setMaxPointSize(final float maxSize) {
+        _maxPointSize = maxSize;
+    }
+
+    /**
+     * When DistanceAttenuation is enabled, the points maximum size will get clamped to this value.
+     *
+     * @param maxSize
+     */
+    public float getMaxPointSize() {
+        return _maxPointSize;
+    }
+
+    /**
+     * When DistanceAttenuation is enabled, the points minimum size will get clamped to this value.
+     *
+     * @param maxSize
+     */
+    public void setMinPointSize(final float minSize) {
+        _minPointSize = minSize;
+    }
+
+    /**
+     * When DistanceAttenuation is enabled, the points minimum size will get clamped to this value.
+     *
+     * @param maxSize
+     */
+    public float getMinPointSize() {
+        return _minPointSize;
+    }
+
+    /**
      * Used with Serialization. Do not call this directly.
      *
      * @param s
@@ -162,6 +270,12 @@
         super.write(capsule);
         capsule.write(_pointSize, "pointSize", 1);
         capsule.write(_antialiased, "antialiased", false);
+        capsule.write(_pointType, "pointType", PointType.Point);
+        capsule.write(_useDistanceAttenuation, "useDistanceAttenuation", false);
+        capsule.write(_attenuationCoefficients, "attenuationCoefficients", BufferUtils.createFloatBuffer(new float[] {
+                0.0f, 0f, 0.000004f, 0f }));
+        capsule.write(_minPointSize, "minPointSize", 1);
+        capsule.write(_maxPointSize, "maxPointSize", 64);
     }

     @Override
@@ -169,13 +283,21 @@
         super.read(capsule);
         _pointSize = capsule.readFloat("pointSize", 1);
         _antialiased = capsule.readBoolean("antialiased", false);
+        _pointType = capsule.readEnum("pointType", PointType.class, PointType.Point);
+        _useDistanceAttenuation = capsule.readBoolean("useDistanceAttenuation", false);
+        _attenuationCoefficients = capsule.readFloatBuffer("attenuationCoefficients", BufferUtils
+                .createFloatBuffer(new float[] { 0.0f, 0f, 0.000004f, 0f }));
+        _minPointSize = capsule.readFloat("minPointSize", 1);
+        _maxPointSize = capsule.readFloat("maxPointSize", 64);
+
     }

     @Override
     public void render(final Renderer renderer) {
-        renderer.setupPointParameters(getPointSize(), isAntialiased());

+        renderer.setupPointParameters(_pointSize, isAntialiased(), isPointSprite(), _useDistanceAttenuation,
+                _attenuationCoefficients, _minPointSize, _maxPointSize);
+
         super.render(renderer);
     }
-
}
obi
regular
 
Posts: 317
Joined: Thu Sep 24, 2009 8:06 pm

Re: Point Sprites

Postby renanse » Tue Nov 02, 2010 8:36 pm

Thanks! Will be in shortly.
Gratitude is a mark of a noble soul and a refined character.
User avatar
renanse
Site Admin
 
Posts: 2955
Joined: Tue Oct 28, 2008 6:49 pm
Location: Austin, TX

Re: Point Sprites

Postby renanse » Tue Nov 02, 2010 9:44 pm

fuchs wrote:The Thumbnail images for both the PointCubeExample and the WireframeGeometryShaderExample appear to be missing in SVN.


Just an fyi that I've taken care of this and any other missing thumbnails / descriptions where I could find them. Let me know if you come across any more.
Gratitude is a mark of a noble soul and a refined character.
User avatar
renanse
Site Admin
 
Posts: 2955
Joined: Tue Oct 28, 2008 6:49 pm
Location: Austin, TX

Previous

Return to Core Development Discussions

Who is online

Users browsing this forum: No registered users and 1 guest

cron