How to extrude a shape to a volume - java

I am currently trying to show a series of images that slightly differ from each other in a 3D view, and which contain lots of transparent areas (for example, points that move in time inside a rectangle, and I would provide a 3D view with all their positions over time).
What I'm doing now is generate an image with the points drawn in it, create one Boxes of 40x40x1 per frame (or rectangular shape of 40x40), apply the image as a texture to the FRONT side of the box, and add the boxes to my scenes at positions (0, 0, z) where z is the frame number.
It works quite well, but of course their is discontinuities (of 1 "meter") between the images.
I would like to know if their is a way to create an "extrusion" object based on that image so as to fill the space between the planes. This would be equivalent of creating one 1x1x1 box for each point, placing them at (x, y, z) where x/y are the point's coordinate and z the frame number. The actual problem is that I have lots of points (several hundreds, if not thousands in some cases), and what was relatively easy to handle and render with an image would, I think, become quite heavy to render if I have to create thousands boxes.
Thanks in advance for your help,
Frederic.

You could use 3d textue with your data (40 x 40 x N) pixels, N=number of frames.
But you still has to draw something with this texture enabled.
I would do what you are doing currently - draw quads, but no only along Z axis, but along X and Y too.
Each of N quads along Z axis would have 40x40 size, each of 40 quads along X axis would be 40xN size, and each of 40 quads along Y axis would be Nx40 size.
So for 2x2x2 textue we will draw 2+2+2 = 6 quads, and it will look like regular cube, for 3x3x3 points in texture we will draw 3+3+3 quads, and it will look like 8 cubes stacked into one big cube (so instead of 8 cubes 6 quads each we just draw 9 quads, but the effect is the same).
For 40x40x1000 it would be 1080 quads (reasonable to draw in real time imho) instead of 40*40*1000*6 quads.
I only don't know, if the graphical effect would be exactly what you wanted to achieve.

Related

can I draw 3d surface plot using OpenGL in Android?

I receive real-time data from HC-05 Bluetooth and I want to show this data in a 3D surface chart, there were few libraries but I want to do it myself.
I can make Pyramids and Cubes but I am confused with the Surface chart. how can I draw shapes like the surface charts in OpenGL?
This is a picture of 3D surface chart :
https://www.nevron.com/NIMG.axd?i=Chart/ChartTypes/TriangulatedSurface/triangulated_surface_chart.png
Oh, I've done one of those for the Treasury yield curve. Since you say you can do cubes, than all you have to do is make a grid of them, right next to each other, with the top four points of each aligned with the X and Z axis, and rotate them all 45 degrees. Don't worry about the bottom parts of the cubes that are not visable, they will get z-sorted out of view. The hardest part will be the labels, so I suggest you prerender 20 textures, that is, 0 to 90, and 100 to 900, then slap them on the sides of white cubes. For the tray, just make a bunch of long grey cube 2 pixels thick...

Find the size of maze corridors in a image

So I am building a application to solve mazes one of the options is upload a picture and it will solve it. However upon solving the maze the output will look like this.
I would like to figure out how to make my program find the proper corridor size and have the solution look like this with the pathway completely full
My data is put into a array with 1's representing the walls and 0's the spaces like this. So far I have thought about trying to find the smallest distance between 1's but that runs into problems with circular mazes and writing on the maze. I have thought about filling the distance between the walls but that runs into problems at intersections.
I am drawing on the image using
image.setRGB(x, y, Color.RED.getRGB());
with the image being a BufferedImage.
I am truly all out of ideas and don't know how to come at this problem any help would be appreciated.
Each square in your grid has a certain size. Say wsq * hsq for "width of square times height of square".
Given your much more fine-grained (x, y), you can find in which square it is by dividing x by wsq and y by wsh:
int xsq = x / wsq;
int ysq = y / ysq;
The area to paint red would be from (xsq * wsq, ysq * hsq) and have width/height (wsq, hsq). and you could paint that red, but it would mean that you paint over the walls. So you have to adjust the area you're going to fill with red color by the size of the walls. If the walls are all two pixels thick, you need to add 1 to the x and the y coordinate of the square, and substract 2 from the widht and the height.
And you could fill it again (with a Graphics2D) for every time that you are now calling image.setRGB or you could remember which squares that you already filled.
Note: since you are working with regular-sized squares, you can also optimize your maze-solving algorithm to work in a grid of squares of size (wsq, hsq) rather than the individual pixels in the image.

running on every pixel inside a circle

