Page 1 of 1

How to do raycasting/linePick using the OGRE engine?

Posted: Fri Apr 17, 2009 10:59 am
by Carlos
I don't see any function about casting a ray/a sphere from one point to another point and return the entity ID. So how to do this using the OGRE engine?

And I see that the collision system of the OGRE 3d engine is quite limited. It can't set bounding box/bounding sphere for entities.
When collision occurs, it doesn't provide any function to get collision point positions, normals and sliding points.

Why PB developers didn't make a better collision system?
It is very hard to make a 3D game without a good collision system. Very sad :(

Thanks.

Posted: Fri Apr 17, 2009 2:31 pm
by Comtois
here is a work around, i added few lines in mesmanual.pb example.
To test, use windowedScreen 800x600 and play with left and right keys.

Code: Select all

;
; ------------------------------------------------------------
;
;   PureBasic - Manul Mesh
;
;    (c) 2003 - Fantaisie Software
;
; ------------------------------------------------------------
;

#CameraSpeed = 5

IncludeFile "Screen3DRequester.pb"

Define.f KeyX, KeyY, MouseX, MouseY

If InitEngine3D()

  Add3DArchive("Data", #PB_3DArchive_FileSystem)
  
  InitSprite()
  InitKeyboard()
  InitMouse()
  
  If Screen3DRequester()
    
    
    ; The data has to be organize in this order: Vertex, Normal, Color, UVCoordinate (per vertex)
    ;
    
    ; Create a cube, manually.. See the DataSection, for more precisions
    ;
    WorldDebug(#PB_World_DebugEntity)
    CreateMesh(0, 100)
    
    SetMeshData(0, #PB_Mesh_Vertex | #PB_Mesh_Normal | #PB_Mesh_Color, ?CubeData2, 8)
    SetMeshData(0, #PB_Mesh_Face, ?CubeDataIndex, 12)
    
    CreateMaterial(0, LoadTexture(0, "clouds.jpg"))
    MaterialAmbientColor(0, #PB_Material_AmbientColors)
    
    CreateEntity(0, MeshID(0), MaterialID(0))
    EntityLocate(0,500,0,0)
    CreateEntity(1, MeshID(0), MaterialID(0))
    ;CopyEntity(0,1)
    EntityLocate(1,-500,0,0)
        
    CreateCamera(1,0,0,100,100)
    
    CreateCamera(0, 0, 0, 100, 100)
    CameraLocate(0, 0, 900, 1300)
    CameraLookAt(0,0,0,0)
    AmbientColor($FFFFFF)
    CreateSprite(0,800,600)
    Repeat
      Screen3DEvents()
      
      ClearScreen(RGB(0, 0, 0))
            
      If ExamineKeyboard()
        
        If KeyboardPushed(#PB_Key_Left)
          AngleY + 1
        ElseIf KeyboardPushed(#PB_Key_Right)
          AngleY - 1 
        EndIf

      EndIf


      RotateCamera(1, 0, AngleY, 0)
      
      InputEvent3D(400,300,1,"Test")
      entity=MousePick(1,400,300)
      If entity>-1
        x2.f=PickX()
        y2.f=PickY()
        z2.f=PickZ()
        RotateEntity(Entity,0,1,0,#PB_Relative)
      Else
        If PointPick(1,400,300)
          x2.f=PickX() * 100
          y2.f=PickY() * 100
          z2.f=PickZ() * 100        
        EndIf
      EndIf
      StartDrawing(SpriteOutput(0))
      Box(0,0,800,600,0)
      x1.f=CameraX(1)
      y1.f=CameraY(1)
      z1.f=CameraZ(1)
      LineXY(CameraProjectionX(0,x1,y1,z1),CameraProjectionY(0,x1,y1,z1),CameraProjectionX(0,x2,y2,z2),CameraProjectionY(0,x2,y2,z2),$0000FF)
      StopDrawing()

   
      RenderWorld()
      DisplayTransparentSprite(0,0,0)
      Screen3DStats()      
      FlipBuffers()
    Until KeyboardPushed(#PB_Key_Escape) Or Quit = 1
  EndIf
    
Else
  MessageRequester("Error", "The 3D Engine can't be initialized",0)
EndIf
  
End

#SQRT13 = 0.57735026

DataSection

  CubeData2:
    
    Data.f -100.0,100.0,-100.0        ; 0 position
    Data.f -#SQRT13,#SQRT13,-#SQRT13  ; 0 normal
    Data.l 255                        ; 0 colour
    Data.f 100.0,100.0,-100.0         ; 1 position
    Data.f #SQRT13,#SQRT13,-#SQRT13   ; 1 normal
    Data.l 255                        ; 1 colour
    Data.f 100.0,-100.0,-100.0        ; 2 position
    Data.f #SQRT13,-#SQRT13,-#SQRT13  ; 2 normal
    Data.l 255                        ; 2 colour
    Data.f -100.0,-100.0,-100.0       ; 3 position
    Data.f -#SQRT13,-#SQRT13,-#SQRT13 ; 3 normal
    Data.l 255                        ; 3 colour
    Data.f -100.0,100.0,100.0         ; 4 position
    Data.f -#SQRT13,#SQRT13,#SQRT13   ; 4 normal
    Data.l 255                        ; 4 colour
    Data.f 100.0,100.0,100.0          ; 5 position
    Data.f #SQRT13,#SQRT13,#SQRT13    ; 5 normal
    Data.l 255                        ; 5 colour
    Data.f 100.0,-100.0,100.0         ; 6 position
    Data.f #SQRT13,-#SQRT13,#SQRT13   ; 6 normal
    Data.l 255                        ; 6 colour
    Data.f -100.0,-100.0,100.0        ; 7 position
    Data.f -#SQRT13,-#SQRT13,#SQRT13  ; 7 normal
    Data.l 255                        ; 7 colour

  CubeDataIndex:
    Data.w 0,2,3
    Data.w 0,1,2
    Data.w 1,6,2
    Data.w 1,5,6
    Data.w 4,6,5
    Data.w 4,7,6
    Data.w 0,7,4
    Data.w 0,3,7
    Data.w 0,5,1
    Data.w 0,4,5
    Data.w 2,7,3
    Data.w 2,6,7
      
EndDataSection

Posted: Sat Apr 18, 2009 11:50 am
by Carlos
Can't run the example above.

Error: The specified #sprite is not initialized

What should be modified?

Posted: Sat Apr 18, 2009 11:58 am
by DarkDragon
Carlos wrote:Can't run the example above.

Error: The specified #sprite is not initialized

What should be modified?
You've already run the example. This is a debugger error not a compiler error.
Beside this: run it with the DirectX9 subsystem or without if you had it already enabled.

Posted: Sun Apr 19, 2009 5:22 am
by Carlos
ok, I can run the example with debugger off.

Thanks for writing the example.

Posted: Sun Apr 19, 2009 9:02 am
by DarkDragon
Carlos wrote:ok, I can run the example with debugger off.

Thanks for writing the example.
You didn't understand me. You can run the example correctly if you enable or disable the DirectX9 subsystem (You have to try it, I'm not sure anymore on which it works and on which not).

Posted: Mon Apr 20, 2009 8:07 am
by Carlos
Never mind.
I give up using Purebasic to make games.

Posted: Mon Apr 20, 2009 9:38 am
by djes
:lol: