I have a universe containing a lots of Sphere objects with different colors placed in different locations. What I need to do now is to find a way to display the coordinates of the center of a sphere when clicking on it with the mouse, so that the user is going to be able to retreive this data in a user-friendly way.
Is there someone who has an idea on how to do that?
I assume you are wanting to retrieve the 3D coordinates of the Sphere.
The most obvious solution is to define your own location-storing object [ x y z].
Keep a copy of the location whenever your program is first creating a Sphere.
Are you using this pre-defined Sphere?:
com.sun.j3d.utils.geometry.Sphere
Related
So i am new to libgdx and i am thinking about making 2D quest. I want to know how to interact with the objects on the backround image. For example, i have this location
Is it possible to get the window's coordinates so that if the player is next to it (I want to check the interaction possibilities by the player's coordinates and the interactive object's coordinates), he can press "E" or do something like that?
I was thinking about putting certain images in the background, but I don't know if that's a good idea. I also saw something about TextureRegion but I don't think it can help me because I still don't know how to get the coordinates of a specific area in the background.
Colour code the objects. From the appearance of your game its retro adventure so you are using a restricted palette. A restricted palette has advantages! So if you have windows with two colours, doors with 2 different and separate colours, objects with 2 different separate colours, then you can check when the player gets near a window, or whichever, by seeing what active colours are present on a radius around the player location.
So e.g. the floor and walls are coloured of course but they never trigger anything. This does limit you to one window per room, or one type of object per room (unless you introduce a new window colour pair to distinguish them). The code would be just sample all the pixels in the area around the player maybe a rectangle would be better.
I am looking for code or a library call that will let me get the size of a 3D object .obj file in Java. Javagl looked promising but I don't see any. I know the way to get the bounding box comes from analyzing the file itself is to get the difference between max X and min X vertex coordinates of the object(similar for all other axis). Then you can get the center of the model from the bounding box by X size/2 + min X (similar for other axis)
Is there a better way to do this than to read the file itself or do that calculations manually?
I am using Java since I am trying to make an AR application using Android + ARCore.
I'll post this as an answer, though it is by no means complete, simply because it is too large for a comment. This is a rather generalized response - what exact methods you require will depend on the frameworks you use for your rendering (or 3D object processing), in this case ARCore I suppose.
Goal: Find center
If I read you correctly, you intend to find the center of your 3D object. First you need to decide what exactly you mean by "center", because this decides, whether or not you need a bounding box at all.
Some options:
Center of mass: A simple implementation of this is assuming all your vertices have equal weight and calculating an average over them. Disadvantage: If your vertices are not distributed uniformly, then the center will shift to whereever most vertices occur.
Center of an Axis Aligned Bounding Box: In this case you use your world coordinate system or whatever coordinate system you defined your 3D object in and find x_min, y_min, z_min, x_max, y_max, z_max. The center of your AABB is then simply the average of these two points. Disadvantage: Depending on 3D object orientation and dimensions the center of the AABB can be quite a bit off or not even inside the object at all.
Center of an Oriented Bounding Box: However maybe you want to define your bounding box based on the dimensions of your 3D object. This case is similar to AABB, however with AABB your base vectors for your bounding box are aligned with the ones of your world coordinate system. For an OBB you need to find new base vectors, where one is typically parallel to the largest-distance-vector between two points in your 3D object and the other two are orthogonal to it and each other. Once the bounding box is found finding center is the same as with the AABB. Disadvantage: Finding bases is expensive.
Visual explanation of the three options described:
Center of Mass
Axis Aligned Bounding Box
Oriented Bounding Box
Further reading
See answer for information on OBB and AABB
Aligned Bounding Box
Oriented Bounding Box
Stanford paper on OBB calculation
I'm currently creating a 3D solar system model and need to create trails behind the orbits of the bodies.
I have been using Cylinders to create a 3D line, however I would like to produce a line that stays at a constant width no matter the zoom of the view.
I think it might be possible with a 2D line but im not sure how to go about that, I would need to convert the 3D Points into the 2D Points for the scene and then create a line using them, but the line would need to be continually updated depending on the rotation and zoom of the camera.
Is there a better way to go about this?
I am using a Java application to display an image on the screen. I also am using an eye-tracker device which records the absolute pixel X,Y locations where the person is looking on the screen.
However, what I need to do is convert these X,Y coordinates from the screen positions into the X,Y locations of the image. In other words, somehow I need to figure out that (just an example) 482, 458 translates to pixel 1,1 (the upper left pixel) of the image.
How can I determine the image's placement on the screen (not relative to anything)?
I saw a few posts about "getComponentLocation" and some other APIs, but in my experimentation with these, they seem to be giving coordinates relative to the window. I have also had problems with that because the 1,1 coordinate that they give is within the window, and there is actually a bar at the top of the window (that has the title and the close and minimize buttons) whose width I do not know, so I cannot easily translate.
Surely there must be a way to get the absolute pixel location on the screen of a component?
If we are talking about Swing/AWT application than class java.awt.Component has method getLocationOnScreen which seemed to do what you want
And yes as #RealSkeptic mentioned in comments to question:
SwingUtilities.html#convertPointFromScreen
will do all this work for you considering components hierarchy
I'm trying to build a food menu that the first things users will see on the screen monitor are rotating images of twelve different dishes. I imagine trying to use threads and a timer that will rotate the objects in a circle via changing coordinates or layout managers.
However, 3d rotational movements are encouraged to which I have no real experience in. I've also heard that you can use a java applet and let javascript rotate the objects. I welcome any recommendations and thank you for reading.
If you don't want to go the whole Java 3D or OpenGL route, you can get a 2½ D effect by using AffineTransform and varying x, y and the apparent size. There's an example here.