We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hi, I want to rotate many 3D planes around their center along the Y axis. My idea is to translate each plane into the center of the screen, rotate them along Y axis and then translate them to their right place. But after the rotation all the axes are rotated and I cannot figure how to translate the planes correctly. Any idea? Is it possible to remove perspective?
Thanks, paolofuse
Answers
You didn't mention it, but I'm going to assume that the planes all have their normal pointing along the y-axis. If they don't then after you translate them to the origin you would have to first rotate them to align that way. Edit: In other words I am assuming that the planes exist on the xz-plane. If they don't they will still spin on the y-axis which will make them look "tilted" while spinning
Assuming that their normals point along the y-axis:
- Take each of the 4 corner points, use them to find the plane's center (the average of the 4 point's positions), and translate all 4 to the origin using the plane's center. None of the points will actually be at the origin, the center of the plane will be there
- Rotate all 4 points along the y-axis
- Translate all 4 points back using the plane's center position - Repeat these steps for the other planes
Here is an example in 2D, you could think of it as looking down on the planes from above to relate it to yours:
Tweaked the answer a little in order to understand how it works. But it's beyond me! :(
Anyways, gonna post my exercise anyways as an alternative: ;;)
Hi asimes, what you told in your first pot is correct. I need to rotate along Y axis, so what I need is to TILT my planes. It's easy to do if I translate a plane into the center, but I need to rotate each plane around its Y axis. Thanks.
The same code will produce that effect, I just pointed out that it would happen because I was not sure if it was desirable. Edit: Normally an additional rotation step is necessary to avoid this effect
The example I posted is in 2D and performs a rotation around the z-axis because we are looking at x and y in 2D. If you were to replace all of the code that affects y with z then it would cause a rotation around the y-axis.
Here, I thought I'd make a 3D version incase my explanation was not clear enough:
@GoToLoop, When a rotation is performed it rotates an object around the origin. If the plane was not translated so that its center was at the origin then it would fly around all over the place.
The first step of the for loop moves the plane so that its center is at the origin (p[i].sub(c)). Then the math for a rotation about the desired axis (the z-axis in the 2D sketch and the y-axis in the 3D sketch). Finally the plane is translated back to where it should be after being rotated (p[i].add(c)).
The problem with doing this using Processing's translate() / rotate() functions is that the coordinate system has changed and so translating the plane back where it belongs after the rotation is not very straightforward.
I have sаme trouble.
I think you have to use beginCamera() and endCamera() function, but I'm not sure... http://www.processing.org/reference/beginCamera_.html
Hi. My friend help me. this is virtual screens