mesh transform problem

Blitz3D Forums/Blitz3D Programming/mesh transform problem

The forum is locked. These are the original blitzbasic.com forums, kept so they can still be read. No new topics, replies or edits can be made here. To join in, head over to the Blitz3D+ forums.

Here's a demo of the tricky part, rotating by the right amount.
It actually turns the camera rather than a 'camera pivot' so we can see the results.
; Tap a key to step through demo. Escape quits.

; 1. random positions
; 2. aim at red
; 3. turn so green is to the right

Graphics3D 640, 480, 32, 1

p1 = CreateSphere() : EntityColor p1, 255,0,0
p2 = CreateSphere() : EntityColor p2, 0,255,0

cam = CreateCamera()
Repeat

	PositionEntity p1,  Rnd(-4,4), Rnd(-4,4), 10 + Rnd(0,5)
	PositionEntity p2,  Rnd(-4,4), Rnd(-4,4), 10 + Rnd(0,5)
	
	RenderWorld : Flip : WaitKey  ; random
	
	PointEntity cam, p1
	
	RenderWorld : Flip : WaitKey  ; aim at red
	
	TFormPoint EntityX(p2,True), EntityY(p2,True), EntityZ(p2,True), 0, cam
	angle# = ATan2( TFormedY(), TFormedX() )
	
	TurnEntity cam, 0, 0, angle      ; After this we are aiming at red sphere
	RenderWorld : Flip : WaitKey     ; with green sphere to the right.
	
Until KeyHit(1)