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?
Related
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 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
I'm currently developing a 2D RPG with LWJGL, and am still in the engine stage of development. I've got a lot of the tech I want created, but one of my big problems is fixing the camera on the player. All the solutions I've seen involve moving the world and keeping the player still, which can work, but it seems apparent that this can cause some calculation issues if not closely monitored. Normally, I'd write a system where I wouldn't have to worry about it, but I refuse, because I eventually intend on adding multiplayer capability, where a moving world would be unplayable.
Is there a way to affix the camera to an object or point that can move WITHOUT using translate to move the world around? Also, I'd like to avoid Slick if possible. That would require me to rework much of my game engine as it currently stands.
Whenever you are going to project the 3d viewport onto a 2d screen you need to move everything according to the point of view of the observer (the so called camera or view).
I guess you can't escape from this. What you usually do is having a Camera object which holds position and rotation that is used to build the view matrix which is passed to the vertices of your scene through a uniform to the shaders. Passing transformation matrices to shaders is the normality so you shouldn't feel burdened by it. You can always premultiply it with the perspective matrix.
You must move the whole world to match the position of your camera just because you need to transform everything in your scene as it is seen from that point of view, otherwise how could you then project it on your screen? There is no "move the camera, keep the world still" concept.
Move the world visually, it's how every other RPG does it. Don't move the actual world's location though.
Draw everything but the ui normally, than translate it all according to the players position (i.e. glTranslate2f(-player.x,-player.y)). This is all done in the render method. On networked multiplayer, the viewport is done to that specific player (i.e. Bob's screen is translated based off Bob's position, Jane's is translated based off Jane's position). Should you instead want single-screen multiplayer, you will probably have to use mutliple framebuffers (one per player), and use them as viewports.
I have a 3D scene that runs on libGDX(Android). I want to use particle system. When I create one using the tutorials/examples found online (e.g. Particle System libGDX) I get a particle system which works fine. Except for one thing: it is fixed on screen.
When I move the camera around the particle system stays on the same place on screen (like a fixed HUD element or so). Maybe it's because of Sprite-nature of ParticleEffect.
The other issue related is that the ParticleEffect.setPosition() method takes values not in the World coordinates but in screen pixels. Is this correct? I can calculate new on-screen coordinates in pixels and update ParticleEffect position every frame. But that seems like a hack to me.
Is there a more "right" way to make my particle system behave like other objects in my 3D scene and not be fixed on screen?
The Particle System is just working in 2D System. It's not a 3D Particle System thats why you wont get it into your world. That's why it's inside of the g2d package (graphics 2D). Thats also the reason why it just take 2D cords and not 3D cords.
Also the Feature list says that it's inside of the 2D Highlevel API.
Featurelist
I have two views called x and y they are both black lines (for example I made the height of the x line is 1dp and width 230dp and as background filled with the color black).
Now i want to move the position of the lines programmatically (for example I want the y line 50dp to the right of the orginal position).
Can someone help me how to do this?
I have tried things such as setpadding but the line doesn't move.
Thanks in advance!
(ps: my minimum sdk is set for 7 so i can't use the newest api's).
Old Answer
Have a look at the Absolute Layout, it allows you to position
child elements using x, y coordinates. It is deprecated but it's the
only way in Android to do real x,y coordinate positioning.
I would ask what the main point behind what you are trying to do is
though? It sounds like you started with a goal, were led down a path
and now are asking how to get to the end of that path, rather than
asking how to do what you need to do.
Edited
For drawing graphs have a look instead at https://stackoverflow.com/questions/2271248/how-to-draw-charts-in-android.
Using a Layout class to draw a chart will only lead to a really slow app, since the layout classes are designed for creating relatively static layouts, not drawing full graphics.
Instead use either the Canvas and draw your drawables yourself or use the graphing packages listed in the SO question I linked above.