[SOLVED] Draw line with a point and an angle

Problems building or running the engine, queries about how to use features etc.
Post Reply
User avatar
saejox
Goblin
Posts: 260
Joined: Tue Oct 25, 2011 1:07 am
x 36

[SOLVED] Draw line with a point and an angle

Post by saejox »

Hi,

I like to draw a line using a point such as Vector3(1,2,5) and an angle. Angle is in Vector3 format -- Vector3(0,1,0), Vector3(1,0,1) etc.. .--

I know how to draw line between two points, but cant figure out how to draw it with an angle.

Thanks
Last edited by saejox on Tue Oct 25, 2011 4:08 pm, edited 1 time in total.
User avatar
omniter
OGRE Contributor
OGRE Contributor
Posts: 424
Joined: Thu Mar 19, 2009 8:08 am
Location: Canada
x 44

Re: Draw line with a point and an angle

Post by omniter »

By angle, do you mean euler angles? If so, what do these euler angles describe? Please give a more detailed explanation of the desired output and its relation to the given inputs.
User avatar
saejox
Goblin
Posts: 260
Joined: Tue Oct 25, 2011 1:07 am
x 36

Re: Draw line with a point and an angle

Post by saejox »

omniter wrote:By angle, do you mean euler angles? If so, what do these euler angles describe? Please give a more detailed explanation of the desired output and its relation to the given inputs.
i want my casted ray to be drawn. i have a starting point and a vector3 direction.

given line length is 10,
start point 5,4,-2

for direction 0,1,0 ; drawline( 5,4,-2 , 5,14,-2)
for direction 1,0,0 ; drawline( 5,4,-2 , 15,4,-2)
for direction -1,0,0 ; drawline (5,4,-2 , -5,14,-2)
User avatar
saejox
Goblin
Posts: 260
Joined: Tue Oct 25, 2011 1:07 am
x 36

Re: Draw line with a point and an angle

Post by saejox »

i'm sure most of you already draw raycast line for debug purposes. thats what i want to do.
User avatar
saejox
Goblin
Posts: 260
Joined: Tue Oct 25, 2011 1:07 am
x 36

Re: Draw line with a point and an angle

Post by saejox »

found it!
never had to deal with vectors and points since freshman.

here is what did,


step 1: normalize direction vector first
step 2: magnitude is a scalar. like 5, 10. its length of the line
step 3: just call => drawline( (origin.x, origin.y, origin.z) , (origin.x + direction.x * magnitude, origin.y + direction.y * magnitude, origin.z + direction.z * magnitude) )


this way i can draw ray's with any magnitude i want.

thanks.
User avatar
omniter
OGRE Contributor
OGRE Contributor
Posts: 424
Joined: Thu Mar 19, 2009 8:08 am
Location: Canada
x 44

Re: [SOLVED] Draw line with a point and an angle

Post by omniter »

If you already know how to draw a line between two points, then this is just one extra step. If you have point A, a direction V, and a length t, then you can get point B with this:
B = A + t*norm(V)

EDIT:
Seems like you found a solution already. It looks a bit verbose though, considering you're working with Vector3s. The code should be just as simple as the equation I gave.
User avatar
saejox
Goblin
Posts: 260
Joined: Tue Oct 25, 2011 1:07 am
x 36

Re: [SOLVED] Draw line with a point and an angle

Post by saejox »

omniter wrote:If you already know how to draw a line between two points, then this is just one extra step. If you have point A, a direction V, and a length t, then you can get point B with this:
B = A + t*norm(V)

EDIT:
Seems like you found a solution already. It looks a bit verbose though, considering you're working with Vector3s. The code should be just as simple as the equation I gave.
it the same equation, mine looks long as a function call.

thank you for your reply.
User avatar
lingfors
Hobgoblin
Posts: 525
Joined: Mon Apr 02, 2007 12:18 am
Location: Sweden
x 79

Re: Draw line with a point and an angle

Post by lingfors »

saejox wrote:step 1: normalize direction vector first
step 2: magnitude is a scalar. like 5, 10. its length of the line
step 3: just call => drawline( (origin.x, origin.y, origin.z) , (origin.x + direction.x * magnitude, origin.y + direction.y * magnitude, origin.z + direction.z * magnitude) )
You know operators + and * are overloaded for vectors, right? So you could just calculate end point as

Code: Select all

Vector3 endPoint = origin + magnitude * direction;
Post Reply