Jump to content
  • Advertisement
Sign in to follow this  
yyyy988

sweep a 2D shape into 3D

This topic is 2667 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello,
Does anyone know where I can find examples about how to use sweep method to draw objects? I have spent a couple of hours to search online, but I did not find any example code for this. (There are some about sweep-selection, but I do not think this is what I want.) Could anyone give me some simple examples like drawing a cube by translating a square along the line and a cylinder by rotating a line along the circle? I really know the idea, but it is difficult for me to figure out all the details. Hopefully, the example also includes how to map texture to this kind of complicate objects. Any advice is appreciated. Thanks!

Share this post


Link to post
Share on other sites
Advertisement
A couple of search terms that might help are 'extrusion' and 'procedural mesh'.

(There's actually a tutorial project on the Unity engine site that shows how to do this; although it's Unity-specific, the concepts are general and can be applied elsewhere.)

Share this post


Link to post
Share on other sites
Yes, I also tried those terms, but only found some advice to implement it. Could you give me some pseudo-code about what I should do step by step?

Share this post


Link to post
Share on other sites

Yes, I also tried those terms, but only found some advice to implement it. Could you give me some pseudo-code about what I should do step by step?

To be honest, it's a little involved, so even the pseudocode for it would be fairly complex.

If you can specify a single example that you're wondering about though, that might make it easier. (For example, 'I want to sweep a circle along a spline to make a tube'.)

Share this post


Link to post
Share on other sites
The front:
Convert the 2D polygon into a 3D polygon (by replacing [x,y] with [x,y,0]).
The back:
Clone the 3D polygon and offset it in the Z direction.
The edges:
For each line in the 2D polygon, create a 3D square (by creating 2 copies of the line, one of them offset in the Z direction, and creating two new lines in the Z axis to join them).

Share this post


Link to post
Share on other sites
As I said, the very simple example is enough like drawing a cube and cylinder by using translation and rotation. Of course, opengl support them as basic 3D objects, but I just want to know how the path defined and if we move 2D shape along the path, how to connect two adjacent shapes?

Share this post


Link to post
Share on other sites

As I said, the very simple example is enough like drawing a cube and cylinder by using translation and rotation.

Well, that's two examples ;) I was trying to narrow it down to just one to make the question a little easier to answer.

Anyway, Hodgman provided a rough outline for the cube case, so maybe you can use that as a point of departure.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!