Skip to main content

How to move the camera !? And what *is* the camera?

Please note these java.net forums are being decommissioned and use the new and improved forums at https://community.oracle.com/community/java.
2 replies [Last post]
rhavin
Offline
Joined: 2011-02-09

Perhaps someone can help:

I have a fn that gets a texture and creates a raster at given coordinates:

// -----------------------------------------------------------------------------------
private void texturedRaster(Group group, float fSize, Vector3f pos)
{
Raster  r  = new Raster();
Texture2D tex =
Game.projectileManager.projectileGet(ProjectileManager.iPROJ_FIREBALL);

r.setImage((ImageComponent2D) tex.getImage(0));
r.setPosition(new Point3f(pos.x, pos.y, pos.z));
r.setSize(256, 256);
r.setClipMode(Raster.CLIP_IMAGE);
r.setDstOffset(-128,-128);

Appearance appear = new Appearance();
TransparencyAttributes transAttr = new TransparencyAttributes();
transAttr.setTransparency(0.0f);
transAttr.setTransparencyMode(TransparencyAttributes.BLENDED);
appear.setTransparencyAttributes(transAttr);

Shape3D shape = new Shape3D(r, appear);
group.addChild(shape);
};

As u may see in this picture, it all looks fine if the position of the Raster is near, because the texture was created in a resolution appropiate for near viewing:
(http://q-pool.de/img/myspace/raster0.jpg)

If i put the Raster a little bit farer away, it's shape is automatically scaled to the new position (it is - after all - still a Shape3D). Put the texture is *not* scaled, as u can see in this picture. (http://q-pool.de/img/myspace/raster1.jpg)

is there a way to do that? I also experimented a little bit with OrientedShape3D… has anyone a running (and working;-) example? i was able to use it like this:

// -----------------------------------------------------------------------------------
private void texturedOrientedShape(Group group, float fSize, Vector3f pos)
{
OrientedShape3D os = new OrientedShape3D();
Texture2D tex =
Game.projectileManager.projectileGet(ProjectileManager.iPROJ_FIREBALL);

// coordinates of texture
TexCoord2f[] q = {new TexCoord2f(), new TexCoord2f(), new TexCoord2f(),
new TexCoord2f()};

q[0].set(1.0f, 0.0f);
q[1].set(1.0f, 1.0f);
q[2].set(0.0f, 1.0f);
q[3].set(0.0f, 0.0f);

// resulting shape corners
Point3f[] p = {new Point3f(), new Point3f(), new Point3f(), new Point3f()};
p[0].set(pos.x - fSize, pos.y - fSize, pos.z);
p[1].set(pos.x + fSize, pos.y - fSize, pos.z);
p[2].set(pos.x + fSize, pos.y + fSize, pos.z);
p[3].set(pos.x - fSize, pos.y + fSize, pos.z);

Shape3D shape = texturedPlane(p, q, tex, false);
os.addGeometry(shape.getGeometry());
os.setAppearance(shape.getAppearance());
os.setAlignmentMode(OrientedShape3D.ROTATE_ABOUT_AXIS);
os.setCapability(OrientedShape3D.ALLOW_AXIS_WRITE);
os.setAlignmentAxis(0.0f, 0.0f, -1.0f);
group.addChild(os);
};

unfortunately, the result looks like this (pretty nice from front)… (http://q-pool.de/img/myspace/oshape0.jpg) :

… but it doesnt orient itself dynamically to the viewpoint ;-/
(http://q-pool.de/img/myspace/oshape1.jpg)

BTW, i set the 'camera' with

universe.getViewingPlatform().getViewPlatformTransform().setTransform(trNew);

Any suggestions so far…?

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
rhavin
Offline
Joined: 2011-02-09

OK, guess you have…
osFoo: OrientedShape3D, lets say at (3,3,0)
unWorld: SimpleUniverse
bgRoot: BranchGroup containing the world

you start a (0,0,0) and want to move to (3,3,3) … what do you have to do to set the camera (=ViewPlatform…? View…?) to that position and have osFoo orient to you and not to (0,0,0)? If i use…

Transform3D trNew = new Transform3D();
trNew.setTranslation(new Vector3d(3.0,3.0,3.0));
unWorld.getViewingPlatform().getViewPlatformTransform().setTransform(trNew);

…then the camera ends at (3,3,3) but osFoo 'looks' at (0,0,0) !?? So i didnt actually move the view but some kind of 'offsetted' it. How do i move?
BTW, once you figured out how some Java3D objects work, you finally understand the "documentation" ;-)

rhavin
Offline
Joined: 2011-02-09

I still didnt solve this, but i got a clue by experimenting with my world:

the OrientedShape does not align to the camera, but to the origin (0,0,0) and is therefore quite useless if u move with

universe.getViewingPlatform().getViewPlatformTransform().setTransform(trNew);

so the question i still have to solve is: how do you move the origin?