View Full Version : Drawing a point in a plane

Exoide

01-11-2010, 10:19 AM

Hi there,

I wanna create a polygon that lies into the plane that intersect the base vectors at 1 unit.

What I need is a function like this:

struct Vector3

{

double x, y, z;

};

Vector3 PutPixelInPlane(planeX, planeY)

{

// Get the base vectors from the current Model-View matrix

// Calculate the plane that intersect each base vector at 1 unit

// Return the position of the point at planeX, planeY in the OpenGL coordinate system

}

Can someone give me an idea about how to do it?

Thank you.

DmitryM

01-11-2010, 10:57 AM

return Vector3(planeX, planeY, 1-planeX-planeY);

Exoide

01-11-2010, 01:09 PM

Hi Dmitri,

Thank you for your answer but I didn't explain myself very well in my post.

In my previous post the arguments for the function "planeX" and "planeY" are in fact the point's coordinates that relies in such plane.

And I need the function return to me the position of that point in the absolute coordinate system.

In this way I don't have to rotate nor translate the model-view matrix that must be always the identity matrix.

Thank you once again.

DmitryM

01-11-2010, 03:08 PM

"planeX" and "planeY" are in fact the point's coordinates that relies in such plan

What do you mean by "relies"? What coordinate system are these values in?

Exoide

01-12-2010, 05:34 AM

OK, let me tell you the whole history.

I need to create a circle using the current position of the "coordinate axes" (base vectors of the coordinate system) of the model-view matrix, I mean, you can do a lot of rotations and translations and then create a circle in the current position of the coordinate axes.

To create the circle I use the following formula for the XY plane

glVertexd(cos(x) * radius, sin(y) * radius, 0);

As you can see I'm working with only two coordinates and it's OK. The problem arises when I do some rotations to draw the circle in a different plane, in this case I need to set every circle's point in the three coordinates (x, y, z) but I only have the cos(x) and sin(y) so I need to know what's the value of Z for each point.

That's why I say that I've a plane (the plane where the circle will be drawn) so having a plane I just need to refer to a point in that plane as (X, Y) but I want to know where it's exactly located in the default OpenGL's coordinate system, I mean the equivalent position of that point for the identity matrix of the model-view.

The main idea is to do all the rotations and translations to easily locate and create the circle (and the other types of shapes) but create their vertices referring to the Gl's identity matrix so every time I need to render the scene I don't have to change the GL's model-view matrix to render each object.

So resuming what I need?

I need a function that receive the two coordinates of a point in the current plane and it returns the three coordinates for that point respect to the GL's identity matrix for the model-view.

Something like this:

struct Vector3

{

double x, y, z;

};

Vector3 PutPixelInPlane(point_PosX_inPlane, point_PosY_inPlane)

{

// Get the base vectors from the current Model-View matrix

// Calculate the plane that intersect each base vector at 1 unit

// Return the position of the point at point_PosX_inPlane, point_PosY_inPlane respect to the Gl's identity matrix coordinate system

}

Of course, if there's another way to do it let me know. This is just the way I see to solve the problem.

Thank you.

DmitryM

01-12-2010, 06:11 AM

alright then:

return (ModelViewMatrix * Vector4(point_PosX_inPlane, point_PosY_inPlane, 0,1)).Xyz;

This is a matrix 4x4 multiply on a vector 4x1 given a vector result.

The matrix represents model->world transformations, and point_*_inPlane are in the local space, so the multiplication gives you world-space coordinates (what you call "referring to the Gl's identity matrix").

Exoide

01-12-2010, 09:33 AM

Hi Dmitry,

I see your point! The plane you're using as reference for the local transformations is the XY plane. That's why your answer is so simple.

It works!!!!

My error was from the start. For me the reference plane is the plane that intersect each base vector at its length. As you can see in that way the answer become more complex and in general everything become more complex.

I've learned a very good lesson with this problem because I was wrong in the way I saw the problem.

Thank you very very very much once again for your help.

Powered by vBulletin® Version 4.2.3 Copyright © 2017 vBulletin Solutions, Inc. All rights reserved.