3D Coordinate System

Everything related to 3D programming
User avatar
Comtois
Addict
Addict
Posts: 1429
Joined: Tue Aug 19, 2003 11:36 am
Location: Doubs - France

Re: 3D Coordinate System

Post 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
Please correct my english
http://purebasic.developpez.com/
S.T.
User
User
Posts: 16
Joined: Mon Dec 21, 2015 7:43 pm

Re: 3D Coordinate System

Post 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.
User avatar
Comtois
Addict
Addict
Posts: 1429
Joined: Tue Aug 19, 2003 11:36 am
Location: Doubs - France

Re: 3D Coordinate System

Post 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.
Please correct my english
http://purebasic.developpez.com/
S.T.
User
User
Posts: 16
Joined: Mon Dec 21, 2015 7:43 pm

Re: 3D Coordinate System

Post by S.T. »

This is fixed in version 5.41
Thanks!
IdeasVacuum
Always Here
Always Here
Posts: 6425
Joined: Fri Oct 23, 2009 2:33 am
Location: Wales, UK
Contact:

Re: 3D Coordinate System

Post 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.
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
User avatar
Samuel
Enthusiast
Enthusiast
Posts: 755
Joined: Sun Jul 29, 2012 10:33 pm
Location: United States

Re: 3D Coordinate System

Post 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.
IdeasVacuum
Always Here
Always Here
Posts: 6425
Joined: Fri Oct 23, 2009 2:33 am
Location: Wales, UK
Contact:

Re: 3D Coordinate System

Post 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:
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
User avatar
Samuel
Enthusiast
Enthusiast
Posts: 755
Joined: Sun Jul 29, 2012 10:33 pm
Location: United States

Re: 3D Coordinate System

Post 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.
IdeasVacuum
Always Here
Always Here
Posts: 6425
Joined: Fri Oct 23, 2009 2:33 am
Location: Wales, UK
Contact:

Re: 3D Coordinate System

Post 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.
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
User avatar
Samuel
Enthusiast
Enthusiast
Posts: 755
Joined: Sun Jul 29, 2012 10:33 pm
Location: United States

Re: 3D Coordinate System

Post 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.
Post Reply