I’ve read the wiki and the HelloPicking example but I can’t see how both applies to my question. I understand how to set a viewport and how to use multiple cameras. My problem is how to keep another camera on screen according to screen cordinates. Actually I realized that world coordinates to viewport would works too. I want to update the camera viewport using screen coordinates or world coordinates values. I don’t know how explain very well so I drew this to make it more clear. I tried to upload the image but I’m getting errors so I uploaded it to ImgBB.
@chalcosoma, so it looks like you are wanting to do like a “magnifying glass” type situation on one of your models? sounds like a neat idea, to me.
And I don’t know how much help this will be, but:
so for viewport coordinates it goes in the format: x1, x2, y1, y2 and the values ranging from 0.0f to 1.0f. bottom-left to top-right.
Some code for that might help would be to do up the jme samples (and include the test data jar so it will all work-ish) and check out multiviews in the renderer folder.
That should give ya a good handle that you can think of viewport coordinates as like a percent type situation.
then you would probably want to figure out a location on your mesh or object (maybe it’s spatial/node coordinates?) and use a ray-collision type situation with the camera… you would be reversing the camera’s direction mathematically to go from the object to the camera and see what 2D point you collide with on the camera’s near plane.
That’s probably the process you are looking for, though I can’t think of the right math to suggest for doing so… I’ve discarded a lot of that info off of the top of my head.
But… does that sound like a good clarification of what you are trying to do?
EDIT: oh wait… looks like you are using a good method up there in your code. LOL
It’s not a magnifying glass. I want to show the top of the object in Camera2 (as seen in the image) and place the camera viewport close to the object. I’m making a dice roller app and the object is a dice. I want to show the dice result in the camera, showing the dice top face.
You may want to make alternative arrangements in case the die is near the top of the screen (dieCenterScreenLocation.y > 0.7fscreenHeight) near the left edge (dieCenterScreenLocation.x < 0.1fscreenWidth) or near the right edge (dieCenterScreenLocation.x > 0.9f*screenWidth).
I’m not sure I’ve interpreted the question correctly but just in case you are trying to figure out where to place a 3D perspective camera such that an object is fully in view…
I had to do something similar when lining up the imposter camera for the SimArboreal tree editor. I wanted a reasonably tight fit so as not to waste texture space. There is a magic number (not really magic) in the camera’s projection matrix which can be used to find the distance for a particular width/height.
There is a comment in the source code here:
That, and the surrounding code, might be helpful when fully ingested.