PDA

View Full Version : Connecting 2 points in 3D space


poolstok
22-11-2004, 03:38 PM
Hello All!

Well, I am Johan from South Africa, and this is my 1st post here.

I's studied Computer Systems Engineering yonks ago, but later decided to follow Graphics as my main focus. I ended up as the creative dude in a VR developing company. So my programming skills are a bit numbed....

Now for my problem Noboy here seem to be able to solve this.... I need to connect 2 points in 3d space - almost like a line graph.

Kewl.

As long as I move my 2 points in only 2 of the 3 dimentions - like in X and Y, or in X and Z, my code works fine. As soon as I move my point into a 3rd simantion as well, I get a deviation.

Basically what I am doing is look where the the one point is and plonk my bar there as well. Then I look where the second point is, calculate the translation and orientation from the first, and then scale my bar in that orintation for the correct lenght. The bar allways seem to be the correct lenght, but there is a bug in my orientation calculation as soon as I go into a 3rd dimetnion...

Package: EON Studio 5.0
Scripting Language: VB Script
The code:


Sub On_RunMeAllways()

'Get points coordinates
Point1Temp = Point1
Point2Temp = Point2

'calculate the offsets of the 2 points
XDif = Point2Temp(0) - Point1Temp(0)
YDif = Point2Temp(1) - Point1Temp(1)
ZDif = Point2Temp(2) - Point1Temp(2)

'calculates the lenght of the diagonal
BarLengthTemp = BarLength

BarLengthTemp(0) = 0.03
BarLengthTemp(1) = (XDif^2 + yDif^2 + ZDif^2)^(0.5)
BarLengthTemp(2) = 0.03


Angle1 = (Atn(ZDif/XDif))*(180/(22/7))
if XDif > 0 then Angle1 = Angle1 - 90
if XDif < 0 then Angle1 = Angle1 + 90

Angle2 = 0 - (Atn(YDif/XDif))*(180/(22/7))


BarHeadingTemp = BarHeading
BarHeadingTemp(0) = Angle2
BarHeadingTemp(1) = 0
BarHeadingTemp(2) = Angle1

'send lenght to bar
BarLength = BarLengthTemp

'send startpoint to bar
StartPoint = Point1Temp

'send heading to bar
BarHeading = BarHeadingTemp


end sub

Any ideas as to what is going wrong?

Thanx

Poolstok