Halfextents

Can someone explain what are these halfextents like in CylinderCollisionShape ?



Tnx,

Vertilka

It’s the length from the center of the shape to the outer bound of the shape.

So basically Yhalfextent * 2 = Yextent



The center is assumed to be the mean of all the vertices positions.

isn’t it more developer friendly to give a constructor with width, height and depth instead ?

any way tnx.



V.

Idk, halfextents is pretty wide spread when it comes to shapes or bounding volume.

Yeah, and helps drive the point home that these are extending from 0,0,0 in all directions.

I think the current implementation is the most developer friendly actually.

1 Like
@vertilka said:
isn't it more developer friendly to give a constructor with width, height and depth instead ?
any way tnx.

V.

Even if we used width, height and depth, it would still relate to a half-extent. Using a different way would be silly as this is an unwritten standard and we don't need to muddle things more than they actually are. The terms used throughout the industry should remain the same even if implementations are different.

while we are at it, Quad does use width and height, and doesn’t extend from the center, this seems to be the only exception, any reason for this?

@wezrule said:
while we are at it, Quad does use width and height, and doesn't extend from the center, this seems to be the only exception, any reason for this?

Because all quads usage from all engines are used that way? :P

they are? that sucks :frowning: I would still rather see it be consistent with everything else jME has. Thats why i wondered if there was a special reason it was done this way

