Spatial mirroring

Hi to everyone,



is it possible to mirror a spatial respect to a given axis? I’ve tried scaling by -1, but the normals seems to be inverted.

Any idea?



Bye and thanks in advance,



Alfredo

Invert the normals after scaling? :slight_smile:

I’m trying, but… any hint about the function to use?? :smiley:



Thanks,



Alfredo

if you scale by negative numbers, beware here:

http://hub.jmonkeyengine.org/groups/general-2/forum/topic/negative-scale-params-cause-intersection-with-ray-to-fail-jme3-r7259/

EDIT: I mean, at least collisions with Ray will fail at a Box’s corners… from certain angles

Uhm… thanks for the link, cyuczieekc,

I only want to mirror my object along a given axis, and the easiest and most popular way is to perform a negative scaling.



I someone knows alternative methods or built-in functions let me know :slight_smile:



Bye,



Alfredo

This might be useful:

http://www.blender.org/development/release-logs/blender-234/opengl-normals/

Thanks for the link :slight_smile:

I’ve more or less solved, but I’m encountering still two problems:


  1. In the link the suggestion is to set the orientation of the frontFace with glFrontFace. I’ve implemented this function to swap culling:



    [java]

    public static void swapCulling(Geometry geom){



    Matrix4f worldMatrix = geom.getWorldMatrix();

    Vector3f v1 = new Vector3f(worldMatrix.m00, worldMatrix.m01, worldMatrix.m02);

    Vector3f v2 = new Vector3f(worldMatrix.m10, worldMatrix.m11, worldMatrix.m12);

    Vector3f v3 = new Vector3f(worldMatrix.m20, worldMatrix.m21, worldMatrix.m22);



    Vector3f cross = v1.cross(v2);

    float result = cross.dot(v3);



    geom.getMaterial().getAdditionalRenderState().setFaceCullMode(FaceCullMode.Off);



    if(result > 0)

    GL11.glFrontFace(GL11.GL_CCW);

    else

    GL11.glFrontFace(GL11.GL_CW);



    }

    [/java]



    As you can see is not optimized, since the Culling is disabled. Setting directly GL11.glFrontFace causes a NullPointerExceptions.

    How can I correctly set the front face for a geometry?


  2. The mirrored object often shows a darker color respect to the original one. Sometimes is so dark to appear black (if I englight the object I can see the correct color). Why? This seems to indicate that normals are still bad oriented.



    Any ideas?

    Thanks,



    Alfredo

There’s no need to make the “GL” calls, setting the cull mode to “FaceCullMode.Off” should have the same result.

Some faces appear dark still because jME3 doesn’t support backface lighting, there was a patch posted recently on the forum, but in my opinion its just a hack of sorts.

Perhaps there’s a way in which you can avoid having to mirror your model?

Unfortunately it’s an important feature of my library (I mean the ability of mirroring objects scaling by -1).

I hope that next releases of JME will fix this or include a method for normals swapping :slight_smile:



Bye,

Alfredo