AlignToVector help

Blitz3D Forums/Blitz3D Beginners Area/AlignToVector help

Trek(Posted 2010) [#1]
I just want to understand what is going on with the code...I have a separate mesh for the ground and a separate mesh for cliffs to climb. I'm using TFormVector into LinePick to find the cliff when it's infront of the player. Then I use the code:

TFormVector 0, 0, 5, player, 0
LinePick EntityX(player), EntityY(player), EntityZ(player), TFormedX(), TFormedY(), TFormedZ()
AlignToVector player, PickedNX(), PickedNY(), PickedNZ(), 3, 0.1

When I do this, the player lines up with the wall, but he turns around 180 degrees. I could easily TFormVector from behind him to get around this, but I'm just wondering why it's doing this...I mean he doesn't turn upsidedown when I change the code to align to the ground below him. Any insight would be appreciated. Thanks


_Skully(Posted 2010) [#2]
Sounds like gimble lock


Guy Fawkes(Posted 2010) [#3]
sure skully, thats helpful. -.-

lol


_Skully(Posted 2010) [#4]
Gimble Lock

You would have to use Quadernions to fix it.

Better?


Guy Fawkes(Posted 2010) [#5]
no. lol. i dont speak nerd.

:P


Stevie G(Posted 2010) [#6]
Aligntovector uses quarternions internally so it can't be gimbal lock. Do you have a working example which doesn't require external media which you can post?


Ked(Posted 2010) [#7]
no. lol. i dont speak nerd.

Explain why you are on a programming forum.

(Let me know if you don't know what "programming" means. I can attempt to "cool" it up for you.)


Guy Fawkes(Posted 2010) [#8]
i said i don't SPEAK it. I never said I didn't KNOW it.


Trek(Posted 2010) [#9]
So what I'm wanting is for him to face the cliff while he's scaling it...the way it is, as you'll see, he just flips around when you hit the button.

Graphics3D 800,600

SetBuffer BackBuffer()

camera=CreateCamera()
CameraViewport camera,0,0,800,600

light=CreateLight()

Global cube
Global cone
Global land
Global cliff
Global cube_col		= 2
Global land_col		= 3
Global cliff_col	= 4
Global alignment%	= 1

Collisions cube_col, land_col, 2, 2
Collisions cube_col,cliff_col, 2, 2

cube=CreateCube()
EntityType cube, cube_col, False
EntityColor cube, 0, 80, 150
EntityRadius cube, 1.5, 1.5
PositionEntity cube, 0, 0, 10

cone=CreateCone()
PositionEntity cone, 0, 0, 13
EntityColor cone, 0, 80, 150
RotateEntity cone, 90, 0, 0
ScaleEntity cone, 1, 2, 1
EntityParent cone, cube

land=CreatePlane()
EntityPickMode land, 2
EntityType land, land_col, True
PositionEntity land, 0, -10, 0
RotateEntity land, 0, 0, -15
EntityColor land, 100, 170, 50

cliff=CreateCube()
EntityPickMode cliff, 2
ScaleEntity cliff, 10, 40, 10
EntityType cliff, cliff_col, True
RotateEntity cliff, 0, 10, -15
PositionEntity cliff, 10, 0, 40
EntityColor cliff, 80, 80, 80

While Not KeyHit(1)

	If KeyDown(17) = True Then
		MoveEntity cube, 0, 0, .5
	EndIf
	If KeyDown(31) = True Then
		MoveEntity cube, 0, 0, -.5
	EndIf
	If KeyDown(30) = True Then
		TurnEntity cube, 0, 3, 0
	EndIf
	If KeyDown(32) = True Then
		TurnEntity cube, 0, -3, 0
	EndIf

	If KeyDown(2) = True Then
		alignment = 1
	EndIf
	If KeyDown(3) = True Then
		alignment = 2
	EndIf
	TFormVector 0, 0, 3, cube, 0
	LinePick(EntityX(cube,True),EntityY(cube,True),EntityZ(cube,True),TFormedX(),TFormedY(),TFormedZ())
	If PickedEntity() = cliff Then
		If KeyDown(4) = True Then
			alignment = 3
		EndIf
	EndIf
	If alignment = 1 Then
		LinePick EntityX(cube), EntityY(cube), EntityZ(cube), 0, -1, 0, 1
		If PickedEntity() <> land Then
			TranslateEntity cube, 0, -.5, 0
		EndIf
	EndIf
	
	If alignment = 2 Then
		TFormVector 0, 1.5, 0, cube, 0
		LinePick(EntityX(cube,True),EntityY(cube,True),EntityZ(cube,True),TFormedX(),TFormedY(),TFormedZ())
		AlignToVector cube,PickedNX(),PickedNY(),PickedNZ(),2,0.1

		LinePick EntityX(cube), EntityY(cube), EntityZ(cube), 0, -1, 0, 1
		If PickedEntity() <> land Then
			TranslateEntity cube, 0, -.5, 0
		EndIf
	EndIf
	
	If alignment = 3 Then
		TFormVector 0, 0, 1.5, cube, 0
		LinePick(EntityX(cube,True),EntityY(cube,True),EntityZ(cube,True),TFormedX(),TFormedY(),TFormedZ())
		AlignToVector cube,PickedNX(),PickedNY(),PickedNZ(),3,0.1
	EndIf

	UpdateWorld
	RenderWorld

	Text 150,500,"WASD for movement"
	Text 150,515,"Press 1 for normal alignment"
	Text 150,530,"Press 2 for ground alignment"
	Text 150,545,"Press 3 while facing and close to cliff for cliff alignment"
	
	Flip

	Wend
End



Matty(Posted 2010) [#10]
Ok - the picked surface in your alignment = 3 if statement generates a set of normals (pickednx etc) which are facing away from the cliff. You are then aligning the z-axis of your cube such that it faces away from the cliff. Instead you should reverse them all (-pickednx(),-pickedny(),-pickednz()) so that the cube will point towards the cliff.

Secondly there's no guarantee your pick command will strike the cliff with such a short distance - meaning you should use the pickedentity()<>0 to check if an entity was actually picked, otherwise the pickednx() etc commands will not be the data you want.


Trek(Posted 2010) [#11]
Works for me, thanks Matty