Let's say I have many small bitmaps and I draw a big circle around them but not necessary all bitmaps are inside of the circle (like some can be half way in or have their edges stick out) and I want to run on every single pixel of the bitmaps in the circle (meaning pixels that are outside of the circle wont be counted, only the parts that are inside), how do I go about doing that, I know how to run on every pixel of all the bitmap, but not in a specific shape..
You need to create an imaginary grid, or rather a grid that is only useful in that it will help you solve the problem at hand. This is the grid that you will assign all the bitmaps to a position on, imagining that the circle's center is to be located at (0,0).
You then use a little math
to find if a pixel as it is relative to its bitmap's position on the grid, is within the radius of the circle.
Of course the distance formuala is
Or if you rather it is the sqrt( a^2 + b^2 ). where 'a' is the difference in x and 'b' is the difference in y between 2 points.

Draw curved custom object in LIBGDX?

I've recently been looking into LibGDX and seem to have hit a wall, seen in the picture, the blue dot represents the users finger, the map generation it self is where i seem to get stuck, does LibGDX provide a method of dynamically drawing curved objects? I could simply generate them myself as images but then the image is hugely stretched to the point of the gap for the finger can fit 3! But also would need to be 1000's of PX tall to accommodate the whole level design.
Is it such that i should be drawing hundreds of polygons close together to make a curved line?
On a side not i'll need a way of determining when the object has from bottom to top so i can generate another 'chunk' of map.
You don't need hundreds of polygons to make a curve like you drew. You could get away with 40 quads on the left, and 40 on the right, and it would look pretty smooth. Raise that to 100 on each side and it will look almost perfectly smooth, and no modern device is going to have any trouble running that at 60fps.
You could use the Mesh class to generate a procedural mesh for each side. You can make the mesh stay in one spot, locked to the camera, and modify it's vertices and UVs to make it look like you are panning down an infinitely long corridor. This will take a fair amount of math up front but should be smooth sailing once you have that down.
Basically, your level design could be based on some kind of equation that takes Y offset as an input. Or it could be a long array of offsets, and you could use a spline equation or linear equation to interpolate between them. The output would be the UV and X coordinates which can be used to update each of the vertices of your two meshes.
You can use the vertex shader to efficiently update the UV coordinates, using a constant offset uniform parameter that you update each frame. That way you don't have to move UV data to the GPU every frame.
For the vertex positions, use your Mesh's underlying float[] and call setVertices() each frame to update it. Info here.
Actually, it might look better if you leave the UV's and the X positions alone, and just scroll the Y positions up. Keep a couple quads of padding off top and bottom of screen, and just move the top quad to the bottom after it scrolls off screen.
How about creating a set of curved forms that can be put together variably. Like the gap in the middle will at the top and bottom of each image be in the middle (with the same curvature at end and beginning points)...
And inbetween the start and end points you can go crazy on the shape.
And finally, you can randomly put those images together and get an endless world.
If you don't want to stop in the middle each time, you could also have like three entry and exit points (left, middle, right)... and after an image that ends left, you of course need to add an image that starts left, but might end somewhere else...

Java Applet Graphics Resizing

So I've got an assignment that takes two inputs, males and females, and outputs matingPairs, the product of the two.
In addition to that, the instructions ask to draw a shape using one of those variables.
I've decided to draw circles for each value.
I first draw matingPairs, followed by the smaller male and female circles on top of the original, larger matingPairs circle.
The problem I'm running in to is obviously representing the graphic in the applet. If the numbers go higher than say 100, the graphic becomes too large for the applet.
I'm looking for a way to basically have the matingPairs circle always fill the applet, then have males and females dynamically adjust so their size is scaled relative to the matingPairs circle size. I'm using JApplet.
Thank you very much for any guidance. I'm really looking for a solution, rather a push in the right direction.
May be you should provide more instruction about how are you drawing the circles in the Graphics object.
The idea is to manage two bi-dimensional spaces with different scales; the first one is the input data and the second one represents the available area to draw such data. The first one can have data on any location, such (5, 5), (0.2, 0.3)or (1200, 3400). The key is to map the original coordinates of the first space into the second, using the proper transformation: scale + translation.
This transformation must be calculated prior to start drawing and applies to any point drawn.
The idea is to map the rectangle where input data resides to the available area in the graphics. If the graphics area is 200x200 pixels and the data could be from (0, 0) to (400, 400), just divide by 2 the coordinates of the points to draw. If the original data is not centered in (0, 0), use a translation.
So, do you need to know how to get the size of the applets canvas or how to scale the male/female circles accordingly?
Edit:
Drawing a circle to fill the 600x600 area should be easy. Just keep in mind that you often specify the top left corner of the circle and the width and height (i.e. the diameter) when calling drawOval() / fillOval() or similar methods.
The next question is: what does represent the size of the input (males/females) and output (pairs), the area or the radius of the circles? Whatever it is, it should be easy to calculate the input/output ratio and then multiply the fixed size of the output circle with it in order to get the size of the input circle.

Categories

Resources