Jump to content
  • Advertisement
Sign in to follow this  
Lloyd040690

Simple math question

This topic is 2772 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

I have a point in space, and direction normal. I want to create a quad that faces the direction of the normal and has the point in space as its center point.
Any help is appreciated.

Share this post


Link to post
Share on other sites
Advertisement
The term you're looking for is 'billboarding'. (Google and/or a forum search should tell you the rest.)

Share this post


Link to post
Share on other sites

I though billboarding was specifically referring to a quad that faced the camera.

It usually is, but for at least one type of billboarding, it's the same problem that you're trying to solve.

Here is a thread where I described one method for aligning an object with a vector. There are several ways to solve the problem though, each with its own advantages and disadvantages; if you'd like a more specific suggestion, perhaps you could tell us what higher-level problem you're trying to solve.

Share this post


Link to post
Share on other sites

I though billboarding was specifically referring to a quad that faced the camera.


Same idea more or less, what is your up vector reference for what youre doing?

Share this post


Link to post
Share on other sites
from nvidia portal engine (coded in delphi)


p i the normal and punkt_na_plaszyznie is a point on that plane you jmmust get the distance



float __fastcall getplaneD(t3dpoint vn,t3dpoint point)
{
return -((vn.x*point.x)+(vn.y*point.y)+(vn.z*point.z));
}




TPolygon CreatePoly(t3dpoint p,t3dpoint punkt_na_plaszczyznie, float SIZE)


{
// SIZE = 16384.0;
TPolygon Result;
t3dpoint n, tmp;
float a, b, c,d;

d = getplaneD(p,punkt_na_plaszczyznie);
// Create a huge polygon on the given plane.

//Result.Count := 4;

a = abs(p.x);
b = abs(p.y);
c = abs(p.z);
if ((a >= b) && (a >= c) ) {
// Plane is mostly YZ-aligned.
Result.V[0] = triplesingletoT3DPOINT(-(p.y*-SIZE + p.z*-SIZE + d)/p.x, -SIZE, -SIZE);
Result.V[1] = triplesingletoT3DPOINT(-(p.y*SIZE + p.z*-SIZE + d)/p.x, SIZE, -SIZE);
Result.V[2] = triplesingletoT3DPOINT(-(p.y*SIZE + p.z*SIZE + d)/p.x, SIZE, SIZE);
Result.V[3] = triplesingletoT3DPOINT(-(p.y*-SIZE + p.z*SIZE + d)/p.x, -SIZE, SIZE);
}
if ( (b >= a) && (b >= c) ) {
// Plane is mostly XZ-aligned.
Result.V[0] = triplesingletoT3DPOINT(-SIZE, -(p.x*-SIZE + p.z*-SIZE +d)/p.y, -SIZE);
Result.V[1] = triplesingletoT3DPOINT(SIZE, -(p.x*SIZE + p.z*-SIZE + d)/p.y, -SIZE);
Result.V[2] = triplesingletoT3DPOINT(SIZE, -(p.x*SIZE + p.z*SIZE + d)/p.y, SIZE);
Result.V[3] = triplesingletoT3DPOINT(-SIZE, -(p.x*-SIZE + p.z*SIZE + d)/p.y, SIZE);
}
if ( (c >= a) && (c >= b) ) {
// Plane is mostly XY-aligned.
Result.V[0] = triplesingletoT3DPOINT(-SIZE, -SIZE, -(p.x*-SIZE + p.y*-SIZE + d)/p.z);
Result.V[1] = triplesingletoT3DPOINT(SIZE, -SIZE, -(p.x*SIZE + p.y*-SIZE + d)/p.z);
Result.V[2] = triplesingletoT3DPOINT(SIZE, SIZE, -(p.x*SIZE + p.y*SIZE + d)/p.z);
Result.V[3] = triplesingletoT3DPOINT(-SIZE, SIZE, -(p.x*-SIZE + p.y*SIZE + d)/p.z);

}
n = vectorcross(vectors_substract_v1minusv2(Result.V[0], Result.V[1]),
vectors_substract_v1minusv2(Result.V[2], Result.V[1]));
Result.normal = p;
Result.Count = 4;
if (Dot(p, n) <= 0 ) {
tmp = Result.V[1];
Result.V[1] = Result.V[3];
Result.V[3] = tmp;
}
return Result;
}

[/quote]

Share this post


Link to post
Share on other sites
There's an infinite number of these quads, they can rotate around this normal. You would have to have some more info or if it wouldn't matter, then something like this should work

vec3 normal;
vec3 pt;
vec2 quadDim; // dimension of quad divided by 2

// setup directions for both local axis of quad
vec3 right = random vector not equal to normal;
vec3 up = normal cross right
right = up cross normal

// set quad points
vec3 a = pt - right * quadDim.x - up * quadDim.y;
vec3 b = pt + right * quadDim.x - up * quadDim.y;

vec3 c = pt - right * quadDim.x + up * quadDim.y;
vec3 d = pt + right * quadDim.x + up * quadDim.y;

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!