MoveEntity improvement

Blitz3D Forums/Blitz3D Programming/MoveEntity improvement

hello!

for my software rendered 3d engine i am looking for a MoveEntity() improvement!

this is what i got yet:

Function rMoveEntity(ent, x#, y#, z#)
re.rEntity = Object.rEntity(ent)
re\x# = re\x# + Cos(re\pitch#) * Cos(re\yaw#) * x#
re\y# = re\y# + Cos(re\pitch#) * Sin(re\yaw#) * y#
re\z# = re\z# + Sin(re\pitch#) * z#
End Function


but it doesnt work :(

Try to send the rEntity object itself as a parameter:
Function rMoveEntity(re.rEntity, x#, y#, z#)

And move the mesh itself too to see any result:
PositionEntity re\ent, x#, y#, z#

Try to send the rEntity object itself as a parameter:
Function rMoveEntity(re.rEntity, x#, y#, z#)

this doesnt make sense, because the point is not that the object = Null

And move the mesh itself too to see any result:
PositionEntity re\ent, x#, y#, z#

???

Ok, I didn't understand it properly. What is 'ent' ?

the entity.
my problem is the calculation of the coordinates, and no other...

I hope this does make any sense then: :)
	rx# = rx# + (Cos(pitch#) * z + Sin(yaw) * x)
	ry# = ry# + (Sin(pitch#) * z + Cos(roll) * y)
	rz# = rz# + (Cos(yaw) * x + Sin(roll) * y)


hm, well, it is a lil bit better than my b*llsh*t, but it doesnt work yet sry :(...

Yes, you are right, I thought of it too easy. After a few more tries, it now uses only the Yaw, but in a correct way.
Using the Pitch and Roll should sort or less go in the same way, only using X,Y and Y,Z.
I use now Yaw and Yaw+90 to calculate the direction. Maybe there is an easier way, I don't know.
; Createcube Example
; ------------------

Graphics3D 640,480
SetBuffer BackBuffer()

camera=CreateCamera()

light=CreateLight()
RotateEntity light,90,0,0

; Create cube
cube=CreateCube()

PositionEntity cube,0,0,5

While Not KeyDown( 1 )

If KeyDown(203) Then TurnEntity cube, 0, 1, 0
If KeyDown(205) Then TurnEntity cube, 0, -1, 0

If KeyDown(200) Then iMoveEntity cube, -0.0, 0, -0.1
If KeyDown(208) Then iMoveEntity cube, +0.0, 0, +0.1

RenderWorld
Flip
Wend

End

Function iMoveEntity(mesh, x#, y#, z#)

		rx# = EntityX(mesh)
		ry# = EntityY(mesh)
		rz# = EntityZ(mesh)
		
		;1
		yaw# = EntityYaw(mesh)
		
	rx# = rx# + (Cos(yaw# + 90) * z)
	rz# = rz# + (Sin(yaw# + 90) * z)
	
	rx# = rx# + (Cos(yaw#) * x)
	rz# = rz# + (Sin(yaw#) * x)

	PositionEntity mesh, rx, ry, rz
	
End Function

By the way, how is your shadow thing coming along ?

well, thank you for help :)
if someone has got an idea to make it work like i tried in the first code in this thread...please let me know ;)

ps: the shadow system isn't doing much since the last 2 months because we dont know how to speed it up... don't hope on our system, it is just a demo and perhabs it will be a demo 4ever :(...

Why not download the minib3d module for bmax, im guessing you could work it out from their using the source cos it has those type of functions.

they are using matrices nd vectors, but not me :(

I tried and tried, but I can't. :( So I searched some more and I found this, from jfk:
  xl1#=zwww(i)*Sin(gamma)+xwww(i)*Cos(gamma)
  yl1#=ywww(i)
  zl1#=zwww(i)*Cos(gamma)-xwww(i)*Sin(gamma)

  xl2#=xl1
  yl2#=yl1*Cos(beta)-zl1*Sin(beta)
  zl2#=yl1*Sin(beta)+zl1*Cos(beta)
 
  xl3#=(yl2*Sin(alpha)+xl2*Cos(alpha))
  yl3#=(yl2*Cos(alpha)-xl2*Sin(alpha))
  zl3#=(zl2)

It is from his 3d engine in the code archives:
http://www.blitzbasic.com/codearcs/codearcs.php?code=418

well, i don't know what this is, but i have got s.th like this put into my engine, and it doesnt work :(

edit: here is what i got yet http://www.blitzbasic.com/gallery/view_pic.php?id=1384&gallery=&page=1

Today, I'm not at home. This code seems to do the right thing, but I can only get it to work on 2 angles (it is one more allready!). Here is the source:
; Createcube Example
; ------------------

Graphics3D 640,480,0,2
SetBuffer BackBuffer()

camera=CreateCamera()
;CameraZoom camera, 2.4

light=CreateLight()
RotateEntity light,90,0,0

; Create cube
cube=CreateCube()

PositionEntity cube,0,0,5

While Not KeyDown( 1 )

If KeyDown(203) Then iMoveEntity cube, -0.1, 0, 0
If KeyDown(205) Then iMoveEntity cube, +0.1, 0, 0

If KeyDown(200) Then iMoveEntity cube, -0.0, 0, -0.1
If KeyDown(208) Then iMoveEntity cube, +0.0, 0, +0.1

If KeyDown(16) Then TurnEntity cube, 0, -1, 0
If KeyDown(17) Then TurnEntity cube, 0, +1, 0

If KeyDown(18) Then TurnEntity cube, -1, 0, 0
If KeyDown(19) Then TurnEntity cube, +1, 0, 0

If KeyDown(20) Then TurnEntity cube, 0, 0, -1
If KeyDown(21) Then TurnEntity cube, 0, 0, +1

If KeyHit(30) Then
	PositionEntity cube, 0 ,0, 5
	RotateEntity cube, 0, 0, 0
End If

RenderWorld

Text 0, 0, "Cursor keys to move"
Text 0, 20, "Q/W Rotate Yaw"
Text 0, 40, "E/R Rotate Pitch"
Text 0, 60, "A reset"

Flip
Wend

End

Function iMoveEntity(mesh, x#, y#, z#)

		rx# = EntityX(mesh)
		ry# = EntityY(mesh)
		rz# = EntityZ(mesh)
		
		;1
		gamma# = EntityYaw(mesh)
		beta#  = -EntityPitch(mesh)
		alpha# = EntityRoll(mesh)

  xl1#=z#*Sin(gamma)+x#*Cos(gamma)
  yl1#=y#
  zl1#=z#*Cos(gamma)-x#*Sin(gamma)

  xl2#=xl1
  yl2#=yl1*Cos(beta)-zl1*Sin(beta)
  zl2#=yl1*Sin(beta)+zl1*Cos(beta)
 
  xl3#=(yl2*Sin(alpha)+xl2*Cos(alpha))
  yl3#=(yl2*Cos(alpha)-xl2*Sin(alpha))
  zl3#=(zl2)


	
	rx = rx + xl3
	ry = ry - yl3
	rz = rz - zl3
		
	PositionEntity mesh, rx, ry, rz
	
End Function

The third angle works, but it somehow goes in the wrong direction. This code applies each angle of rotation (pitch/yaw/roll) one by one, which is the right way to do it, at least, that is what I've read somewhere.

it doesnt :(

; Createcube Example
; ------------------

Graphics3D 640,480,0,2
SetBuffer BackBuffer()

camera=CreateCamera()
;CameraZoom camera, 2.4

light=CreateLight()
RotateEntity light,90,0,0

; Create cube
cube=CreateCube()

PositionEntity cube,0,0,5

While Not KeyDown( 1 )

	iMoveEntity camera, (KeyDown(32) - KeyDown(30)) * .2, 0, (KeyDown(31) - KeyDown(17)) * .2
	TurnEntity camera, MouseYSpeed(), -MouseXSpeed(), 0
	MoveMouse GraphicsWidth() / 2, GraphicsHeight() / 2


RenderWorld


Flip
Wend

End

Function iMoveEntity(mesh, x#, y#, z#)

		rx# = EntityX(mesh)
		ry# = EntityY(mesh)
		rz# = EntityZ(mesh)
		
		;1
		gamma# = EntityYaw(mesh)
		beta#  = -EntityPitch(mesh)
		alpha# = EntityRoll(mesh)

  xl1#=z#*Sin(gamma)+x#*Cos(gamma)
  yl1#=y#
  zl1#=z#*Cos(gamma)-x#*Sin(gamma)

  xl2#=xl1
  yl2#=yl1*Cos(beta)-zl1*Sin(beta)
  zl2#=yl1*Sin(beta)+zl1*Cos(beta)
 
  xl3#=(yl2*Sin(alpha)+xl2*Cos(alpha))
  yl3#=(yl2*Cos(alpha)-xl2*Sin(alpha))
  zl3#=(zl2)


	
	rx = rx + xl3
	ry = ry - yl3
	rz = rz - zl3
		
	PositionEntity mesh, rx, ry, rz
	
End Function


I see what you mean, it is because the three angles affect each other. When Roll=180, the Yaw works upside down. As long as the three angles are not handled correctly, the function will give strange results.

.