>: CG Forums on 3dtotal - The best forums for CG artists :.
threedy forums home
 


top-table-gradient
Go Back   3DTotal Forums > Archives > Archives > Scripting & coding
bottom-table-gradient

 
 
Thread Tools Display Modes
14211 rads test
Prev Previous Post   Next Post Next
Old 22-11-2004, 02:38 PM   #1
poolstok
Registered User
 
Join Date: Nov 2004
Location: Pretoria, South Africa
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to poolstok
Connecting 2 points in 3D space

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
poolstok is offline   Reply With Quote
 


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT. The time now is 06:36 AM.


Powered by vBulletin®
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
all images displayed on this site are copyright the original artists and may not be reproduced, copied or published elsewhere without their express permission