[java] Location in Java3D universe

Started by
6 comments, last by chris_j_pook 19 years ago
Hi, I am making an interactive walk though of my university campus and was wondering... How can I find the exact coordinates of where the user is standing at any one time in a J3D virtual universe ? I need to find this so that when they press a button information is displayed about the nearest building. Any ideas would be greatly appreciated. Thanks Chris
Advertisement
1) what has time to do with this?
2) where is the problem to compute the positions?!

If you have a very complex scenegraph and are unable to keep track of your objects position, this could maybe help:
myObject3D.getLocalToVworld(myTransform3D);
myTransform3D.invert();
so that you can get the pos.

But usually, you know where your objects are and you transform the scene in consequence, not the opposite!
Thanks for the reply...

Sorry I think I need to clarify the problem.

I want to be able to find the exact position of the users viewpoint so that i can find which building it is closest to when they press a button. I will use this to work out which building to show the information of.

Any ideas ?

Chirs
Think of it as a simpler problem, a 2-Dimensional problem.

In 2-Dimensions you know you have an x-coordinate and a y-coordinate. You use these coords to draw the position of your entity (or virtual tour guide). Within a 3-Dimensional space, you still have the same x and y coordinates, with the addition of the z-coordinate. For the time being, ignore this additional axis.

To draw the world in 3 dimensions, you need to already know your location. It's where everything is drawn in accordance to your point of view. You can't have 3 or even 2 dimensions unless you already know the coordinates (location) of any item.

So how are you handling it? In a 2-Dimensional world I would already have an int (or floating point) of my location in the form of xPos and yPos. I'd then code a couple methods to set my xPos and yPos and another couple methods to return my current x and y position.

Using these methods I can then draw and/or retrieve the location of my entity at any time.

In order to place anything within your 3-Dimensional space you will already have to have an xPos yPos and zPos for any entity within that world. You have to have those three positions in order to exist within a space, don't you? And if you've already got those coded, you've got an easy way of returning them.
---Real programmers don't comment their code. It was hard enough to write, it should be hard to understand!
Ok I get what you mean but ...

In my program I create a Canvas3D and then add building objects to it and move them to their correct locations using Transform3D. This is done only once at the start.

The problem I have is getting the actual x,y coords of where the scene is being viewed from. I want a function like viewPlatform.getX() or something so I can find out twhere the virtual viewer is stood in the world.

The view starts out at 0,0 i assume... but because you can move using the mouse the coords will change. What i need is to be able to find them out at any time.


Do you get what I mean ?

Thanks

Chris
yes, the view, starts at 0,0

for your problem, i see several solutions:
either the one explained before:
myViewPlatform.getLocalToVworld(myTransform3D);
myTransform3D.invert();


or, if you're using a ViewingPlatform (the default in a SimpleUniverse):
myViewingPlatform.getMultiTransformGroup()

or:
extend the OrbitBehavior to know the transform. I beleive it is placed in:
OrbitBehavior#targetTG

for information, to get the pos from a Transform3D:
myTransform3D.get(myVector3fORd);
=> myVector3fORd.x & myVector3fORd.y


is it enough or would you want more explanations?
I think he means the view direction. Not the position in the world(?)
Thanks for all the replies...

I have now managed to fix my problem. I used the getViewPlatformTransform function on the viewingPlatform to get an X, Y, Z coord for where the viewer is stood.

seems to work ok.

Thanks again ...

Chris

This topic is closed to new replies.

Advertisement