|
View:
New views
9 Messages
—
Rating Filter:
Alert me
|
|
|
How do I change how far the camera can see?Hello!
I'm developing a small app where I can move around the camera. But now I would like to change the distance how far the camera can see. Or perhaps this is some radius in some BoundingSphere I need to set. All code suggestions is most welcome. Below is 2 image of my world: http://fredand44.webs.com/bilder/w1.png If I move camera back a bit the houses disappears. http://fredand44.webs.com/bilder/w2.png I would love to be able to for eg double this distance. Best regards Fredrik [Message sent by forum member 'fredand' (fredand44@...)] http://forums.java.net/jive/thread.jspa?messageID=368676 --------------------------------------------------------------------- To unsubscribe, e-mail: interest-unsubscribe@... For additional commands, e-mail: interest-help@... |
|
|
Re: How do I change how far the camera can see?Fredrik,
Looks like you need to adjust the front and back clip planes - View.setFrontClipDistance and View.setBackClipDistance. You may also want to do View.setFront/BackClipPolicy(View.VIRTUAL_EYE) depending on how you want to interpret the distances. Hope that helps. Bill [Message sent by forum member 'weiland' (weiland@...)] http://forums.java.net/jive/thread.jspa?messageID=368681 --------------------------------------------------------------------- To unsubscribe, e-mail: interest-unsubscribe@... For additional commands, e-mail: interest-help@... |
|
|
Re: How do I change how far the camera can see?Hello!
Thanks for your reply! I tried like this in a class that extends Canvas3D: //I set a Transform3d to place the camera at 0, 0, 10 (like 10 meters back, towards the screen) cameraTransform3D.set(new Vector3f(0.0f, 0.0f, 10.0f)); cameraTransformGroup = simpleUniverse.getViewingPlatform().getViewPlatformTransform(); cameraTransformGroup.setTransform(cameraTransform3D); //I then set the view like this getView().setFrontClipDistance( View.PHYSICAL_EYE ); getView().setBackClipPolicy( View.PHYSICAL_EYE ); getView().setFrontClipDistance(1.0); getView().setBackClipDistance(20.0); //To me the above code means that where ever the camera is placed it will see objects thats is between 1 meter and 20 meter infront of the camera. Correct me if I'm wrong!! //I then place a colorcube in front of the camera: TransformGroup referensTransformGroup = new TransformGroup(); Transform3D referensTransform3D = new Transform3D(); referensTransform3D.setTranslation( new Vector3d( -1.0, 2.0, -5.0 ) ); referensTransformGroup.setTransform(referensTransform3D); referensTransformGroup.addChild(new ColorCube()); //To me it now looks like the camera is 15 meters away from the camera. I then got some code to move the camera 1 meter at a time. But even if I increase the distance more then 20 meters the colorcube is showing. First the camera then is 16 meters away: http://fredand44.webs.com/11a.png Then I move the camera to: http://fredand44.webs.com/35a.png But as you can see, the colorcube is still showing. Do you see where I go wrong, please let me know! Best regards Fredrik [Message sent by forum member 'fredand' (fredand44@...)] http://forums.java.net/jive/thread.jspa?messageID=369030 --------------------------------------------------------------------- To unsubscribe, e-mail: interest-unsubscribe@... For additional commands, e-mail: interest-help@... |
|
|
Re: How do I change how far the camera can see?your view is definitely not 35 meters away from the viewing object.
it would appear much smaller. i guess there is something wrong with your "I then got some code to move the camera 1 meter at a time." and the "Then I move the camera to: http://fredand44.webs.com/35a.png" [Message sent by forum member 'optimusprime1982' (c.krenn@...)] http://forums.java.net/jive/thread.jspa?messageID=369064 --------------------------------------------------------------------- To unsubscribe, e-mail: interest-unsubscribe@... For additional commands, e-mail: interest-help@... |
|
|
Re: How do I change how far the camera can see?Hello!
Thanks for the reply! If you got the time, please run this code below. To me this looks like that I do not manage to just set the camera see-distance to 1-20 meters with: getView().setFrontClipDistance( View.PHYSICAL_EYE ); getView().setBackClipPolicy( View.PHYSICAL_EYE ); getView().setFrontClipDistance(1.0); getView().setBackClipDistance(20.0); If I move the camera with VK_DOWN or VK_UP I move it futhera away then 20 meters from the colorcube, but It is still showing even then camera is up to 50 metersaway from point 0,0,0. Or do I do not move the camera 1 meter at each time?? Best regards Fredrik package test; import java.awt.BorderLayout; import java.awt.Color; import java.awt.event.KeyEvent; import java.awt.event.KeyListener; import javax.media.j3d.AmbientLight; import javax.media.j3d.BoundingSphere; import javax.media.j3d.BranchGroup; import javax.media.j3d.Canvas3D; import javax.media.j3d.Transform3D; import javax.media.j3d.TransformGroup; import javax.media.j3d.View; import javax.swing.JFrame; import javax.swing.JOptionPane; import javax.vecmath.Color3f; import javax.vecmath.Point3d; import javax.vecmath.Vector3d; import javax.vecmath.Vector3f; import com.sun.j3d.utils.geometry.ColorCube; import com.sun.j3d.utils.universe.SimpleUniverse; public class Object3DCanvasTest extends Canvas3D implements KeyListener { BranchGroup branchGroup; SimpleUniverse simpleUniverse; TransformGroup main = new TransformGroup(); TransformGroup cameraTransformGroup; Transform3D cameraTransform3D = new Transform3D(); public static int CAMERA_DISTANCE_MIN = 0; public static int CAMERA_DISTANCE_MAX = 50; int index = 0; Color bgColor = Color.black; double cameraAngleAroundOwnXAxis = 0.0; double cameraAngleAroundOwnYAxis = 0.0; public Object3DCanvasTest() { super(SimpleUniverse.getPreferredConfiguration()); addKeyListener(this); simpleUniverse = new SimpleUniverse(this); simpleUniverse.addBranchGraph( addLight() ); cameraTransform3D.set(new Vector3f(0.0f, 0.0f, 0.0f)); cameraTransformGroup = simpleUniverse.getViewingPlatform().getViewPlatformTransform(); cameraTransformGroup.setTransform(cameraTransform3D); //I guess this means that I the camera can se ONLY things infront of camera between 1 - 20 meters, relative to camera location??? getView().setFrontClipDistance( View.PHYSICAL_EYE ); getView().setBackClipPolicy( View.PHYSICAL_EYE ); getView().setFrontClipDistance(1.0); getView().setBackClipDistance(20.0); //Let's put a colorcube as reference TransformGroup referensTransformGroup = new TransformGroup(); Transform3D referensTransform3D = new Transform3D(); referensTransform3D.setTranslation( new Vector3d( -2.0, 0.0, -10.0 ) ); referensTransformGroup.setTransform(referensTransform3D); referensTransformGroup.addChild(new ColorCube()); main.addChild(referensTransformGroup); branchGroup = new BranchGroup(); branchGroup.addChild(main); simpleUniverse.addBranchGraph( branchGroup ); } private BranchGroup addLight() { BranchGroup branchGroup = new BranchGroup(); BoundingSphere bounds = new BoundingSphere(new Point3d(0.0,0.0,0.0), 200.0); AmbientLight ambientLightNode = new AmbientLight(new Color3f(0.5f, 0.5f, 0.5f)); ambientLightNode.setInfluencingBounds(bounds); branchGroup.addChild(ambientLightNode); branchGroup.compile(); return branchGroup; } public void move3DCamera(int dir) { if(dir == KeyEvent.VK_UP) { Transform3D temp = new Transform3D(); cameraTransformGroup.getTransform(temp); float[] matrix = new float[16]; temp.get(matrix); matrix[11] = matrix[11] - 1; //I can not go deeper then 0 at z-axis if(CAMERA_DISTANCE_MIN <= matrix[11]) { temp.set(matrix); cameraTransformGroup.setTransform( temp ); } else { JOptionPane.showMessageDialog(null, "The camera can not be moved closer to orgin\nthen min limit which is: " + CAMERA_DISTANCE_MIN); } } else if(dir == KeyEvent.VK_DOWN) { Transform3D temp = new Transform3D(); cameraTransformGroup.getTransform(temp); float[] matrix = new float[16]; temp.get(matrix); matrix[11] = matrix[11] + 1; //At next backwards the colorcubde should not be visible since distance between camera and colorcube is 21 if(10 == matrix[11]) { temp.set(matrix); cameraTransformGroup.setTransform( temp ); JOptionPane.showMessageDialog(null, "At next backwards the colorcubde should not be visible since distance between camera and colorcube is 21\nRight now distance is 10 + 10 = 20\n camera z: " + matrix[11] + "\n colorcube z: -10" ); } if(CAMERA_DISTANCE_MAX >= matrix[11]) { temp.set(matrix); cameraTransformGroup.setTransform( temp ); } else { JOptionPane.showMessageDialog(null, "The camera can not be moved futher away from orgin\nthen max limit which is: " + CAMERA_DISTANCE_MAX); } } } public static void main(String[] args) { JFrame frame = new JFrame("Test"); frame.getContentPane().add(new Object3DCanvasTest(), BorderLayout.CENTER); frame.setSize(200, 200); frame.setVisible(true); } @Override public void keyPressed(KeyEvent ke) { if(ke.getKeyCode() == KeyEvent.VK_UP) { move3DCamera(KeyEvent.VK_UP); } else if(ke.getKeyCode() == KeyEvent.VK_DOWN) { move3DCamera(KeyEvent.VK_DOWN); } } @Override public void keyReleased(KeyEvent arg0) { // TODO Auto-generated method stub } @Override public void keyTyped(KeyEvent arg0) { // TODO Auto-generated method stub } } [Message sent by forum member 'fredand' (fredand44@...)] http://forums.java.net/jive/thread.jspa?messageID=369197 --------------------------------------------------------------------- To unsubscribe, e-mail: interest-unsubscribe@... For additional commands, e-mail: interest-help@... |
|
|
Re: How do I change how far the camera can see?Hi,
as Bill recommended in an earlier post the VIRTUAL_EYE mode should be set as clip policy as long as you measure distances only in virtual world coordinates. That is what you are intenting to do. [code] // getView().setFrontClipDistance( View.PHYSICAL_EYE ); ?? getView().setFrontClipPolicy( View.VIRTUAL_EYE ); getView().setBackClipPolicy( View.VIRTUAL_EYE ); getView().setFrontClipDistance(1.0); getView().setBackClipDistance(20.0); [/code] August [Message sent by forum member 'interactivemesh' (A.Lammersdorf@...)] http://forums.java.net/jive/thread.jspa?messageID=369232 --------------------------------------------------------------------- To unsubscribe, e-mail: interest-unsubscribe@... For additional commands, e-mail: interest-help@... |
|
|
Re: How do I change how far the camera can see?is it that what you are trying to achieve?
import java.awt.BorderLayout; import java.awt.Color; import java.awt.event.KeyEvent; import java.awt.event.KeyListener; import javax.media.j3d.AmbientLight; import javax.media.j3d.BoundingSphere; import javax.media.j3d.BranchGroup; import javax.media.j3d.Canvas3D; import javax.media.j3d.Transform3D; import javax.media.j3d.TransformGroup; import javax.media.j3d.View; import javax.swing.JFrame; import javax.vecmath.Color3f; import javax.vecmath.Point3d; import javax.vecmath.Vector3d; import javax.vecmath.Vector3f; import com.sun.j3d.utils.geometry.ColorCube; import com.sun.j3d.utils.universe.SimpleUniverse; public class Object3DCanvasTest extends Canvas3D implements KeyListener { BranchGroup branchGroup; SimpleUniverse simpleUniverse; TransformGroup main = new TransformGroup(); TransformGroup cameraTransformGroup; Transform3D cameraTransform3D = new Transform3D(); public static int CAMERA_DISTANCE_MIN = 0; public static int CAMERA_DISTANCE_MAX = 50; int index = 0; Color bgColor = Color.black; double cameraAngleAroundOwnXAxis = 0.0; double cameraAngleAroundOwnYAxis = 0.0; public Object3DCanvasTest() { super(SimpleUniverse.getPreferredConfiguration()); addKeyListener(this); simpleUniverse = new SimpleUniverse(this); simpleUniverse.addBranchGraph(addLight()); //put the camera 5 meters away from 0,0,0 cameraTransform3D.set(new Vector3f(0.0f, 0.0f, 5.0f)); cameraTransformGroup = simpleUniverse.getViewingPlatform() .getViewPlatformTransform(); cameraTransformGroup.setTransform(cameraTransform3D); getView().setFrontClipPolicy(View.VIRTUAL_EYE); getView().setBackClipPolicy(View.VIRTUAL_EYE); getView().setFrontClipDistance(1.0); getView().setBackClipDistance(20.0); // Let's put a colorcube as reference TransformGroup referensTransformGroup = new TransformGroup(); Transform3D referensTransform3D = new Transform3D(); referensTransform3D.setTranslation(new Vector3d(0.0, 0.0, 0.0)); referensTransformGroup.setTransform(referensTransform3D); referensTransformGroup.addChild(new ColorCube(1)); main.addChild(referensTransformGroup); branchGroup = new BranchGroup(); branchGroup.addChild(main); simpleUniverse.addBranchGraph(branchGroup); } private BranchGroup addLight() { BranchGroup branchGroup = new BranchGroup(); BoundingSphere bounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 200.0); AmbientLight ambientLightNode = new AmbientLight(new Color3f(0.5f, 0.5f, 0.5f)); ambientLightNode.setInfluencingBounds(bounds); branchGroup.addChild(ambientLightNode); branchGroup.compile(); return branchGroup; } public void move3DCamera(KeyEvent ke) { float one = 0; if (ke.getKeyCode() == KeyEvent.VK_UP) { one = 1; } else{ one = -1; } Transform3D temp = new Transform3D(); cameraTransformGroup.getTransform(temp); Vector3f vec = new Vector3f(); temp.get(vec); vec.z = vec.z+one; temp.set(vec); cameraTransformGroup.setTransform(temp); } public static void main(String[] args) { JFrame frame = new JFrame("Test"); frame.getContentPane().add(new Object3DCanvasTest(), BorderLayout.CENTER); frame.setSize(200, 200); frame.setVisible(true); } @Override public void keyPressed(KeyEvent ke) { move3DCamera(ke); } @Override public void keyReleased(KeyEvent arg0) { // TODO Auto-generated method stub } @Override public void keyTyped(KeyEvent arg0) { // TODO Auto-generated method stub } } [Message sent by forum member 'optimusprime1982' (c.krenn@...)] http://forums.java.net/jive/thread.jspa?messageID=369239 --------------------------------------------------------------------- To unsubscribe, e-mail: interest-unsubscribe@... For additional commands, e-mail: interest-help@... |
|
|
Re: How do I change how far the camera can see?Hello Guys!
You solved it! Thanks alot. I read that: # VIRTUAL_EYE - specifies that the associated distance is from the eye and in units of virtual distance. # PHYSICAL_EYE - specifies that the associated distance is from the eye and in units of physical distance (in meters). This is the default policy for both front and back clipping. Now I also see that PHYSICAL_EYE is default, that also tells me that it makes no sense to set it to PHYSICAL_EYE. But I'm not sure that I understand the differens between PHYSICAL and VIRTUAL, so if any one have time to explain I would be very glad to read it! Best regards Fredrik [Message sent by forum member 'fredand' (fredand44@...)] http://forums.java.net/jive/thread.jspa?messageID=369245 --------------------------------------------------------------------- To unsubscribe, e-mail: interest-unsubscribe@... For additional commands, e-mail: interest-help@... |
|
|
Re: How do I change how far the camera can see?Quoting from the Java 3d guide:
These policies are defined as follows. PHYSICAL_EYE: Specifies that the plane is located relative to the eye's position as measured in the physical space (in meters). PHYSICAL_SCREEN: Specifies that the plane is located relative to the screen (that is, the image plate) as measured in physical space (in meters). VIRTUAL_EYE: Specifies that the plane is located relative to the virtual eyepoint as measured in virtual world coordinates. VIRTUAL_SCREEN: Specifies that the plane is located relative to the screen (that is, the image plate) as measured in virtual world coordinates. Java 3d maintains a notion of where the viewer's head/eyes are relative to the screen. I'm not clear on where the relationship is made between scale of virtual and physical coordinate systems (maybe the default assumption is that everything is in meters?) but it's possible to change the relationship by setting a scale factor on the view platform transform. It seems to me that nominally there should be little difference between using the virtual vs physical policies above, but they have a pronounced effect, even when you set up everything with defaults. Anyone have more insight on this? Bill [Message sent by forum member 'weiland' (weiland@...)] http://forums.java.net/jive/thread.jspa?messageID=369508 --------------------------------------------------------------------- To unsubscribe, e-mail: interest-unsubscribe@... For additional commands, e-mail: interest-help@... |
| Free embeddable forum powered by Nabble | Forum Help |