use of com.jme3.math.Quaternion in project jmonkeyengine by jMonkeyEngine.
the class KinematicRagdollControl method ikUpdate.
private void ikUpdate(float tpf) {
TempVars vars = TempVars.get();
Quaternion tmpRot1 = vars.quat1;
Quaternion[] tmpRot2 = new Quaternion[] { vars.quat2, new Quaternion() };
Iterator<String> it = ikTargets.keySet().iterator();
float distance;
Bone bone;
String boneName;
while (it.hasNext()) {
boneName = it.next();
bone = (Bone) boneLinks.get(boneName).bone;
if (!bone.hasUserControl()) {
Logger.getLogger(KinematicRagdollControl.class.getSimpleName()).log(Level.FINE, "{0} doesn't have user control", boneName);
continue;
}
distance = bone.getModelSpacePosition().distance(ikTargets.get(boneName));
if (distance < IKThreshold) {
Logger.getLogger(KinematicRagdollControl.class.getSimpleName()).log(Level.FINE, "Distance is close enough");
continue;
}
int depth = 0;
int maxDepth = ikChainDepth.get(bone.getName());
updateBone(boneLinks.get(bone.getName()), tpf * (float) FastMath.sqrt(distance), vars, tmpRot1, tmpRot2, bone, ikTargets.get(boneName), depth, maxDepth);
Vector3f position = vars.vect1;
for (PhysicsBoneLink link : boneLinks.values()) {
matchPhysicObjectToBone(link, position, tmpRot1);
}
}
vars.release();
}
use of com.jme3.math.Quaternion in project jmonkeyengine by jMonkeyEngine.
the class TestDepthOfField method simpleInitApp.
@Override
public void simpleInitApp() {
Node mainScene = new Node("Main Scene");
rootNode.attachChild(mainScene);
createTerrain(mainScene);
DirectionalLight sun = new DirectionalLight();
sun.setDirection(lightDir);
sun.setColor(ColorRGBA.White.clone().multLocal(1.7f));
mainScene.addLight(sun);
DirectionalLight l = new DirectionalLight();
l.setDirection(Vector3f.UNIT_Y.mult(-1));
l.setColor(ColorRGBA.White.clone().multLocal(0.3f));
mainScene.addLight(l);
flyCam.setMoveSpeed(50);
cam.setFrustumFar(3000);
cam.setLocation(new Vector3f(-700, 100, 300));
cam.setRotation(new Quaternion().fromAngles(new float[] { FastMath.PI * 0.06f, FastMath.PI * 0.65f, 0 }));
Spatial sky = SkyFactory.createSky(assetManager, "Scenes/Beach/FullskiesSunset0068.dds", false);
sky.setLocalScale(350);
mainScene.attachChild(sky);
fpp = new FilterPostProcessor(assetManager);
// fpp.setNumSamples(4);
int numSamples = getContext().getSettings().getSamples();
if (numSamples > 0) {
fpp.setNumSamples(numSamples);
}
dofFilter = new DepthOfFieldFilter();
dofFilter.setFocusDistance(0);
dofFilter.setFocusRange(50);
dofFilter.setBlurScale(1.4f);
fpp.addFilter(dofFilter);
viewPort.addProcessor(fpp);
inputManager.addListener(new ActionListener() {
public void onAction(String name, boolean isPressed, float tpf) {
if (isPressed) {
if (name.equals("toggle")) {
dofFilter.setEnabled(!dofFilter.isEnabled());
}
}
}
}, "toggle");
inputManager.addListener(new AnalogListener() {
public void onAnalog(String name, float value, float tpf) {
if (name.equals("blurScaleUp")) {
dofFilter.setBlurScale(dofFilter.getBlurScale() + 0.01f);
System.out.println("blurScale : " + dofFilter.getBlurScale());
}
if (name.equals("blurScaleDown")) {
dofFilter.setBlurScale(dofFilter.getBlurScale() - 0.01f);
System.out.println("blurScale : " + dofFilter.getBlurScale());
}
if (name.equals("focusRangeUp")) {
dofFilter.setFocusRange(dofFilter.getFocusRange() + 1f);
System.out.println("focusRange : " + dofFilter.getFocusRange());
}
if (name.equals("focusRangeDown")) {
dofFilter.setFocusRange(dofFilter.getFocusRange() - 1f);
System.out.println("focusRange : " + dofFilter.getFocusRange());
}
if (name.equals("focusDistanceUp")) {
dofFilter.setFocusDistance(dofFilter.getFocusDistance() + 1f);
System.out.println("focusDistance : " + dofFilter.getFocusDistance());
}
if (name.equals("focusDistanceDown")) {
dofFilter.setFocusDistance(dofFilter.getFocusDistance() - 1f);
System.out.println("focusDistance : " + dofFilter.getFocusDistance());
}
}
}, "blurScaleUp", "blurScaleDown", "focusRangeUp", "focusRangeDown", "focusDistanceUp", "focusDistanceDown");
inputManager.addMapping("toggle", new KeyTrigger(keyInput.KEY_SPACE));
inputManager.addMapping("blurScaleUp", new KeyTrigger(keyInput.KEY_U));
inputManager.addMapping("blurScaleDown", new KeyTrigger(keyInput.KEY_J));
inputManager.addMapping("focusRangeUp", new KeyTrigger(keyInput.KEY_I));
inputManager.addMapping("focusRangeDown", new KeyTrigger(keyInput.KEY_K));
inputManager.addMapping("focusDistanceUp", new KeyTrigger(keyInput.KEY_O));
inputManager.addMapping("focusDistanceDown", new KeyTrigger(keyInput.KEY_L));
}
use of com.jme3.math.Quaternion in project jmonkeyengine by jMonkeyEngine.
the class TestFog method simpleInitApp.
public void simpleInitApp() {
this.flyCam.setMoveSpeed(50);
Node mainScene = new Node();
cam.setLocation(new Vector3f(-34.74095f, 95.21318f, -287.4945f));
cam.setRotation(new Quaternion(0.023536969f, 0.9361278f, -0.016098259f, -0.35050195f));
// load sky
mainScene.attachChild(SkyFactory.createSky(assetManager, "Textures/Sky/Bright/BrightSky.dds", false));
createTerrain(mainScene);
DirectionalLight sun = new DirectionalLight();
Vector3f lightDir = new Vector3f(-0.37352666f, -0.50444174f, -0.7784704f);
sun.setDirection(lightDir);
sun.setColor(ColorRGBA.White.clone().multLocal(2));
mainScene.addLight(sun);
rootNode.attachChild(mainScene);
fpp = new FilterPostProcessor(assetManager);
//fpp.setNumSamples(4);
int numSamples = getContext().getSettings().getSamples();
if (numSamples > 0) {
fpp.setNumSamples(numSamples);
}
fog = new FogFilter();
fog.setFogColor(new ColorRGBA(0.9f, 0.9f, 0.9f, 1.0f));
fog.setFogDistance(155);
fog.setFogDensity(1.0f);
fpp.addFilter(fog);
viewPort.addProcessor(fpp);
initInputs();
}
use of com.jme3.math.Quaternion in project jmonkeyengine by jMonkeyEngine.
the class TestLightScattering method simpleInitApp.
@Override
public void simpleInitApp() {
// put the camera in a bad position
cam.setLocation(new Vector3f(55.35316f, -0.27061665f, 27.092093f));
cam.setRotation(new Quaternion(0.010414706f, 0.9874893f, 0.13880467f, -0.07409228f));
// cam.setDirection(new Vector3f(0,-0.5f,1.0f));
// cam.setLocation(new Vector3f(0, 300, -500));
//cam.setFrustumFar(1000);
flyCam.setMoveSpeed(10);
Material mat = assetManager.loadMaterial("Textures/Terrain/Rocky/Rocky.j3m");
Spatial scene = assetManager.loadModel("Models/Terrain/Terrain.mesh.xml");
TangentBinormalGenerator.generate(((Geometry) ((Node) scene).getChild(0)).getMesh());
scene.setMaterial(mat);
scene.setShadowMode(ShadowMode.CastAndReceive);
scene.setLocalScale(400);
scene.setLocalTranslation(0, -10, -120);
rootNode.attachChild(scene);
// load sky
rootNode.attachChild(SkyFactory.createSky(assetManager, "Textures/Sky/Bright/FullskiesBlueClear03.dds", false));
DirectionalLight sun = new DirectionalLight();
Vector3f lightDir = new Vector3f(-0.12f, -0.3729129f, 0.74847335f);
sun.setDirection(lightDir);
sun.setColor(ColorRGBA.White.clone().multLocal(2));
scene.addLight(sun);
FilterPostProcessor fpp = new FilterPostProcessor(assetManager);
int numSamples = getContext().getSettings().getSamples();
if (numSamples > 0) {
fpp.setNumSamples(numSamples);
}
Vector3f lightPos = lightDir.multLocal(-3000);
LightScatteringFilter filter = new LightScatteringFilter(lightPos);
LightScatteringUI ui = new LightScatteringUI(inputManager, filter);
fpp.addFilter(filter);
viewPort.addProcessor(fpp);
}
use of com.jme3.math.Quaternion in project jmonkeyengine by jMonkeyEngine.
the class TestMultiRenderTarget method simpleInitApp.
@Override
public void simpleInitApp() {
viewPort.addProcessor(this);
// flyCam.setEnabled(false);
cam.setLocation(new Vector3f(4.8037705f, 4.851632f, 10.789033f));
cam.setRotation(new Quaternion(-0.05143692f, 0.9483723f, -0.21131563f, -0.230846f));
Node tank = (Node) assetManager.loadModel("Models/HoverTank/Tank2.mesh.xml");
//tankMesh.getMaterial().setColor("Specular", ColorRGBA.Black);
rootNode.attachChild(tank);
display1 = new Picture("Picture");
// make it appear behind stats view
display1.move(0, 0, -1);
display2 = (Picture) display1.clone();
display3 = (Picture) display1.clone();
display4 = (Picture) display1.clone();
display = (Picture) display1.clone();
ColorRGBA[] colors = new ColorRGBA[] { ColorRGBA.White, ColorRGBA.Blue, ColorRGBA.Cyan, ColorRGBA.DarkGray, ColorRGBA.Green, ColorRGBA.Magenta, ColorRGBA.Orange, ColorRGBA.Pink, ColorRGBA.Red, ColorRGBA.Yellow };
pls = new PointLight[3];
for (int i = 0; i < pls.length; i++) {
PointLight pl = new PointLight();
pl.setColor(colors[i % colors.length]);
pl.setRadius(5);
display.addLight(pl);
pls[i] = pl;
}
}
Aggregations