use of com.jme3.math.Quaternion in project jmonkeyengine by jMonkeyEngine.
the class VehicleWheel method applyWheelTransform.
public void applyWheelTransform() {
if (wheelSpatial == null) {
return;
}
Quaternion localRotationQuat = wheelSpatial.getLocalRotation();
Vector3f localLocation = wheelSpatial.getLocalTranslation();
if (!applyLocal && wheelSpatial.getParent() != null) {
localLocation.set(wheelWorldLocation).subtractLocal(wheelSpatial.getParent().getWorldTranslation());
localLocation.divideLocal(wheelSpatial.getParent().getWorldScale());
tmp_inverseWorldRotation.set(wheelSpatial.getParent().getWorldRotation()).inverseLocal().multLocal(localLocation);
localRotationQuat.set(wheelWorldRotation);
tmp_inverseWorldRotation.set(wheelSpatial.getParent().getWorldRotation()).inverseLocal().mult(localRotationQuat, localRotationQuat);
wheelSpatial.setLocalTranslation(localLocation);
wheelSpatial.setLocalRotation(localRotationQuat);
} else {
wheelSpatial.setLocalTranslation(wheelWorldLocation);
wheelSpatial.setLocalRotation(wheelWorldRotation);
}
}
use of com.jme3.math.Quaternion in project jmonkeyengine by jMonkeyEngine.
the class AbstractPhysicsControl method applyPhysicsTransform.
/**
* Applies a physics transform to the spatial
*
* @param worldLocation
* @param worldRotation
*/
protected void applyPhysicsTransform(Vector3f worldLocation, Quaternion worldRotation) {
if (enabled && spatial != null) {
Vector3f localLocation = spatial.getLocalTranslation();
Quaternion localRotationQuat = spatial.getLocalRotation();
if (!applyLocal && spatial.getParent() != null) {
localLocation.set(worldLocation).subtractLocal(spatial.getParent().getWorldTranslation());
localLocation.divideLocal(spatial.getParent().getWorldScale());
tmp_inverseWorldRotation.set(spatial.getParent().getWorldRotation()).inverseLocal().multLocal(localLocation);
localRotationQuat.set(worldRotation);
tmp_inverseWorldRotation.set(spatial.getParent().getWorldRotation()).inverseLocal().mult(localRotationQuat, localRotationQuat);
spatial.setLocalTranslation(localLocation);
spatial.setLocalRotation(localRotationQuat);
} else {
spatial.setLocalTranslation(worldLocation);
spatial.setLocalRotation(worldRotation);
}
}
}
use of com.jme3.math.Quaternion in project jmonkeyengine by jMonkeyEngine.
the class EnvMapUtils method getCubeMapCrossDebugViewWithMipMaps.
public static Node getCubeMapCrossDebugViewWithMipMaps(TextureCubeMap cubeMap, AssetManager assetManager) {
Node n = new Node("CubeMapDebug" + cubeMap.getName());
int size = cubeMap.getImage().getWidth();
int nbMips = cubeMap.getImage().getMipMapSizes().length;
Picture[] pics = new Picture[6 * nbMips];
// 128f / (float) size;
float ratio = 1f;
int offset = 0;
int guiOffset = 0;
for (int mipLevel = 0; mipLevel < nbMips; mipLevel++) {
size = Math.max(1, cubeMap.getImage().getWidth() >> mipLevel);
int dataSize = cubeMap.getImage().getMipMapSizes()[mipLevel];
byte[] dataArray = new byte[dataSize];
for (int i = 0; i < 6; i++) {
ByteBuffer bb = cubeMap.getImage().getData(i);
bb.rewind();
bb.position(offset);
bb.get(dataArray, 0, dataSize);
ByteBuffer data = BufferUtils.createByteBuffer(dataArray);
pics[i] = new Picture("bla");
Texture2D tex = new Texture2D(new Image(cubeMap.getImage().getFormat(), size, size, data, cubeMap.getImage().getColorSpace()));
pics[i].setTexture(assetManager, tex, true);
pics[i].setWidth(size);
pics[i].setHeight(size);
n.attachChild(pics[i]);
}
pics[0].setLocalTranslation(guiOffset + size, guiOffset + size * 2, 1);
pics[0].setLocalRotation(new Quaternion().fromAngleAxis(PI, Vector3f.UNIT_Z));
pics[1].setLocalTranslation(guiOffset + size * 3, guiOffset + size * 2, 1);
pics[1].setLocalRotation(new Quaternion().fromAngleAxis(PI, Vector3f.UNIT_Z));
pics[2].setLocalTranslation(guiOffset + size * 2, guiOffset + size * 3, 1);
pics[2].setLocalRotation(new Quaternion().fromAngleAxis(PI, Vector3f.UNIT_Z));
pics[3].setLocalTranslation(guiOffset + size * 2, guiOffset + size, 1);
pics[3].setLocalRotation(new Quaternion().fromAngleAxis(PI, Vector3f.UNIT_Z));
pics[4].setLocalTranslation(guiOffset + size * 2, guiOffset + size * 2, 1);
pics[4].setLocalRotation(new Quaternion().fromAngleAxis(PI, Vector3f.UNIT_Z));
pics[5].setLocalTranslation(guiOffset + size * 4, guiOffset + size * 2, 1);
pics[5].setLocalRotation(new Quaternion().fromAngleAxis(PI, Vector3f.UNIT_Z));
guiOffset += size * 2 + 1;
offset += dataSize;
}
Quad q = new Quad(cubeMap.getImage().getWidth() * 4 + nbMips, guiOffset + size);
Geometry g = new Geometry("bg", q);
Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
mat.setColor("Color", ColorRGBA.Black);
g.setMaterial(mat);
g.setLocalTranslation(0, 0, 0);
n.attachChild(g);
n.setLocalScale(ratio);
return n;
}
use of com.jme3.math.Quaternion in project jmonkeyengine by jMonkeyEngine.
the class MotionEvent method read.
@Override
public void read(JmeImporter im) throws IOException {
super.read(im);
InputCapsule in = im.getCapsule(this);
lookAt = (Vector3f) in.readSavable("lookAt", null);
upVector = (Vector3f) in.readSavable("upVector", Vector3f.UNIT_Y);
rotation = (Quaternion) in.readSavable("rotation", null);
directionType = in.readEnum("directionType", Direction.class, Direction.None);
path = (MotionPath) in.readSavable("path", null);
spatial = (Spatial) in.readSavable("spatial", null);
}
use of com.jme3.math.Quaternion in project jmonkeyengine by jMonkeyEngine.
the class TestBatchNodeCluster method simpleInitApp.
//protected
// protected Geometry player;
@Override
public void simpleInitApp() {
timer = new NanoTimer();
batchNode = new SimpleBatchNode("BatchNode");
xPosition.add(0);
yPosition.add(0);
zPosition.add(0);
mat1 = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
mat1.setColor("Color", ColorRGBA.White);
mat1.setColor("GlowColor", ColorRGBA.Blue.mult(10));
mat2 = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
mat2.setColor("Color", ColorRGBA.White);
mat2.setColor("GlowColor", ColorRGBA.Red.mult(10));
mat3 = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
mat3.setColor("Color", ColorRGBA.White);
mat3.setColor("GlowColor", ColorRGBA.Yellow.mult(10));
mat4 = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
mat4.setColor("Color", ColorRGBA.White);
mat4.setColor("GlowColor", ColorRGBA.Orange.mult(10));
randomGenerator();
//rootNode.attachChild(SkyFactory.createSky(
// assetManager, "Textures/SKY02.zip", false));
inputManager.addMapping("Start Game", new KeyTrigger(KeyInput.KEY_J));
inputManager.addListener(al, new String[] { "Start Game" });
cam.setLocation(new Vector3f(-34.403286f, 126.65158f, 434.791f));
cam.setRotation(new Quaternion(0.022630932f, 0.9749435f, -0.18736298f, 0.11776358f));
batchNode.batch();
terrain = new Node("terrain");
terrain.setLocalTranslation(50, 0, 50);
terrain.attachChild(batchNode);
flyCam.setMoveSpeed(100);
rootNode.attachChild(terrain);
Vector3f pos = new Vector3f(-40, 0, -40);
batchNode.setLocalTranslation(pos);
Arrow a = new Arrow(new Vector3f(0, 50, 0));
Geometry g = new Geometry("a", a);
g.setLocalTranslation(terrain.getLocalTranslation());
Material m = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
m.setColor("Color", ColorRGBA.Blue);
g.setMaterial(m);
FilterPostProcessor fpp = new FilterPostProcessor(assetManager);
fpp.addFilter(new BloomFilter(BloomFilter.GlowMode.Objects));
// SSAOFilter ssao = new SSAOFilter(8.630104f,22.970434f,2.9299977f,0.2999997f);
// fpp.addFilter(ssao);
viewPort.addProcessor(fpp);
// viewPort.setBackgroundColor(ColorRGBA.DarkGray);
}
Aggregations