@wezrule said:
they are? that sucks :( I would still rather see it be consistent with everything else jME has. Thats why i wondered if there was a special reason it was done this way


Quads work more like you'd expect them to in a UI... which (not ironically) is the majority of the places they are used.

right, for UI purposes it makes a lot of sense to have it like that. Do you think a half extent constructor using a Vector2f would be of use for 3D?

I don’t see the point personally. When you think about a quad you think about whole width / height. Changing that to extents from center when in 3D would just confuse people.



I think it would be better if YOU would just follow how everyone else does it instead. :wink: :stuck_out_tongue:

I’d rather not follow what everyone else does, and think for myself actually :slight_smile: I can see benefits from being able to do it both ways. Everything else extends from the center, or allows mutiple ways of placing the mesh down (Box). So I don’t see why the Quad should be some special exception based purely on what other engines do. We are our own, and can do what we want :slight_smile: And I’m not saying remove the current way, but add the option to do it from the center.

I don’t see it being a big deal, but for what it is worth I agree with wezrule… there is no harm in adding another constructor using extents.



The only thing is it has to be clear what constructor does what and what the difference is etc. How likely is confusion in this case?

For years people have cried about Microsoft disregarding standards and/or making their own based on a widely accepted one. What you are proposing is the same thing.



Quads are 2D planes and as such I find using a center-centric extent approach wrong.



That’s my 2 cents.

I personally agree with @madjack, that’s the only possible approach I can seeplausible for a quad.

ok, to keep everyone happy, can’t disappoint my @madjack :slight_smile: <3. I have made a hybrid solution, which enables modifying the origin of the quad (which other engine/applications also do!), while keeping it in the XY plane. I also fixed some of the comments:



[java]# This patch file was generated by NetBeans IDE

It uses platform neutral UTF-8 encoding and n newlines.

— Base (BASE)

+++ Locally Modified (Based On LOCAL)

@@ -31,14 +31,14 @@

*/

package com.jme3.scene.shape;



+import com.jme3.math.Vector2f;

import com.jme3.scene.Mesh;

import com.jme3.scene.VertexBuffer.Type;



/**

    • <code>Quad</code> represents a rectangular plane in space
    • defined by 4 vertices. The quad’s lower-left side is contained
    • at the local space origin (0, 0, 0), while the upper-right
    • side is located at the width/height coordinates (width, height, 0).
    • <code>Quad</code> represents a rectangular plane in space defined by 4
    • vertices. The quad’s lower-left side is contained at the origin while
    • the upper-right side is located at the width/height from the origin.

      *
  • @author Kirill Vainer

    */

    @@ -46,37 +46,65 @@



    private float width;

    private float height;
  • private Vector2f origin;



    /**
  • /*
  • Serialization only. Do not use.

    */
  • public Quad(){
  • public Quad() {

    }



    /**
  • * Create a quad with the given width and height. The quad<br />
    
  • * is always created in the XY plane.<br />
    
  • * Create a quad with the given width and height. The quad is always created<br />
    
  • * in the XY plane.<br />
    

*

  • @param width The X extent or width
  • * @param height The Y extent or width<br />
    
  • * @param height The Y extent or height<br />
    

*/

  • public Quad(float width, float height){
  •    updateGeometry(width, height);<br />
    
  • public Quad(float width, float height) {
  •    updateGeometry(Vector2f.ZERO, width, height);<br />
    

}



/**

  • * Create a quad with the given width and height. The quad<br />
    
  • * is always created in the XY plane.<br />
    
  • * Create a quad with the given width and height. The quad is always created<br />
    
  • * in the XY plane.<br />
    

*

  • @param width The X extent or width
  • * @param height The Y extent or width<br />
    
  • * @param flipCoords If true, the texture coordinates will be flipped<br />
    
  • * along the Y axis.<br />
    
  • * @param height The Y extent or height<br />
    
  • * @param flipCoords If true, the texture coordinates will be flipped along<br />
    
  • * the Y axis.<br />
    

*/

  • public Quad(float width, float height, boolean flipCoords){
  •    updateGeometry(width, height, flipCoords);<br />
    
  • public Quad(float width, float height, boolean flipCoords) {
  •    updateGeometry(Vector2f.ZERO, width, height, flipCoords);<br />
    

}


  • /**
  • * Create a quad with the given width and height. The quad is always created<br />
    
  • * in the XY plane.<br />
    
  • *<br />
    
  • * @param origin The origin of the quad<br />
    
  • * @param width The X extent or width<br />
    
  • * @param height The Y extent or height<br />
    
  • */<br />
    
  • public Quad(Vector2f origin, float width, float height) {
  •    updateGeometry(origin, width, height);<br />
    
  • }

    +
  • /**
  • * Create a quad with the given width and height. The quad is always created<br />
    
  • * in the XY plane.<br />
    
  • *<br />
    
  • * @param origin The origin of the quad<br />
    
  • * @param width The X extent or width<br />
    
  • * @param height The Y extent or height<br />
    
  • * @param flipCoords If true, the texture coordinates will be flipped along<br />
    
  • * the Y axis.<br />
    
  • */<br />
    
  • public Quad(Vector2f origin, float width, float height, boolean flipCoords) {
  •    updateGeometry(origin, width, height, flipCoords);<br />
    
  • }

    +

    public float getHeight() {

    return height;

    }

    @@ -85,26 +113,30 @@

    return width;

    }


  • public void updateGeometry(float width, float height){
  •    updateGeometry(width, height, false);<br />
    
  • public Vector2f getOrigin() {
  •    return origin;<br />
    

}


  • public void updateGeometry(float width, float height, boolean flipCoords) {
  • public void updateGeometry(Vector2f origin, float width, float height) {
  •    updateGeometry(origin, width, height, false);<br />
    
  • }

    +
  • public void updateGeometry(Vector2f origin, float width, float height, boolean flipCoords) {
  •    this.origin = origin;<br />
    

this.width = width;

this.height = height;

  •    setBuffer(Type.Position, 3, new float[]{0,      0,      0,<br />
    
  •                                            width,  0,      0,<br />
    
  •                                            width,  height, 0,<br />
    
  •                                            0,      height, 0<br />
    
  •                                            });<br />
    

+ setBuffer(Type.Position, 3, new float[]{origin.x, origin.y, 0,
+ origin.x + width, origin.y, 0,
+ origin.x + width, origin.y + height, 0,
+ origin.x, origin.y + height, 0});

- if (flipCoords){
+ if (flipCoords) {
setBuffer(Type.TexCoord, 2, new float[]{0, 1,
1, 1,
1, 0,
0, 0});
- }else{
+ } else {
setBuffer(Type.TexCoord, 2, new float[]{0, 0,
1, 0,
1, 1,
@@ -114,16 +146,14 @@
0, 0, 1,
0, 0, 1,
0, 0, 1});
- if (height < 0){
+ if (height < 0) {
setBuffer(Type.Index, 3, new short[]{0, 2, 1,
0, 3, 2});
- }else{
+ } else {
setBuffer(Type.Index, 3, new short[]{0, 1, 2,
0, 2, 3});
}

updateBound();
}
-
-
}
[/java]

A Vec2 is used to make the user aware there is no Z axis modifying. As Kirill (@momoko_fan) was the original author of this, I think he should decide whether it goes in or not

For those of you who want to create a center based quad, with x/y half extents, then you can do like this (provided this gets accepted ofc).
[java]Vector2f center = new Vector2f(0, 0);
float xHalfExtent = 2.5f;
float yHalfExtent = 2.5f;
Quad quad = new Quad(center.subtract(xHalfExtent, yHalfExtent), xHalfExtent * 2, yHalfExtent * 2);[/java]

Last time I post on this “issue”.



I’m not the decider or anything, but this is unnecessary and unneeded. It adds nothing to the class or the functionality of the class and it goes against every engine that uses quads. The only thing this succeeds at is indulge @wezrule temper tantrum.



I might add that using a Vector2f is a bad idea. If it should be implemented, it should use a Vector3f as a quad can and is sometimes used in a 3D scene. Billboards are a great example of that.

Hmm madjack you seem to be on your period lately, thought u were cooler than this :frowning:


goes against every engine that uses quads. The only thing this succeeds at is indulge @wezrule temper tantrum.


And now i had to waste time writing this, when i've only got good intent... :( thx for that :/. As i stated earlier, other engines/applications do allow setting of quad origins/and-or extending from the center, to name a few...:

XNA - http://msdn.microsoft.com/en-us/library/bb464051(v=xnagamestudio.10).aspx
[java]public Quad( Vector3 origin, Vector3 normal, Vector3 up, float width, float height )[/java]

QtQuick3d - http://doc.qt.digia.com/qt-quick3d-snapshot/qglbuilder.html#addPane-2
function to create a quad centered on the origin, lying in the Z=0 plane, with width (x dimension) and height (y dimension) specified by size.
[java]void QGLBuilder::addPane ( QSizeF size )[/java]

Everyone I could find documentation for (wasn't a lot ^_^, its hard to find!!), did it... they don't just force you start from (0, 0).... And actually extend it to let you have it in any orientation as well...

Unity - http://docs.unity3d.com/Documentation/ScriptReference/Plane.Plane.html
The resulting plane goes through the given three points. The points go around clockwise as you look down on the top surface of the plane.
[java]Unity : static function Plane (inNormal : Vector3, inPoint : Vector3) : Plane[/java]
( ^ although they piece together many quads to make it)
@madjack said:
I might add that using a Vector2f is a bad idea. If it should be implemented, it should use a Vector3f as a quad can and is sometimes used in a 3D scene. Billboards are a great example of that.


The Vector2f was to make u happy...
@madjack said:
Quads are 2D planes