Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
What would be the easiest way to render a radial menu ( with dynamic number of items ) in DirectX 9?
void DrawMenu(int x, int y, int radius, int width, int segments, LPDIRECT3DDEVICE9 dev){
Draw2DCircle(x, y, radius, D3DCOLOR_RGBA(0, 255, 255, 255), dev);
Draw2DCircle(x, y, radius-width, D3DCOLOR_RGBA(0, 255, 255, 255), dev);
float innerX, innerY, outerX, outerY;
float Theta;
for (int i = 0; i < segments; i++){
Theta = i * (2*PI / segments);
innerX = (radius - width)*cos(Theta) + x;
innerY = (radius - width)*sin(Theta) + y;
outerX = (radius)*cos(Theta) + x;
outerY = (radius)*sin(Theta) + y;
DrawLine(innerX, innerY, outerX, outerY, D3DCOLOR_RGBA(0, 255, 255, 255), dev);
}
}
I did as Mario said and it works like a charm, but... What would I need to do that menu would be colored?
Draving functions:
void DrawLine(int x1, int y1, int x2, int y2, D3DCOLOR color, LPDIRECT3DDEVICE9 dev){
D3DTLVERTEX Line[2];
Line[0] = CreateD3DTLVERTEX(x1, y1, 0.0f, 1.0f, color, 0.0f, 0.0f);
Line[1] = CreateD3DTLVERTEX(x2, y2, 0.0f, 1.0f, color, 0.0f, 0.0f);
dev->SetFVF(D3DFVF_TL);
dev->SetTexture(0, NULL);
dev->DrawPrimitiveUP(D3DPT_LINESTRIP, 2, &Line[0], sizeof(Line[0]));}
void Draw2DCircle(int x, int y, float radius, D3DCOLOR color, LPDIRECT3DDEVICE9 dev){
const int NUMPOINTS = 40;
D3DTLVERTEX Circle[NUMPOINTS + 1];
int i;
float X;
float Y;
float Theta;
float AngleBetweenPoints;
AngleBetweenPoints = (float)((2 * PI) / NUMPOINTS);
for (i = 0; i <= NUMPOINTS; i++)
{
Theta = i * AngleBetweenPoints;
X = (float)(x + radius * cos(Theta));
Y = (float)(y - radius * sin(Theta));
Circle[i] = CreateD3DTLVERTEX(X, Y, 0.0f, 1.0f, color, 0.0f, 0.0f);
}
dev->SetFVF(D3DFVF_TL);
dev->SetTexture(0, NULL);
dev->DrawPrimitiveUP(D3DPT_LINESTRIP, NUMPOINTS, &Circle[0], sizeof(Circle[0]));}
Custom vertex structure
struct D3DTLVERTEX{
float fX;
float fY;
float fZ;
float fRHW;
D3DCOLOR Color;
float fU;
float fV;};
For future questions, you should include some code, so people are able to help you pinpoint where you've made a mistake rather than (re-)writing everything from scratch.
Consider the following code untested pseudo code. You might need some more adjustments and/or fix a few bugs (writing this from memory; not with some dev environment running).
I'm going to draw an empty circle only. It should be trivial to extend this to draw a ring, which essentially just means adding a second, smaller circle.
To draw a circle, you'd typically use a fixed number of points. Let's assume we'd like to use at least 30.
With an equal distribution, this means we'll get 30 / number_of_segments points per segment. There's a problem however: There might be cases where the ending of a segment should be between two points, so it's better to use 30 / number_of_segments + 1 points for each segment.
Once this is established, it's rather easy to define all points using polar coordinates:
The first point has an angle of start = segment_number * (360 / number_of_segments).
The last point has an angle of end = (segment_number + 1) * (360 / number_of_segments).
The remaining points are equally distributed between start and end.
To get cartesian coordinates you'd just use trigonometry (r is the radius, a the angle):
x = r * cos(a);
y = r * sin(a);
With all your points known, it should be easy to create some visible geometry with that. Keep in mind that you might have to add some offset to move the circle/ring as well.
Related
I am facing problems trying to make 3d objects clickable by mouse. For intersection checking I use ray casting. Code I found, ported for my solution:
Exactly picking
bool RaySphereIntersect(Vector3, Vector3, float);
bool TestIntersection(Matrix projectionMatrix, Matrix viewMatrix, Matrix worldMatrix, Vector3 origin, float radius, int m_screenWidth, int m_screenHeight, int mouseX, int mouseY)
{
float pointX, pointY;
Matrix inverseViewMatrix, translateMatrix, inverseWorldMatrix;
Vector3 direction, rayOrigin, rayDirection;
bool intersect, result;
// Move the mouse cursor coordinates into the -1 to +1 range.
pointX = ((2.0f * (float)mouseX) / (float)m_screenWidth) - 1.0f;
pointY = (((2.0f * (float)mouseY) / (float)m_screenHeight) - 1.0f) * -1.0f;
// Adjust the points using the projection matrix to account for the aspect ratio of the viewport.
pointX = pointX / projectionMatrix._11;
pointY = pointY / projectionMatrix._22;
// Get the inverse of the view matrix.
inverseViewMatrix=XMMatrixInverse(NULL, viewMatrix);
// Calculate the direction of the picking ray in view space.
direction.x = (pointX * inverseViewMatrix._11) + (pointY * inverseViewMatrix._21) + inverseViewMatrix._31;
direction.y = (pointX * inverseViewMatrix._12) + (pointY * inverseViewMatrix._22) + inverseViewMatrix._32;
direction.z = (pointX * inverseViewMatrix._13) + (pointY * inverseViewMatrix._23) + inverseViewMatrix._33;
// Get the origin of the picking ray which is the position of the camera.
// Get the world matrix and translate to the location of the sphere.
// Now get the inverse of the translated world matrix.
inverseWorldMatrix= XMMatrixInverse(NULL, worldMatrix);
// Now transform the ray origin and the ray direction from view space to world space.
rayOrigin=XMVector3TransformCoord(origin, inverseWorldMatrix);
rayDirection=XMVector3TransformNormal(direction, inverseWorldMatrix);
// Normalize the ray direction.
rayDirection=XMVector3Normalize(rayDirection);
// Now perform the ray-sphere intersection test.
intersect = RaySphereIntersect(rayOrigin, rayDirection, radius);
if (intersect == true)
return true;
else
return false;
}
bool RaySphereIntersect(Vector3 rayOrigin, Vector3 rayDirection, float radius)
{
float a, b, c, discriminant;
// Calculate the a, b, and c coefficients.
a = (rayDirection.x * rayDirection.x) + (rayDirection.y * rayDirection.y) + (rayDirection.z * rayDirection.z);
b = ((rayDirection.x * rayOrigin.x) + (rayDirection.y * rayOrigin.y) + (rayDirection.z * rayOrigin.z)) * 2.0f;
c = ((rayOrigin.x * rayOrigin.x) + (rayOrigin.y * rayOrigin.y) + (rayOrigin.z * rayOrigin.z)) - (radius * radius);
// Find the discriminant.
discriminant = (b * b) - (4 * a * c);
// if discriminant is negative the picking ray missed the sphere, otherwise it intersected the sphere.
if (discriminant < 0.0f)
return false;
else
return true;
}
How do I create sphere
D3DSphere(float x, float y, float z, float radius, float r, float g, float b, float a)
{
this->x = x;
this->y = y;
this->z = z;
this->radius = radius;
this->shape = GeometricPrimitive::CreateSphere(radius*2.0f);
this->world = Matrix::Identity;
this->world = XMMatrixMultiply(this->world, Matrix::CreateTranslation(x, y, z));
this->index = vsphere;
d3dsphere[vsphere] = this;
vsphere++;
}
How do I call raycaster
void Game::LButtonUp(int x, int y)
{
Vector3 eye(camx, camy, camz);
Vector3 at(Vector3::Zero);
m_view = Matrix::CreateLookAt(eye, at, Vector3::UnitY);
for (int i = 0; i < vsphere; i++)
{
if (TestIntersection(m_projection, m_view, d3dsphere[i]->world, eye, d3dsphere[i]->radius, 800, 600, x, y))
{
MessageBoxW(NULL, L"LOL", L"It works", MB_OK);
break;
}
}
}
Nothing happens by clicking, but if I rotate camera, perpendicularly to XOY, sometimes, clicking near the sphere, message box appears.
Update
MessageBox appears independently on camera angle, and it seems, that it detects intersection correctly, but mirrored, relatively to the window center. For example, if sphere is at (0, window.bottom-20) point then I will get MessageBox if I click at (0, 20) point.
What if calculation of the direction of the picking ray is wrong, if it was wrote for left-handed system, and I use right-handed?
Probably, because of the right-handed system, that is used by default in DirectX Tool Kit the next section from caster
pointX = ((2.0f * (float)mouseX) / (float)m_screenWidth) - 1.0f;
pointY = (((2.0f * (float)mouseY) / (float)m_screenHeight) - 1.0f) * -1.0f;
Should be changed to
pointX = (((2.0f * (float)mouseX) / (float)m_screenWidth) - 1.0f) * -1.0f;
pointY = (((2.0f * (float)mouseY) / (float)m_screenHeight) - 1.0f);
Important
That code also will work wrong because of depth independence, i.e. you may select sphere that is situated behind the sphere you clicking. For solve that I changed the code:
float distance3(float x1, float y1, float z1, float x2, float y2, float z2)
{
float dx=x1-x2;
float dy=y1-y2;
float dz=z1-z2;
return sqrt(dx*dx+dy*dy+dz*dz);
}
void Game::LButtonUp(int x, int y)
{
Vector3 eye(camx, camy, camz);
Vector3 at(Vector3::Zero);
m_view = Matrix::CreateLookAt(eye, at, Vector3::UnitY);
int last_index=-1;
float last_distance=99999.0f;//set the obviously highest value, may happen in your scene
for (int i = 0; i < vsphere; i++)
{
if (TestIntersection(m_projection, m_view, d3dsphere[i]->world, eye, d3dsphere[i]->radius, 800, 600, x, y))
{
float distance=distance3(camx,camy,camz, d3dsphere[i]->x, d3dsphere[i]->y, d3dsphere[i]->z);
if(distance<last_distance)
{
last_distance=distance;
last_index=i;
}
}
}
d3dsphere[last_index];//picked sphere
}
I'm trying to create a rather simple game which largely involves drawing circles with SDL2. I discovered SDL lacks and built-in method to draw circles to an SDL_Renderer, but upon searching for a method, I discovered this helpful answer which details using the Midpoint Circle Algorithm to accomplish this. Since I wanted a filled circle, I wrote a rather simple function that just draws a lot of slightly smaller circles to give the appearance of a filled circle. Unfortunately, this resulted in circles being drawn with gaps that form a sort of 'X' pattern on the circle, as shown:
Here is my draw_hollow_circle function:
void draw_hollow_circle(SDL_Renderer *renderer, int centerx, int centery, int radius)
{
// Draws a hollow circle with the given position and radius
const int diameter = (radius * 2);
int x = radius - 1;
int y = 0;
int tx = 1;
int ty = 1;
int error = tx - diameter;
while (x >= y)
{
// Each renders an octant of the circle
SDL_RenderDrawPoint(renderer, centerx + x, centery + y);
SDL_RenderDrawPoint(renderer, centerx + x, centery - y);
SDL_RenderDrawPoint(renderer, centerx - x, centery + y);
SDL_RenderDrawPoint(renderer, centerx - x, centery - y);
SDL_RenderDrawPoint(renderer, centerx + y, centery - x);
SDL_RenderDrawPoint(renderer, centerx + y, centery + x);
SDL_RenderDrawPoint(renderer, centerx - y, centery - x);
SDL_RenderDrawPoint(renderer, centerx - y, centery + x);
if (error <= 0)
{
++y;
error += ty;
ty += 2;
}
if (error > 0)
{
--x;
tx += 2;
error += (tx - diameter);
}
}
}
And here is my draw_circle function:
void draw_circle(SDL_Renderer *renderer, int x, int y, int radius, int r, int g, int b)
{
// Draws a filled circle with the given position, radius, and color
SDL_SetRenderDrawColor(renderer, r, g, b, SDL_ALPHA_OPAQUE);
// Draw a lot of slightly smaller hollow circles to give the impression of a filled circle
while (radius >= 0)
{
draw_hollow_circle(renderer, x, y, radius);
--radius;
}
}
Now, this is rather annoying, and I would like a method of avoiding such gaps and getting just a pure red circle, but I have unfortunately not been able to find any method of doing so. I tried a different method involving drawing many radii going from the center of the circle to the edge, but this resulted in a similar problem, albeit with the gaps in slightly different places. Any type of answer would be fine, be it an algorithm better suited for filled circles, an error in the math of my code, etc.
The holes are artifacts of round-off errors. Precise positioning of each point would use real numbers (think floating point), but pixel coordinates must be integers, hence the rounding. Yes, you get similar artifacts when drawing diagonal lines for a similar reason. The only lines that could be drawn without rounding of some sort are horizontal, vertical, those with slope +1, and those with slope −1.
A simple approach to fill the circle is to draw rectangles instead of points. Each iteration of the loop in draw_hollow_circle draws eight points. The first four would be the corners of one rectangle, while the second four form another rectangle. Try drawing those two rectangles instead of the eight points. (You no longer need to iterate over radii.)
(Stick to fully opaque colors for this since many of the points will be drawn multiple times. That would interfere with partial transparency.)
You can connect the points on the circle circumference with either horizontal or vertical lines to achieve a filled circle. This does not create overlap like the method described by #JaMit, so blending should be possible:
void fill_circle(SDL_Renderer *renderer, int centerX, int centerY, int radius) {
const int diameter = (radius * 2);
int x = (radius - 1);
int y = 0;
int tx = 1;
int ty = 1;
int error = (tx - diameter);
while (x >= y)
{
// top
SDL_RenderDrawLine(renderer, centerX - y, centerY - x, centerX + y, centerY - x);
// top-center piece
SDL_RenderDrawLine(renderer, centerX - x, centerY - y, centerX + x, centerY - y);
// lower-center piece
SDL_RenderDrawLine(renderer, centerX - x, centerY + y, centerX + x, centerY + y);
// lower piece
SDL_RenderDrawLine(renderer, centerX - y, centerY + x, centerX + y, centerY + x);
if (error <= 0)
{
++y;
error += ty;
ty += 2;
}
if (error > 0)
{
--x;
tx += 2;
error += (tx - diameter);
}
}
}
You can comment out the draw-line statements, one-by-one, to see the effects.
So I have this piece of code, which pretty much draws various 2D textures on the screen, though there are multiple sprites that have to be 'dissected' from the texture (spritesheet). The problem is that rotation is not working properly; while it rotates, it does not rotate on the center of the texture, which is what I am trying to do. I have narrowed it down to the translation being incorrect:
glTranslatef(x + sr->x/2 - sr->w/2,
y + sr->y/2 - sr->h/2,0);
glRotatef(ang,0,0,1.f);
glTranslatef(-x + -sr->x/2 - -sr->w/2,
-y + -sr->y/2 - -sr->h/2,0);
X and Y is the position that it's being drawn to, the sheet rect struct contains the position X and Y of the sprite being drawn from the texture, along with w and h, which are the width and heights of the 'sprite' from the texture. I've tried various other formulas, such as:
glTranslatef(x, y, 0);
The below three switching the negative sign to positive (x - y to x + y)
glTranslatef(sr->x/2 - sr->w/2, sr->y/2 - sr->h/2 0 );
glTranslatef(sr->x - sr->w/2, sr->y - sr->h/2, 0 );
glTranslatef(sr->x - sr->w, sr->y - sr->w, 0 );
glTranslatef(.5,.5,0);
It might also be helpful to say that:
glOrtho(0,screen_width,screen_height,0,-2,10);
is in use.
I've tried reading various tutorials, going through various forums, asking various people, but there doesn't seem to be a solution that works, nor can I find any useful resources that explain to me how I find the center of the image in order to translate it to '(0,0)'. I'm pretty new to OpenGL so a lot of this stuff takes awhile for me to digest.
Here's the entire function:
void Apply_Surface( float x, float y, Sheet_Container* source, Sheet_Rect* sr , float ang = 0, bool flipx = 0, bool flipy = 0, int e_x = -1, int e_y = -1 ) {
float imgwi,imghi;
glLoadIdentity();
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D,source->rt());
// rotation
imghi = source->rh();
imgwi = source->rw();
Sheet_Rect t_shtrct(0,0,imgwi,imghi);
if ( sr == NULL ) // in case a sheet rect is not provided, assume it's width
//and height of texture with 0/0 x/y
sr = &t_shtrct;
glPushMatrix();
//
int wid, hei;
glGetTexLevelParameteriv(GL_TEXTURE_2D,0,GL_TEXTURE_WIDTH,&wid);
glGetTexLevelParameteriv(GL_TEXTURE_2D,0,GL_TEXTURE_HEIGHT,&hei);
glTranslatef(-sr->x + -sr->w,
-sr->y + -sr->h,0);
glRotatef(ang,0,0,1.f);
glTranslatef(sr->x + sr->w,
sr->y + sr->h,0);
// Yeah, out-dated way of drawing to the screen but it works for now.
GLfloat tex[] = {
(sr->x+sr->w * flipx) /imgwi, 1 - (sr->y+sr->h *!flipy )/imghi,
(sr->x+sr->w * flipx) /imgwi, 1 - (sr->y+sr->h * flipy)/imghi,
(sr->x+sr->w * !flipx) /imgwi, 1 - (sr->y+sr->h * flipy)/imghi,
(sr->x+sr->w * !flipx) /imgwi, 1 - (sr->y+sr->h *!flipy)/imghi
};
GLfloat vertices[] = { // vertices to put on screen
x, (y + sr->h),
x, y,
(x +sr->w), y,
(x +sr->w),(y +sr->h)
};
// index array
GLubyte index[6] = { 0,1,2, 2,3,0 };
float fx = (x/(float)screen_width)-(float)sr->w/2/(float)imgwi;
float fy = (y/(float)screen_height)-(float)sr->h/2/(float)imghi;
// activate arrays
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
// pass verteices and texture information
glVertexPointer(2, GL_FLOAT, 0, vertices);
glTexCoordPointer(2, GL_FLOAT, 0, tex);
glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_BYTE, index);
glDisableClientState(GL_VERTEX_ARRAY);
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
glPopMatrix();
glDisable(GL_TEXTURE_2D);
}
Sheet container class:
class Sheet_Container {
GLuint texture;
int width, height;
public:
Sheet_Container();
Sheet_Container(GLuint, int = -1,int = -1);
void Load(GLuint,int = -1,int = -1);
float rw();
float rh();
GLuint rt();
};
Sheet rect class:
struct Sheet_Rect {
float x, y, w, h;
Sheet_Rect();
Sheet_Rect(int xx,int yy,int ww,int hh);
};
Image loading function:
Sheet_Container Game_Info::Load_Image(const char* fil) {
ILuint t_id;
ilGenImages(1, &t_id);
ilBindImage(t_id);
ilLoadImage(const_cast<char*>(fil));
int width = ilGetInteger(IL_IMAGE_WIDTH), height = ilGetInteger(IL_IMAGE_HEIGHT);
return Sheet_Container(ilutGLLoadImage(const_cast<char*>(fil)),width,height);
}
Your quad (two triangles) is centered at:
( x + sr->w / 2, y + sr->h / 2 )
You need to move that point to the origin, rotate, and then move it back:
glTranslatef ( (x + sr->w / 2.0f), (y + sr->h / 2.0f), 0.0f); // 3rd
glRotatef (0,0,0,1.f); // 2nd
glTranslatef (-(x + sr->w / 2.0f), -(y + sr->h / 2.0f), 0.0f); // 1st
Here is where I think you are getting tripped up. People naturally assume that OpenGL applies transformations in the order they appear (top-to-bottom), that is not the case. OpenGL effectively swaps the operands everytime it multiplies two matrices:
M1 x M2 x M3
~~~~~~~
(1)
~~~~~~~~~~
(2)
(1) M2 * M1
(2) M3 * (M2 * M1) --> M3 * M2 * M1 (row-major / textbook math notation)
The technical term for this is post-multiplication, it all has to do with the way matrices are implemented in OpenGL (column-major). Suffice it to say, you should generally read glTranslatef, glRotatef, glScalef, etc. calls from bottom-to-top.
With that out of the way, your current rotation does not make any sense.
You are telling GL to rotate 0 degrees around an axis: <0,0,1> (the z-axis in other words). The axis is correct, but a 0 degree rotation is not going to do anything ;)
It should be of the form circle(float xcenter, float ycenter, float radius).
Using GL_TRIANGLE_FAN plop down your center point and then your perimeter vertices:
void glCircle( float x, float y, float r, bool filled = true, unsigned int subdivs = 20 ) {
if( filled ) {
glBegin( GL_TRIANGLE_FAN );
glVertex2f( x, y );
} else {
glBegin( GL_LINE_STRIP );
}
for( unsigned int i = 0; i <= subdivs; ++i ) {
float angle = i * ((2.0f * 3.14159f) / subdivs);
glVertex2f( x + r * cos(angle), y + r * sin(angle) );
}
glEnd();
}
There's a gluDisk, but it has a somewhat different signature than you've given. It always centers the disk on the origin, and expects you to use glTranslate if that's not where you want your disk. It's also a bit more versatile in other ways -- the disk it draws can have a hole in the center, which you (apparently) don't care about, as well as a "loops" parameter to draw more than one disk at a time. That makes adapting it to what you've asked for just a bit more work than you'd like:
void circle(float xcenter, float ycenter, float radius) {
GLUquadric* quad = gluNewQuadric();
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
glLoadIdentity();
glTranslatef(xcenter, ycenter);
gluDisk(quad, 0, radius, 256, 1);
glPopMatrix();
gluDeleteQuadric(quad);
}
I'd say this is right at the point that it's open to question whether it's easier to just do like #genpfault said, and draw a circular triangle-fan yourself.
I'm new to c++ 3D, so I may just be missing something obvious, but how do I convert from 3D to 2D and (for a given z location) from 2D to 3D?
You map 3D to 2D via projection. You map 2D to 3D by inserting the appropriate value in the Z element of the vector.
It is a matter of casting a ray from the screen onto a plane which is parallel to x-y and is at the required z location. You then need to find out where on the plane the ray is colliding.
Here's one example, considering that screen_x and screen_y ranges from [0, 1], where 0 is the left-most or top-most coordinate and 1 is right-most or bottom-most, respectively:
Vector3 point_of_contact(-1.0f, -1.0f, -1.0f);
Matrix4 view_matrix = camera->getViewMatrix();
Matrix4 proj_matrix = camera->getProjectionMatrix();
Matrix4 inv_view_proj_matrix = (proj_matrix * view_matrix).inverse();
float nx = (2.0f * screen_x) - 1.0f;
float ny = 1.0f - (2.0f * screen_y);
Vector3 near_point(nx, ny, -1.0f);
Vector3 mid_point(nx, ny, 0.0f);
// Get ray origin and ray target on near plane in world space
Vector3 ray_origin, ray_target;
ray_origin = inv_view_proj_matrix * near_point;
ray_target = inv_view_proj_matrix * mid_point;
Vector3 ray_direction = ray_target - ray_origin;
ray_direction.normalise();
// Check for collision with the plane
Vector3 plane_normal(0.0f, 0.0f, 1.0f);
float denominator = plane_normal.dotProduct(ray_direction);
if (fabs(denom) >= std::numeric_limits<float>::epsilon())
{
float num = plane_normal.dotProduct(ray.getOrigin()) + Vector3(0, 0, z_pos);
float distance = -(num/denom);
if (distance > 0)
{
point_of_contact = ray_origin + (ray_direction * distance);
}
}
return point_of_contact
Disclaimer Notice: This solution was taken from bits and pieces of Ogre3D graphics library.
The simplest way is to do a divide by z. Therefore ...
screenX = projectionX / projectionZ;
screenY = projectionY / projectionZ;
That does perspective projection based on distance. Thing is it is often better to use homgeneous coordinates as this simplifies matrix transformation (everything becomes a multiply). Equally this is what D3D and OpenGL use. Understanding how to use non-homogeneous coordinates (ie an (x,y,z) coordinate triple) will be very helpful for things like shader optimisations however.
One lame solution:
^ y
|
|
| /z
| /
+/--------->x
Angle is the angle between the Ox and Oz axes (
#include <cmath>
typedef struct {
double x,y,z;
} Point3D;
typedef struct {
double x,y;
} Point2D
const double angle = M_PI/4; //can be changed
Point2D* projection(Point3D& point) {
Point2D* p = new Point2D();
p->x = point.x + point.z * sin(angle);
p->y = point.y + point.z * cos(angle);
return p;
}
However there are lots of tutorials on this on the net... Have you googled for it?