use of com.jme3.math.Transform in project jmonkeyengine by jMonkeyEngine.
the class CompoundCollisionShape method addChildShape.
/**
* adds a child shape at the given local translation
* @param shape the child shape to add
* @param location the local location of the child shape
*/
public void addChildShape(CollisionShape shape, Vector3f location) {
Transform transA = new Transform(Converter.convert(new Matrix3f()));
Converter.convert(location, transA.origin);
children.add(new ChildCollisionShape(location.clone(), new Matrix3f(), shape));
((CompoundShape) cShape).addChildShape(transA, shape.getCShape());
}
use of com.jme3.math.Transform in project jmonkeyengine by jMonkeyEngine.
the class CollisionShapeFactory method createSingleMeshShape.
/**
* This type of collision shape is mesh-accurate and meant for immovable "world objects".
* Examples include terrain, houses or whole shooter levels.<br>
* Objects with "mesh" type collision shape will not collide with each other.
*/
private static MeshCollisionShape createSingleMeshShape(Geometry geom, Spatial parent) {
Mesh mesh = geom.getMesh();
Transform trans = getTransform(geom, parent);
if (mesh != null && mesh.getMode() == Mesh.Mode.Triangles) {
MeshCollisionShape mColl = new MeshCollisionShape(mesh);
mColl.setScale(trans.getScale());
return mColl;
} else {
return null;
}
}
use of com.jme3.math.Transform in project jmonkeyengine by jMonkeyEngine.
the class CollisionShapeFactory method createSingleDynamicMeshShape.
/**
* This method creates a hull collision shape for the given mesh.<br>
*/
private static HullCollisionShape createSingleDynamicMeshShape(Geometry geom, Spatial parent) {
Mesh mesh = geom.getMesh();
Transform trans = getTransform(geom, parent);
if (mesh != null) {
HullCollisionShape dynamicShape = new HullCollisionShape(mesh);
dynamicShape.setScale(trans.getScale());
return dynamicShape;
} else {
return null;
}
}
use of com.jme3.math.Transform in project jmonkeyengine by jMonkeyEngine.
the class TestTexture3D method simpleInitApp.
@Override
public void simpleInitApp() {
//mouseInput.setCursorVisible(true);
flyCam.setMoveSpeed(10);
//creating a sphere
Sphere sphere = new Sphere(32, 32, 1);
//getting the boundingbox
sphere.updateBound();
BoundingBox bb = (BoundingBox) sphere.getBound();
Vector3f min = bb.getMin(null);
float[] ext = new float[] { bb.getXExtent() * 2, bb.getYExtent() * 2, bb.getZExtent() * 2 };
//we need to change the UV coordinates (the sphere is assumet to be inside the 3D image box)
sphere.clearBuffer(Type.TexCoord);
VertexBuffer vb = sphere.getBuffer(Type.Position);
FloatBuffer fb = (FloatBuffer) vb.getData();
float[] uvCoordinates = BufferUtils.getFloatArray(fb);
//now transform the coordinates so that they are in the range of <0; 1>
for (int i = 0; i < uvCoordinates.length; i += 3) {
uvCoordinates[i] = (uvCoordinates[i] - min.x) / ext[0];
uvCoordinates[i + 1] = (uvCoordinates[i + 1] - min.y) / ext[1];
uvCoordinates[i + 2] = (uvCoordinates[i + 2] - min.z) / ext[2];
}
//apply new texture coordinates
VertexBuffer uvCoordsBuffer = new VertexBuffer(Type.TexCoord);
uvCoordsBuffer.setupData(Usage.Static, 3, com.jme3.scene.VertexBuffer.Format.Float, BufferUtils.createFloatBuffer(uvCoordinates));
sphere.setBuffer(uvCoordsBuffer);
//create geometry, and apply material and our 3D texture
Geometry g = new Geometry("sphere", sphere);
Material material = new Material(assetManager, "jme3test/texture/tex3D.j3md");
try {
Texture texture = this.getTexture();
material.setTexture("Texture", texture);
} catch (IOException e) {
e.printStackTrace();
}
g.setMaterial(material);
rootNode.attachChild(g);
//add some light so that it is visible
PointLight light = new PointLight();
light.setColor(ColorRGBA.White);
light.setPosition(new Vector3f(5, 5, 5));
light.setRadius(20);
rootNode.addLight(light);
light = new PointLight();
light.setColor(ColorRGBA.White);
light.setPosition(new Vector3f(-5, -5, -5));
light.setRadius(20);
rootNode.addLight(light);
}
use of com.jme3.math.Transform in project jmonkeyengine by jMonkeyEngine.
the class EnvMapUtils method getVectorFromCubemapFaceTexCoord.
/**
*
* Computes the 3 component vector coordinates for the given face and coords
*
* @param x the x texture coordinate
* @param y the y texture coordinate
* @param mapSize the size of a face of the cube map
* @param face the face to consider
* @param store a vector3f where the resulting vector will be stored
* @param fixSeamsMethod the method to fix the seams
* @return
*/
public static Vector3f getVectorFromCubemapFaceTexCoord(int x, int y, int mapSize, int face, Vector3f store, FixSeamsMethod fixSeamsMethod) {
if (store == null) {
store = new Vector3f();
}
float u;
float v;
if (fixSeamsMethod == FixSeamsMethod.Stretch) {
/* Code from Nvtt : http://code.google.com/p/nvidia-texture-tools/source/browse/trunk/src/nvtt/CubeSurface.cpp
* transform from [0..res - 1] to [-1 .. 1], match up edges exactly. */
u = (2.0f * (float) x / ((float) mapSize - 1.0f)) - 1.0f;
v = (2.0f * (float) y / ((float) mapSize - 1.0f)) - 1.0f;
} else {
//Done if any other fix method or no fix method is set
/* transform from [0..res - 1] to [- (1 - 1 / res) .. (1 - 1 / res)]
* (+ 0.5f is for texel center addressing) */
u = (2.0f * ((float) x + 0.5f) / (float) (mapSize)) - 1.0f;
v = (2.0f * ((float) y + 0.5f) / (float) (mapSize)) - 1.0f;
}
if (fixSeamsMethod == FixSeamsMethod.Wrap) {
// Warp texel centers in the proximity of the edges.
float a = pow((float) mapSize, 2.0f) / pow(((float) mapSize - 1f), 3.0f);
u = a * pow(u, 3f) + u;
v = a * pow(v, 3f) + v;
}
// Code from Nvtt : http://code.google.com/p/nvidia-texture-tools/source/browse/trunk/src/nvtt/CubeSurface.cpp
switch(face) {
case 0:
store.set(1f, -v, -u);
break;
case 1:
store.set(-1f, -v, u);
break;
case 2:
store.set(u, 1f, v);
break;
case 3:
store.set(u, -1f, -v);
break;
case 4:
store.set(u, -v, 1f);
break;
case 5:
store.set(-u, -v, -1.0f);
break;
}
return store.normalizeLocal();
}
Aggregations