miniB3D - request help with Camerapick

Ryan2003

New member
Tutorial Author
Joined
Jul 12, 2020
Messages
19
I am trying to use the camerapick function of miniB3D to pick an on screen entity.
When the camera is poistioned so that I have the view that I want, the pick does not work.
By changinging the camera position, I can get the pick to work, but now it does not
have the view that I want.
How can I have the view that I want and have picking work?

cam.PositionEntity 16, 8, 0 ' this is the view I want,but pick does not work
'cam.PositionEntity 0, 0, 0 ' this one pick works, but not the desired view
code_language.cerberus:
Import minib3d

Function Main()
    New Game
End

Class Game Extends App
    
    Field cam:TCamera
    
    Field light:TLight
    
    Field hexcell:TEntity = CreateCylinder(6)

    Field yTiles:Int = 4' Number of tiles on the y axis
    Field xTiles:Int = 4' Number of tiles on the x axis
    Field totalTiles:Int
    Field length:Float = 1.025    'Length of the hexagon so we can calculate the spacing between tiles

    Field A:Float
    Field B:Float
    Field C:Float
    
    Field coord:Float[]
    
    Method OnCreate()
    
        SetUpdateRate 30
        SetRender()

        totalTiles = yTiles * xTiles
        C = length
        A = Sin(30) * C
        B = Sin(60) * C
        coord = coord.Resize(totalTiles * 2)
        
        cam = CreateCamera()
        cam.CameraClsColor(0, 0, 80)
        cam.PositionEntity 16, 8, 0    ' this is the view I want,but pick does not work
        'cam.PositionEntity 0, 0, 0    ' this one pick works, but not the desired view
        
        hexcell.PositionEntity(5, 0, 0)
        hexcell.ScaleEntity(1.0, 0.3, 1.0)
        cam.PointEntity(hexcell)
        
        light = CreateLight(1)
        light.PositionEntity(10, 0, 7)
        light.RotateEntity(90, 0, 0)
    
        'Wireframe(True)
    
        'Calculate tile positions
        Local k:Int = 0
        For Local i:= 1 To yTiles
            For Local j:= 1 To xTiles
        
                If (i Mod 2)  Then
                    'store the center pixel
                    coord[k] = j * (B * 2) + B
                    k = k + 1
                    coord[k] = C + i * (A + C) - 5
                    k = k + 1
                Else
            
                    'store the center pixel
                    coord[k] = j * (B * 2) + B + B
                    k = k + 1
                    coord[k] = C + i * (A + C) - 5
                    k = k + 1
                EndIf
            Next
        Next
        
        ' place the hexagons
        Local x:Float = 0
        Local z:Float = 0
        Local j:Int = 0
        For Local i:= 0 To totalTiles - 1
            Local tile:TEntity = CopyEntity(hexcell)
            tile.EntityPickMode(2)
            x = coord[j]
            j = j + 1
            z = coord[j]
            j = j + 1
            tile.PositionEntity(x, 0.0, z)
        Next
        
        hexcell.EntityAlpha(0)' hide the orginal hexagon
        
    End
    
    Method OnUpdate()
    
        If KeyHit(KEY_CLOSE) Or KeyHit(KEY_ESCAPE) Then Error ""
        
        
        If TouchDown(0)
            Local e:TEntity = cam.CameraPick(TouchX(), TouchY())
            If Not e Then Print "null pick" Else Print "hex picked"
        EndIf
        
        UpdateWorld()

    End
    
    Method OnRender()

        RenderWorld()   
        
    End

End
View I want:
1597186323942.png
But Picking does not work.
 
Top Bottom