Page 2 of 2

Re: 3D Coordinate System

Posted: Tue Dec 22, 2015 11:44 pm
by Comtois
using mesh manual should work on all system

Code: Select all

#CameraSpeed = 1

IncludeFile #PB_Compiler_Home + "examples/3d/Screen3DRequester.pb"

Define.f KeyX, KeyY, MouseX, MouseY

Macro CreateLine3D_(No, x1, y1, z1, Color1, x2, y2, z2, Color2)
   CreateMesh(No, #PB_Mesh_LineList, #PB_Mesh_Static)
   MeshVertexPosition(x1, y1, z1) 
   MeshVertexColor(Color1)
   MeshVertexPosition(x2, y2, z2) 
   MeshVertexColor(Color2) 

   FinishMesh(#False)
   
   SetMeshMaterial(No, MaterialID(1))
   AttachNodeObject(Node, MeshID(No)) 
EndMacro

If InitEngine3D()
   
  InitSprite()
  InitKeyboard()
  InitMouse()
    
  If Screen3DRequester()
    
    Add3DArchive(#PB_Compiler_Home + "examples/3d/Data/Textures", #PB_3DArchive_FileSystem)
    Add3DArchive(#PB_Compiler_Home + "examples/3d/Data/Models"  , #PB_3DArchive_FileSystem)
    
    LoadMesh(10, "axes.mesh")
    CreateMaterial(0, LoadTexture(0, "axes.png"))
    CreateEntity(0, MeshID(10), MaterialID(0))
    ScaleEntity(0, 0.1, 0.1 ,0.1)
    
     ;- Material
     CreateMaterial(1, LoadTexture(0, "White.jpg"))
     DisableMaterialLighting(1, #True)
    ; Line3D
    ;
    Node = CreateNode(#PB_Any)
    CreateLine3D_(0, 0, 0, 0, RGB(255,   0,   0), 10,  0,  0, RGB(255,   0,   0))  ; Axis X
    CreateLine3D_(1, 0, 0, 0, RGB(  0, 255,   0),  0, 10,  0, RGB(  0, 255,   0))  ; Axis Y
    CreateLine3D_(2, 0, 0, 0, RGB(  0,   0, 255),  0,  0, 10, RGB(  0,   0, 255))  ; Axis Z
        
    ; Camera
    ;
    CreateCamera(0, 0, 0, 100, 100)
    MoveCamera(0, 1, 1, 5, #PB_Absolute)
    CameraLookAt(0, 0, 0, 0)
    
     ;-Light
     CreateLight(0, RGB(255,255,255), -10, 60, 10)
     AmbientColor(RGB(90, 90, 90))
    
    Repeat
      Screen3DEvents()
      
      If ExamineMouse()
        MouseX = -MouseDeltaX() * #CameraSpeed * 0.05
        MouseY = -MouseDeltaY() * #CameraSpeed * 0.05
      EndIf
      
      If ExamineKeyboard()
      
        If KeyboardPushed(#PB_Key_Left)
          KeyX = -#CameraSpeed
        ElseIf KeyboardPushed(#PB_Key_Right)
          KeyX = #CameraSpeed
        Else
          KeyX = 0
        EndIf
        
        If KeyboardPushed(#PB_Key_Up)
          KeyY = -#CameraSpeed
        ElseIf KeyboardPushed(#PB_Key_Down)
          KeyY = #CameraSpeed
        Else
          KeyY = 0
        EndIf
        
      EndIf
       
      RotateCamera(0, MouseY, MouseX, 0, #PB_Relative)
      MoveCamera  (0, KeyX, 0, KeyY)
      
      RenderWorld()
      Screen3DStats()
      FlipBuffers()
    Until KeyboardPushed(#PB_Key_Escape) Or Quit = 1
  EndIf
    
Else
  MessageRequester("Error", "The 3D Engine can't be initialized",0)
EndIf
  
End

Re: 3D Coordinate System

Posted: Wed Dec 23, 2015 11:39 pm
by S.T.
Thank you all for sending your codes/comments.
What I am concerned about is the right-handed sense of the coordinate system not really the color. If you consider a vector multiplication like u x v = w where u is the unit vector along x and v is the unit vector along y then the product w must be along z axis. However in this coordinate system this would appear in the reverse direction and this can mess up all my calculations for visualization. So, for now I have to switch to Windows until this is corrected.

Re: 3D Coordinate System

Posted: Thu Dec 24, 2015 6:48 am
by Comtois
S.T. wrote:If you consider a vector multiplication like u x v = w where u is the unit vector along x and v is the unit vector along y then the product w must be along z axis. However in this coordinate system this would appear in the reverse direction and this can mess up all my calculations for visualization. So, for now I have to switch to Windows until this is corrected.
There was a problem with the CreateLine3D"s color which is corrected with the 5.41 release.
OGRE uses a right-handed coordinate system.on Windows/Linux and MacOS X, so your vector will be the same on all system. If not, just show an example.

About the cross-Product Ogre doc say :
As For which side the resultant vector will be on, the returned vector will be on the side from which the arc from 'this' To rkVector is anticlockwise,
e.g. UNIT_Y.crossProduct(UNIT_Z) = UNIT_X, whilst UNIT_Z.crossProduct(UNIT_Y) = -UNIT_X.

This is because OGRE uses a right-handed coordinate system.

Re: 3D Coordinate System

Posted: Fri Dec 25, 2015 10:01 pm
by S.T.
This is fixed in version 5.41
Thanks!

Re: 3D Coordinate System

Posted: Tue Mar 24, 2020 12:55 am
by IdeasVacuum
I know this is an old debate and "fixed", but the current system for the OpenGL gadget is different to that used in manufacturing industry, so it would be great if PB could allow us to set our own World Ordinate System and not have to translate from a fixed, pre-defined system.

Re: 3D Coordinate System

Posted: Tue Mar 24, 2020 8:32 pm
by Samuel
That's going into the shader territory. The opengl gadget is just a quicker way to create an opengl context. It doesn't limit you to a specific coordinate system. What will limit you is using opengl's old fixed function pipeline which was right handed(If i remember correctly). Go a little more modern and you create your own matrices and control what they are applied to. That will allow you to choose which handed system you want.
This also applies to DirectX.

Re: 3D Coordinate System

Posted: Fri Mar 27, 2020 12:12 am
by IdeasVacuum
Hi Samuel

Well, yes - I could buy a car with square wheels, make my own round wheels and then fit them, but if I could choose the wheels I wanted, without making my own, that would be better. I think it's a valid wish :mrgreen:

Re: 3D Coordinate System

Posted: Fri Mar 27, 2020 5:19 pm
by Samuel
Sure you could buy your own tires and it would save you headache and time. In this case though you're not buying tires, you're asking for them.
And what you are asking for are 3D engine functions, which is what PB/Ogre is intended for. There's very little reason for them to develop another engine that's included with Purebasic.

Re: 3D Coordinate System

Posted: Fri Mar 27, 2020 9:52 pm
by IdeasVacuum
.... Not using the 3D Engine, using OpenGL in the OpenGL Gadget. All I'm saying is, instead of only the default World Ordinates system delivered preset, give the developer a choice.

Re: 3D Coordinate System

Posted: Sat Mar 28, 2020 12:35 am
by Samuel
As I said in a previous post, that preset is because you are using the fixed function pipeline. You will have a choice if you use more modern OpenGL.
Having the team build a 3D engine based around the OpenGL gadget when they already have a functioning 3D engine(Ogre) is pointless.

If you really want it then put the request in the Feature Requests and Wishlists. They'll decide for us.