When i scale a model, the localtranslations in that model doesn't scale within the model. So when i scale the vehicle model in the flagrushtutorial 1000 times, the localtranslation of the frontwheel is still the same localtranslation as I didn't scale it.
hmm i'm not sure what you mean.
the flagrush vehicle gets scaled to 0.0025f initially.
if you set the scale 10 times more or less, the model still looks the same.
you have to adjust the ChaseCam of course to view the whole model if you scale the model up too much.
i tried to get the local translation of the frontwheel.
but that hadn't been downscaled with the complete model.
so it looks like the frontwheel is still far away of the vehicle
quick example made just look to the logs:
package jmetest.flagrushtut.lesson10.scenemonitor;
import java.io.IOException;
import java.net.URL;
import java.util.logging.Logger;
import jmetest.flagrushtut.lesson10.Lesson10;
import jmetest.renderer.loader.TestObjJmeWrite;
import com.jme.app.SimpleGame;
import com.jme.bounding.BoundingBox;
import com.jme.math.Vector3f;
import com.jme.scene.Node;
import com.jme.scene.Spatial;
import com.jme.util.export.binary.BinaryImporter;
public class between extends SimpleGame{
private static final Logger logger = Logger.getLogger(TestObjJmeWrite.class
.getName());
Spatial frontwheel, backwheel;
public static void main(String[] args) {
between app=new between();
app.setConfigShowMode(ConfigShowMode.AlwaysShow);
app.start();
}
protected void simpleInitGame() {
Spatial model = null;
try {
URL bikeFile = Lesson10.class.getClassLoader().getResource("jmetest/data/model/bike.jme");
BinaryImporter importer = new BinaryImporter();
model = (Spatial)importer.load(bikeFile.openStream());
model.setModelBound(new BoundingBox());
model.updateModelBound();
//scale it to be MUCH smaller than it is originally
model.setLocalScale(.0025f);
} catch (IOException e) {
logger
.throwing(this.getClass().toString(), "buildPlayer()",
e);
}
rootNode.attachChild(model);
logger.info("the localtranslation before scaling: "+((Node)model).getChild("frontwheel").getLocalTranslation().toString());
rootNode.detachChild(model);
model.setLocalScale(0.0025f);
rootNode.attachChild(model);
logger.info("the localtranslation after scaling: " +((Node)model).getChild("frontwheel").getLocalTranslation().toString());
}
}
i guess the localTranslation of the child nodes will always be the same regardless of the scale of the base node (the model).
The Scale just modifies the worldTranslation/scale of the child nodes to render them properly.
What do you need the localTranslation of the wheel for?
well i need to have the height of the wheel
model.setLocalScale(.0025f);
snip
model.setLocalScale(0.0025f);
Is the same scale? Dont think that this resizes this to a 0.0025 * 0.0025 ?
Snare
maybe you can get the yExtend of its bounding Box.
that should be half if its heigth.
snareoj2: its the same
no becuase else i would need to add the particle effect to the frontwheel and one on the backwheel too
If you want the particle effect at both wheel you need 2 particle effects?
Because the scale doesnt change
logger.info("the localtranslation before scaling: "+((Node)model).getChild("frontwheel").getLocalTranslation().toString());
rootNode.detachChild(model);
model.setLocalScale(0.0025f);
rootNode.attachChild(model);
logger.info("the localtranslation after scaling: " +((Node)model).getChild("frontwheel").getLocalTranslation().toString());
the localtranslation will always be the same....
Greetz
if i add the particle system as a node to the front wheel it is easiest and fastest if i add another to the wheel
but if i attach it to the vehicle i need to know what the localtranslation is from the wheel to the bike
as frontwheel is already a node, i would just attach two particle systems to front and backwheel.
geronimo3 said:
but if i attach it to the vehicle i need to know what the localtranslation is from the wheel to the bike
that would simply be frontwheel.getLocalTranslation() :)
if you need to get the absolute distance between the frontwheel and the vehicle, you could do something like:
System.out.println("distance Vehicle -> Fronwheelt" +frontwheel.getWorldTranslation().distance(model.getWorldTranslation()));
geronimo3 said:
but if i attach it to the vehicle i need to know what the localtranslation is from the wheel to the bike
that would simply be frontwheel.getLocalTranslation() :)
[/quote$
that is just the problem:
frontwheel.getLocalTranslation() doesn't show the local translation
it shows the vector between the bike and the frontwheel as unscaled
well, yes but thats not a problem.
if you attach a particlesystem to the model with this translations, it will be at the correct location.
because, before rendering, the models scale will be used to calculate the correct translation of both, the wheel and particle system.
in the following screenshot i set the particles localtranslation to the front and backwheels localtranslation.
the modified vehicle constructor:
public Vehicle(String id, Spatial model) {
super(id);
setModel(model);
Node frontParticle = null;
Node backParticle = null;
ZBufferState zb = DisplaySystem.getDisplaySystem().getRenderer().createZBufferState();
zb.setEnabled(true);
zb.setWritable(false);
// i want dark particles
BlendState bs = DisplaySystem.getDisplaySystem().getRenderer().createBlendState();
bs.setBlendEnabled(true);
bs.setSourceFunction(SourceFunction.SourceAlpha);
bs.setDestinationFunction(DestinationFunction.OneMinusSourceAlpha);
try {
// load the particle effect two times
ResourceLocatorTool.addResourceLocator(ResourceLocatorTool.TYPE_TEXTURE,
new SimpleResourceLocator(Vehicle.class.getClassLoader().getResource("jmetest/data/texture/")));
frontParticle = (Node) BinaryImporter.getInstance().load( Vehicle.class.getResource("dirt.jme"));
frontParticle.setRenderState(zb);
frontParticle.setRenderState(bs);
((Node)model).attachChild(frontParticle);
frontParticle.getLocalTranslation().set(frontwheel.getLocalTranslation());
frontwheel.updateWorldBound();
frontParticle.getLocalTranslation().addLocal(new Vector3f(0, -((BoundingBox)frontwheel.getWorldBound()).yExtent, 0));
// now the back wheel
backParticle = (Node) BinaryImporter.getInstance().load( Vehicle.class.getResource("dirt.jme"));
backParticle.setRenderState(zb);
backParticle.setRenderState(bs);
((Node)model).attachChild(backParticle);
backParticle.getLocalTranslation().set(backwheel.getLocalTranslation());
backwheel.updateWorldBound();
// move the particle system out of the middle of the wheel to the ground
backParticle.getLocalTranslation().addLocal(new Vector3f(0, -((BoundingBox)backwheel.getWorldBound()).yExtent*3, 0));
} catch (Exception e) {
e.printStackTrace();
}
}
(the backwheels Boundingbox seems to be a bit small somehow, thats why i multiplied the particle systems y offset by 3 imes the yextent).
the dirt.jme particle effect.