The Author Online Book Forums are Moving

The Author Online Book Forums will soon redirect to Manning's liveBook and liveVideo. All book forum content will migrate to liveBook's discussion forum and all video forum content will migrate to liveVideo. Log in to liveBook or liveVideo with your Manning credentials to join the discussion!

Thank you for your engagement in the AoF over the years! We look forward to offering you a more enhanced forum experience.

Snah (1) [Avatar] Offline
#1
Hi
Im trying to make earth simulator (zooming is very important) I use jpg texture file 2048x1014.
While zooming out (keynavigatorBehavior) works fine for some distance, afther that texture stops to zoom out & stays with same size, but sphere is zooming out (getting smaller)
I tryed to use mipmap, but cant make sphere to update texture at runtime. the source code looks like this:
---------------------------------------------------------
public class Ray3dApp extends Applet{
Appearance createTwistAppearance(){
Appearance twistAppear = new Appearance();
final int SMALLEST = 1;
int imageWidth, imageHeight, imageLevel;
String filename = "earth0.jpg";
TextureLoader loader = new TextureLoader(filename,
this);
ImageComponent2D image = loader.getImage();
imageWidth = image.getWidth();
imageHeight = image.getHeight();
Texture2D texture = new Texture2D(
Texture.MULTI_LEVEL_MIPMAP,Texture.RGBA,
imageWidth,imageHeight);
imageLevel = 0;
texture.setImage(imageLevel, image);
while (imageWidth > SMALLEST || imageWidth > SMALLEST){
imageLevel++;
if (imageWidth > SMALLEST) imageWidth /= 2;
if (imageHeight > SMALLEST) imageHeight /= 2;
filename = "earth"+imageLevel+".jpg";
loader = new TextureLoader(filename, this);
image = loader.getImage();
texture.setImage(imageLevel, image);
}
texture.setMagFilter(Texture.BASE_LEVEL_POINT);
texture.setMinFilter(Texture.MULTI_LEVEL_POINT);
twistAppear.setTexture(texture);
texture.setEnable(true);
return twistAppear;
}
public BranchGroup createSceneGraph(SimpleUniverse su) {
BranchGroup objRoot = new BranchGroup();
Appearance app = new Appearance();
TransformGroup TG = new TransformGroup();
TG.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
objRoot.addChild(TG);
Appearance appear = createTwistAppearance();
Sphere earth = new Sphere(63.78137f,
Primitive.GENERATE_NORMALS | Primitive.GENERATE_TEXTURE_COORDS,200,
appear);
objRoot.addChild(earth);
Movement movement = new Movement(su);
objRoot.addChild(movement.getMouseRotate());
objRoot.addChild(movement.getMouseTranslate());
objRoot.addChild(movement.getMouseZoom());
objRoot.addChild(movement.getKeyNavigator());
BoundingSphere bounds = new BoundingSphere(new Point3d
(),10000);
Background background = new Background(1.0f, 1.0f,
1.0f);
background.setApplicationBounds(bounds);
objRoot.addChild(background);
objRoot.compile();
return objRoot;
}
public Ray3dApp(){
setLayout(new BorderLayout());
GraphicsConfiguration gConfig =
SimpleUniverse.getPreferredConfiguration();
Canvas3D canvas3D = new Canvas3D(gConfig);
add("Center",canvas3D);
canvas3D.setStereoEnable(false);
SimpleUniverse sUniverse = new SimpleUniverse
(canvas3D);
sUniverse.getViewingPlatform
().setNominalViewingTransform();
BranchGroup scene = createSceneGraph(sUniverse);
sUniverse.addBranchGraph(scene);
}
public static void main(String[] args) {
Frame frame = new MainFrame(new Ray3dApp(),
2048,1024 );
}
}

public class Movement{
private BoundingSphere boundsSphere;
private double bounds = 10000;
private TransformGroup vpTrans = null;
private MouseRotate mRotate;
private MouseTranslate mTranslate;
private MouseZoom mZoom;
private KeyNavigatorBehavior kBehavior;
public Movement(SimpleUniverse su){
boundsSphere = new BoundingSphere(new Point3d(),
bounds);
Transform3D T3D = new Transform3D();
Vector3f translate = new Vector3f();
vpTrans = su.getViewingPlatform
().getViewPlatformTransform();
translate.set( 0.0f, 0.0f, 69f);
T3D.setTranslation(translate);
vpTrans.setTransform(T3D);
mRotate = new MouseRotate(MouseBehavior.INVERT_INPUT);
mRotate.setTransformGroup(vpTrans);
mRotate.setSchedulingBounds(boundsSphere);
mTranslate = new MouseTranslate();
mTranslate.setTransformGroup(vpTrans);
mTranslate.setSchedulingBounds(boundsSphere);
mZoom = new MouseZoom(MouseBehavior.INVERT_INPUT);
mZoom.setFactor(1);
mZoom.setTransformGroup(vpTrans);
mZoom.setSchedulingBounds(boundsSphere);
kBehavior = new KeyNavigatorBehavior(vpTrans);
kBehavior.setSchedulingBounds(boundsSphere);
}
public MouseRotate getMouseRotate(){
return mRotate;
}
public MouseTranslate getMouseTranslate(){
return mTranslate;
}
public MouseZoom getMouseZoom(){
return mZoom;
}
public KeyNavigatorBehavior getKeyNavigator(){
return kBehavior;
}
}
---------------------------------------------------------

THANKS
dselman (104) [Avatar] Offline
#2
Re: Need Help with big texture
Snah,

I'm not sure why your original code was not working. My first guess would be a rounding problem (int?) as you moved away from your subject.

For a MIPMAP example that sound similar to what you are trying to do take a look at SplineInterpolatorTest.

Best,

Dan