Local 'Up/ Down' 'For/Aft' and 'Port/Starboard'

Blitz3D Forums/Blitz3D Programming/Local 'Up/ Down' 'For/Aft' and 'Port/Starboard'

_PJ_(Posted 2004) [#1]
Haylp!

I am trying to create a 3D radar (as per Elite), but I am having real difficulty figuring out the relative positions of objects with regards to the Player ship/camera. The Player ship/camera can move and turn freely in 3D...

There was some radar code in the archives, but it wan't very clear to me :/

Can anyone help?


Klaas(Posted 2004) [#2]
tformpoint should do that

source is 0 if the other objects are not parentet, target should be the player
x,y,z is the position of an object
tformpoint(x,y,z,source,target)
tformedx,tformedy,tformedz is then the relativ position to the player


_PJ_(Posted 2004) [#3]
Thanks! that was so quick - I'll give it a try now!


_PJ_(Posted 2004) [#4]
Okay...I've made a little test-prog, but it doesn't seem to work correctly. The 'radar' is near the bottom in the middle, and the lines' length should show the 'height' above or below the ship of the target. The basics work, but when the ship rotates, the radar should reflect this...any ideas where I'm going wrong?

(I'm not sure about the TFormPoint(x,y,z,source,target) )

Graphics3D 800,600,32,0
SetBuffer BackBuffer()

lighting=CreateLight(2)

PositionEntity lighting,-20,20,-30

ship=CreateCone(3,1)
ScaleMesh ship,2,5,1
RotateMesh ship,-90,180,0

red=CreateCube()
blue=CreateCube()
green=CreateCube()

EntityColor red,255,0,0
EntityColor green,0,255,0
EntityColor blue,0,0,255

cam=CreateCamera()

MoveEntity cam,0,0,-20
PointEntity cam,ship

PositionEntity red,Rand(-10,10),Rand(-10,10),Rand(-10,10)
PositionEntity blue,Rand(-10,10),Rand(-10,10),Rand(-10,10)
PositionEntity green,Rand(-10,10),Rand(-10,10),Rand(-10,10)

While Not KeyDown(1)

If KeyDown(208) Then TurnEntity ship,5,0,0
If KeyDown(200) Then TurnEntity ship,-5,0,0

If KeyDown(203) Then TurnEntity ship,0,-5,0
If KeyDown(205) Then TurnEntity ship,0,-5,0

If MouseDown(1) MoveEntity ship,0,0,1

UpdateWorld
RenderWorld

;Radar
Color 255,255,255
Rect 400,500,3,3,0

;Red Dot
TFormPoint (EntityX(ship),EntityY(ship),EntityZ(ship),0,red) 
red_relativeX=TFormedX();-EntityX(ship)
red_relativey=TFormedY();-EntityY(ship)
red_relativez=TFormedZ();-EntityZ(ship)
Color 255,0,0 
Rect 400+red_relativeX,500+red_relativeZ,1,red_relativeY,1


;Green Dot
TFormPoint (EntityX(ship),EntityY(ship),EntityZ(ship),0,green) 
green_relativeX=TFormedX();-EntityX(ship)
green_relativey=TFormedY();-EntityY(ship)
green_relativez=TFormedZ();-EntityZ(ship)
Color 0,255,0 
Rect 400+green_relativeX,500+green_relativeZ,1,green_relativeY,1


;Blue Dot
TFormPoint (EntityX(ship),EntityY(ship),EntityZ(ship),0,blue) 
blue_relativeX=TFormedX();-EntityX(ship)
blue_relativey=TFormedY();-EntityY(ship)
blue_relativez=TFormedZ();-EntityZ(ship)
Color 0,0,255 
Rect 400+blue_relativeX,500+blue_relativeZ,1,blue_relativeY,1


Flip

Wend

End



skidracer(Posted 2004) [#5]
try the following:

;Red Dot
TFormPoint 0,0,0,red,ship
red_relativeX=TFormedX()*5
red_relativey=TFormedY()*5
red_relativez=TFormedZ()*5
Color 255,0,0 
Rect 400+red_relativeX,500+red_relativeZ,1,red_relativeY,1


The TFormPoint command is asking where is red's local coordinate 0,0,0 in ship's local space. I have multiplied the result so you can see the effect. However as the Rect command doesn't like negative heights you can only see the result when the target dot is above the ship.


Stevie G(Posted 2004) [#6]
You should get the tformed point from the cubes worldspace to the ships local space - you had this back to front. Also noticed you're left/right cursors were turning in the same direction too - confused me a bit.

Anyhoo, is this what your looking for??

p.s. How the f do I get this in green with black again?!


[code]

While Not KeyDown(1)

If KeyDown(208) Then TurnEntity ship,5,0,0
If KeyDown(200) Then TurnEntity ship,-5,0,0

If KeyDown(203) Then TurnEntity ship,0,-5,0
If KeyDown(205) Then TurnEntity ship,0,5,0

If MouseDown(1) MoveEntity ship,0,0,1

UpdateWorld
RenderWorld

;Radar
Color 255,255,255
Rect 400,500,3,3,0

;Red Dot
TFormPoint (EntityX(red),EntityY(red),EntityZ(red),0,ship)
red_relativeX=TFormedX()
red_relativey=TFormedY()
red_relativez=TFormedZ()
Color 255,0,0
Rect 400-red_relativeX,500-red_relativeZ,1,red_relativeY,1


;Green Dot
TFormPoint (EntityX(green),EntityY(green),EntityZ(green),0,ship)
green_relativeX=TFormedX()
green_relativey=TFormedY()
green_relativez=TFormedZ()
Color 0,255,0
Rect 400-green_relativeX,500-green_relativeZ,1,green_relativeY,1


;Blue Dot
TFormPoint (EntityX(blue),EntityY(blue),EntityZ(blue),0,ship)
blue_relativeX=TFormedX()
blue_relativey=TFormedY()
blue_relativez=TFormedZ()
Color 0,0,255
Rect 400-blue_relativeX,500-blue_relativeZ,1,blue_relativeY,1


Flip

Wend

[code/]


_PJ_(Posted 2004) [#7]
Cheers stevie - i was confused with how to actually use the TForm commands! Sorry about my cursor code - that's just my usual buggy programming :)

By the way it's [ / code ] at the end not code/ ;) Thanks!

Oh and Thanks skdiracer - I thought that the lines disappeared sometimes for apparently no reason!


_PJ_(Posted 2004) [#8]
Thanks a lot peeps, I cleaned it up, and fixed the negative-Rect command issue... Now I just gotta figure out someway to make it clear which way the 'stalks' point!

Graphics3D 800,600,32,0
SetBuffer BackBuffer()

lighting=CreateLight(2)

PositionEntity lighting,-20,20,-30

ship=CreateCone(3,1)
ScaleMesh ship,2,5,1
RotateMesh ship,-90,180,0

red=CreateCube()
blue=CreateCube()
green=CreateCube()

EntityColor red,255,0,0
EntityColor green,0,255,0
EntityColor blue,0,0,255

cam=CreateCamera()

MoveEntity cam,0,0,-20
PointEntity cam,ship

PositionEntity red,Rand(-10,10),Rand(-10,10),Rand(-10,10)
PositionEntity blue,Rand(-10,10),Rand(-10,10),Rand(-10,10)
PositionEntity green,Rand(-10,10),Rand(-10,10),Rand(-10,10)

While Not KeyDown(1) 

If KeyDown(208) Then TurnEntity ship,5,0,0 
If KeyDown(200) Then TurnEntity ship,-5,0,0 

If KeyDown(203) Then TurnEntity ship,0,5,0 
If KeyDown(205) Then TurnEntity ship,0,-5,0 

If MouseDown(1) MoveEntity ship,0,0,1 

UpdateWorld 
RenderWorld 

;Radar 
Color 255,255,255 
Rect 400,500,3,3,0 

;Red Dot 
TFormPoint (EntityX(red),EntityY(red),EntityZ(red),0,ship) 
red_relativeX=(0-TFormedX())
red_relativey=TFormedY()
red_relativez=TFormedZ()
Color 255,0,0

If red_relativeY>0 Then Rect 400-red_relativeX,500-red_relativeZ,1,red_relativeY,1 
If red_relativeY<0 Then Rect 400-red_relativeX,500-red_relativeZ+Abs(red_relativeY),1,Abs(red_relativeY),1 

;Green Dot 
TFormPoint (EntityX(green),EntityY(green),EntityZ(green),0,ship) 
green_relativeX=(0-TFormedX()) 
green_relativey=TFormedY()
green_relativez=TFormedZ()
Color 0,255,0 

If green_relativeY>0 Then Rect 400-green_relativeX,500-green_relativeZ,1,green_relativeY,1 
If green_relativeY<0 Then Rect 400-green_relativeX,500-green_relativeZ+Abs(green_relativeY),1,Abs(green_relativeY),1 


;Blue Dot 
TFormPoint (EntityX(blue),EntityY(blue),EntityZ(blue),0,ship) 
blue_relativeX=(0-TFormedX()) 
blue_relativey=TFormedY()
blue_relativez=TFormedZ()
Color 0,0,255

If blue_relativeY>0 Then Rect 400-blue_relativeX,500-blue_relativeZ,1,blue_relativeY+1,1 
If blue_relativeY<0 Then Rect 400-blue_relativeX,500-blue_relativeZ+Abs(blue_relativeY),1,Abs(blue_relativeY),1 

Flip 

Wend 

End



_PJ_(Posted 2004) [#9]
EEEK! I hear of changing local co-ordinates...does this affect the Global EntityPitch/Yaw/Roll values of my mesh? does it actutally change anything, or just return a modified value???