?
Solved

Extruding a 2D path

Posted on 2004-09-18
3
Medium Priority
?
242 Views
Last Modified: 2013-12-26
Hi guys,

I have developed a 2d graphics app which can create simple outlines (consisting of straight lines only).  Using DirextX, I would like to extrude each line into a face based on a height parameter.  Each Shape (2D) has an array of Point objects (X & Y values).  

Can anyone help?

I'm using C# but i'll accept the algorythm in pseudo code if you're not familiar with c# as long as it uses standard verticies / vertex buffers / index buffers etc.

Thanks in advance

Chris
0
Comment
Question by:chrisevans123
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 17

Accepted Solution

by:
davebytes earned 1840 total points
ID: 12109431
If you aren't using too many lines to begin with, don't even bother worrying about optimization.

You may want to swap Y and Z in the following, depending on how you want things to look initially.

For each point, you want to make it a 3D point at say Z=100 to start with.  Then you also need the extruded matching point at Z=100+height.

A final vertex array can be rendered as a triangle strip if the points are interlaced.  That is, assuming your initial vertices are in a 2d float structure, and you have a 3d point structure (which D3D does), you want to do something like:

Point2D *array_orig; // already filled in.
int vertex_count; // already filled in...
float extrude_height; // same...

Point3D *array_3d = new Point3D[vertex_count];
int sub;
for (int i=0; i<vertex_count; i++)
{
  subi = 2*i;
  array_3d[subi].x = array_orig[i].x;
  array_3d[subi].y = array_orig[i].y;
  array_3d[subi].z = 100;
  array_3d[subi+1].x = array_orig[i].x;
  array_3d[subi+1].y = array_orig[i].y;
  array_3d[subi+1].z = 100 + extrude_height;
}

Then array_3d can be rendered as a triangle-strip.  You might need to play with clockwise vs counter-clockwise culling (or turn culling off).

-d
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

What is RenderMan: RenderMan is a not any particular piece of software. RenderMan is an industry standard, defining set of rules that any rendering software should use, to be RenderMan-compliant. Pixar's RenderMan is a flagship implementation of …
Artificial Intelligence comes in many forms, and for game developers, Path-Finding is an important ability for making an NPC (Non-Playable Character) maneuver through terrain.  A* is a particularly easy way to approach it.  I’ll start with the algor…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses
Course of the Month11 days, 12 hours left to enroll

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question