Problem Syncing Functionalities Between Blitz3D Variants

Started by RonTek, June 20, 2017, 23:47:49

Previous topic - Next topic

RonTek

I'm trying to convert a simple and short 3rd person routine to Monkey with MiniB3D. I found the Blitz3D code somewhere in the archives/forums.

Blitz3D (Original Code)

Graphics3D 800,600,0,2

Global LIGHT = CreateLight()
Global PLANE = CreatePlane()
EntityColor PLANE, 200,100,100
texture = CreateTexture( 32, 32 )
SetBuffer TextureBuffer( texture )
For y = 0 To 1
For x = 0 To 1
Color 100, 150+25*( ( x+y) Mod 2 ) , 100
Rect x*16,y*16,16,16,1
Next
Next
SetBuffer BackBuffer()
ScaleTexture texture, 50,50
EntityTexture PLANE, texture
FreeTexture texture

Global CUBE = CreateCube() : FitMesh CUBE, -2,0,-2,4,10,4
Tmp = CreateCube() 
FitMesh Tmp, -1,7,2,2,2,2 :
AddMesh Tmp, CUBE : FreeEntity Tmp
Global TARGET = CreatePivot()

Global CAMERApivot = CreatePivot()
Global CAMERA = CreateCamera( CAMERApivot )
PositionEntity CAMERA, 0,50,-50
PointEntity CAMERA , CAMERApivot

CameraRange CAMERA,.001,2000


While Not KeyDown(1)

PositionEntity CAMERApivot , EntityX( CUBE ) , 0, EntityZ( CUBE )
TurnEntity CAMERApivot, 0 , KeyDown(31) - KeyDown(30) , 0

;move relative to camera
Mx# = KeyDown(205) - KeyDown(203)
Mz# = KeyDown(200) - KeyDown(208 )

If Mx <> 0 Or Mz <> 0
;move relative to camera
TFormVector Mx, 0, Mz , CAMERApivot , 0
TranslateEntity CUBE, TFormedX(), 0, TFormedZ()
;turn relative to movement
PositionEntity TARGET, EntityX( CUBE ) + TFormedX() , 0, EntityZ( CUBE ) + TFormedZ()
TurnEntity CUBE, 0 , DeltaYaw( CUBE, TARGET ) * .25, 0
EndIf

RenderWorld()
Flip

Wend



Not getting the exact results on Monkey, I tried checking it with BlitzMax MiniB3D, but I'm getting a blank screen on MiniB3D (BlitzMax) so I switched to OpenB3D for testing.


MiniB3D/OpenB3D (BlitzMax)

'Import sidesign.minib3d
Framework Openb3d.B3dglgraphics
Graphics3D 800,600,0,2

Local Light1:TLight = CreateLight(1)
Local Plane:TMesh = CreateCube()
EntityColor Plane, 200,100, 100
ScaleEntity Plane,2000,1.0,2000

Local Cube:TMesh = CreateCube()
FitMesh Cube ,-2,0,-2,4,10,4
Local Tmp:TMesh = CreateCube()
FitMesh Tmp, -1,7,2,2,2,2
AddMesh Tmp , Cube
EntityColor Cube,255,0,0
FreeEntity Tmp
Local Target:TPivot = CreatePivot()

Local CamPivot:TPivot = CreatePivot()
Local Cam:TCamera = CreateCamera(CamPivot)
PositionEntity Cam, 0,50,-50
PointEntity Cam, CamPivot

CameraRange Cam, .001 , 2000

While Not KeyDown(KEY_ESCAPE)

PositionEntity CamPivot, EntityX( Cube ) , 0, EntityZ( Cube )
TurnEntity CamPivot, 0, KeyDown(KEY_S) - KeyDown(KEY_A) , 0

'move relative To Cam
Mx# = KeyDown(KEY_RIGHT) - KeyDown(KEY_LEFT)
Mz# = KeyDown(KEY_UP) - KeyDown(KEY_DOWN)

If Mx <> 0 Or Mz <> 0
'move relative To Cam
TFormVector Mx, 0, Mz , CamPivot , Cube
TranslateEntity Cube, TFormedX(), 0, TFormedZ()
'turn relative To movement
PositionEntity Target, EntityX( Cube ) + TFormedX() , 0, EntityZ( Cube ) + TFormedZ()
TurnEntity Cube, 0 , DeltaYaw( Cube, Target ) * .25, 0
EndIf

RenderWorld
Flip 0


Wend


My target conversion here..

Monkey-X (MiniB3D)


Import minib3d.opengl.opengles20
'Import minib3d

Function Main()
New Game
End

Class Game Extends App

Field cam:TCamera

Field campivot:TPivot

Field light:TLight
Field cube:TMesh, ground:TMesh
Field tmp:TMesh

Field target:TPivot

Field Mx:Float = 0.0
Field Mz:Float = 0.0

Field txt:TText

' used by fps code
Field old_ms:Int
Field renders:Int
Field fps:Int

Field a:Float=0, dir:Int=0, oldTouchX:Int, oldTouchY:Int, touchBegin:Int, lr#, ud#
Field anim_time:Int

Field init_gl:Bool = False

Method OnCreate()

SetRender()
SetUpdateRate 60

End

Method Init()

If init_gl Then Return

init_gl = True

light=CreateLight(1)
light.PositionEntity 300,300,300

cube=CreateCube()
cube.EntityColor(255,0,0)
FitMesh cube, -2,0,-2,4,10,4
tmp=CreateCube() 
FitMesh tmp, -1,7,2,2,2,2
AddMesh tmp, cube
FreeEntity tmp
target=CreatePivot()

campivot = CreatePivot()
cam = CreateCamera( campivot )
cam.CameraClsColor(0,0,80)
cam.PositionEntity 0,50,-50
PointEntity cam, campivot

CameraRange cam,.001,2000


CameraFogColor cam,255,255,255

txt = TText.CreateText2D()
'txt.NoSmooth()

ground = CreateGrid(10,10)
ground.EntityColor(0,255,0)
ground.ScaleEntity(20,1.0,20)

old_ms=Millisecs()

'Wireframe(True)

Print "main: init done"
End

Method OnUpdate()

If KeyHit(KEY_CLOSE) Or KeyHit(KEY_ESCAPE) Then Error ""

If Not init_gl Then Init(); Return


PositionEntity campivot, EntityX( cube ) , 0, EntityZ( cube )
TurnEntity campivot, 0 , KeyDown(KEY_S) - KeyDown(KEY_A) , 0


txt.SetText(fps+" fps ~nhow are you")
txt.HideEntity()
txt.Draw(0,0)

Mx = KeyDown(KEY_RIGHT) - KeyDown(KEY_LEFT)
Mz = KeyDown(KEY_UP) - KeyDown(KEY_DOWN)

If Mx <> 0 Or Mz <> 0
'move relative to camera
TFormVector Mx, 0, Mz, campivot, cube
TranslateEntity cube, TFormedX(), 0, TFormedZ()
'turn relative to movement
PositionEntity target, EntityX( cube ) + TFormedX() , 0, EntityZ( cube ) + TFormedZ()
TurnEntity cube, 0 , DeltaYaw( cube, target ) * .25, 0
EndIf


' calculate fps
If Millisecs()-old_ms >= 1000
old_ms=Millisecs()
fps=renders
renders=0
Endif

'UpdateWorld()
End

Method OnRender()

RenderWorld()
renders=renders+1

End

End



It seems it's not properly translated given the same commands presented here or maybe I'm missing some extra steps to make it work as intended. I would just like to make the conversion from Blitz3D to MonkeyX (MiniB3D)