Hi S.T, i think it is an API function since there is an underscore as its suffix, usually i use previously available code from other users and relics from their code still there, and also using api functions will not run on linux. sorry for that, the code corrected.
i think in purebasic and may be other programming languages are using the practical way to deal with vectors , and my approach described above are trying to decipher the subject and it seems to me successfull, as an example my approach to normals and tangents
was successful to position the spikes over sphere, and over a knot surface perpendicularly using my deciphering of the normals vector.
in concise as i said the vector defined here from the point of view of how to plot it in practice and not as it is described in math books but it is the essence of what is said in math books which are abstract. so when we say the vector (vx, vy, vz) it means the displacement needed in x,y,z directions to move any point one unit only to the target point labeled as (vx, vy, vz)
Code: Select all
Macro Text3D(No, Texte, Color, Alignment)
CreateText3D(No, Texte)
Text3DColor(No, Color)
Text3DAlignment(No, Alignment)
EndMacro
Declare Room()
Declare CreateMatrix()
Declare DrawCoordinates()
Global.s text
#CameraSpeed = 1
Enumeration
#mesh
#entity
#tex
#light
#camera
#wait
EndEnumeration
;ScreenX = GetSystemMetrics_(#SM_CXSCREEN)
;ScreenY = GetSystemMetrics_(#SM_CYSCREEN)
InitEngine3D()
InitSprite()
InitKeyboard()
InitMouse()
;OpenWindow(0,0,0,ScreenX,ScreenY,"3D Camera research",#PB_Window_BorderLess|#PB_Window_ScreenCentered)
;OpenWindow(0,0,0,ScreenX,ScreenY,"3D Camera research, .... change camera view using keys 1/2")
;OpenWindowedScreen(WindowID(0),0,0,ScreenX,ScreenY,1,0,0,#PB_Screen_WaitSynchronization)
ExamineDesktops()
OpenWindow(0, 0, 0, DesktopWidth(0), DesktopHeight(0), "3D Camera research, .... change camera view using keys 1/2")
OpenWindowedScreen(WindowID(0), 0, 0, DesktopWidth(0), DesktopHeight(0), 0, 0, 0, #PB_Screen_SmartSynchronization)
Add3DArchive(".", #PB_3DArchive_FileSystem)
Add3DArchive(#PB_Compiler_Home + "Examples/3D/Data/Textures", #PB_3DArchive_FileSystem)
Add3DArchive(#PB_Compiler_Home + "Examples/3D/Data/fonts", #PB_3DArchive_FileSystem)
Add3DArchive(#PB_Compiler_Home + "Examples/3D/Data/Scripts", #PB_3DArchive_FileSystem)
Parse3DScripts()
KeyboardMode(#PB_Keyboard_AllowSystemKeys)
CreateMaterial(100, LoadTexture(100, "Wood.jpg"))
Room() ; call the room building
;Create Light
CreateLight(0,RGB(245,245,205),19,13,0)
;Create Camera
CreateCamera(0,0,0,100,100)
MoveCamera(0,-10,0,10,#PB_Absolute)
CameraLookAt(0, 0, 0, 0)
vecX.f=CameraDirectionX(0)
vecY.f=CameraDirectionY(0)
vecZ.f=CameraDirectionZ(0)
;Debug vecX:Debug vecY:Debug vecZ
CreateSphere(2000,0.5); move the sphere to the camera position (-10,0,10)
CreateEntity(2000, MeshID(2000), MaterialID(100) , -10,0,10)
;draw a line from the camera position to the vector*20
CreateLine3D(200, -10,0,10, RGB(0,255,0), -10+vecX*20, 0+vecY*20, 10+vecZ*20, RGB(0,255,0))
AmbientColor(RGB(255,255,255))
CreateMaterial(#tex, LoadTexture(#tex, "geebee2.bmp"))
MaterialCullingMode(#tex, #PB_Material_NoCulling)
CreateMatrix()
temp=1
DrawCoordinates() ; draw X,Y,Z lines
MoveCamera(0,-10,11,53,#PB_Absolute)
CameraLookAt(0, 0, 0, 0)
Repeat
WindowEvent()
If ExamineMouse()
MouseX = -MouseDeltaX() * #CameraSpeed * 0.2
MouseY = -MouseDeltaY() * #CameraSpeed * 0.2
EndIf
ShowCursor_(0)
; Use arrow keys and mouse to rotate and fly in/out
ExamineKeyboard()
If KeyboardPushed(#PB_Key_Left)
KeyX.f = -#CameraSpeed
ElseIf KeyboardPushed(#PB_Key_Right)
KeyX.f = #CameraSpeed
Else
KeyX.f = 0
EndIf
If KeyboardPushed(#PB_Key_Up)
KeyY.f = -#CameraSpeed
ElseIf KeyboardPushed(#PB_Key_Down)
KeyY.f = #CameraSpeed
Else
KeyY.f = 0
EndIf
If KeyboardReleased(#PB_Key_Space) ;press key to toggle the rotation of the object
temp ! 1
EndIf
If KeyboardReleased(#PB_Key_H) ;press H to toggle Hide / UnHide of the room
HideFlag ! 1
For i=100 To 104
HideEntity(i, HideFlag)
Next
EndIf
If KeyboardReleased(#PB_Key_1);change camera view from the top of the room
MoveCamera(0, 0, 60, 0.000001,#PB_Absolute)
CameraLookAt(0, 0, 0, 0)
ElseIf KeyboardReleased(#PB_Key_2) ;;change camera view as usual
MoveCamera(0,-10,11,53,#PB_Absolute)
CameraLookAt(0, 0, 0, 0)
EndIf
roty - temp : ;roty-temp: roty-temp
RotateEntity(#entity, rotx+0, roty/2+0, rotz+90,#PB_Absolute)
RotateCamera(0, MouseY, MouseX, 0, #PB_Relative)
MoveCamera (0, KeyX, 0, KeyY)
RenderWorld()
FlipBuffers()
Until KeyboardPushed(#PB_Key_Escape) Or WindowEvent() = #PB_Event_CloseWindow
;main drawing routine
Procedure DrawMatrix()
Protected.f a, b, x, y, z, t
Protected n.l
a.f = 0.2 :b.f=0.8 : n=20: t.f
While t <= 2*#PI
;parametric equations for the Toroidal spiral
x=(a*Sin(n*t)+b)*Cos(t)
y=(a*Sin(n*t)+b)*Sin(t)
z=a*Cos(n*t)
MeshVertexPosition(x, y, z)
MeshVertexColor(RGB(0,255,0))
t + 0.01
Wend
;************************************************************
EndProcedure
Procedure CreateMatrix()
CreateMesh(0, #PB_Mesh_LineStrip, #PB_Mesh_Static) ; #PB_Mesh_LineStrip to joint the points with lines
;CreateMesh(0, #PB_Mesh_PointList, #PB_Mesh_Static) ; to draw just points
DrawMatrix()
FinishMesh(#True)
SetMeshMaterial(0, MaterialID(#tex))
CreateEntity(#entity, MeshID(0), MaterialID(#tex),0,-4,0)
ScaleEntity(#entity,4,4,4)
EndProcedure
Procedure Room()
;Create Red Wall
CreateTexture(1,32,32)
StartDrawing(TextureOutput(1))
Box(0,0,32,32,RGB(205,0,0))
StopDrawing()
CreateMaterial(1,TextureID(1))
MaterialCullingMode(1, #PB_Material_NoCulling)
CreateCube(100,1)
CreateEntity(100,MeshID(100),MaterialID(1),-19,0,0)
ScaleEntity(100,1,33,32)
;Create Green Wall
CreateTexture(2,32,32)
StartDrawing(TextureOutput(2))
Box(0,0,32,32,RGB(0,205,0))
StopDrawing()
CreateMaterial(2,TextureID(2))
MaterialCullingMode(2, #PB_Material_NoCulling)
CreateCube(101,1)
CreateEntity(101,MeshID(101),MaterialID(2),19,0,0)
ScaleEntity(101,1,33,32)
;Create Back Wall
CreateTexture(3,32,32)
StartDrawing(TextureOutput(3))
Box(0,0,32,32,RGB(250,250,250))
StopDrawing()
CreateMaterial(3,TextureID(3))
MaterialCullingMode(3, #PB_Material_NoCulling)
CreateCube(102,1)
CreateEntity(102,MeshID(102),MaterialID(3),0,0,-16)
ScaleEntity(102,36.5,32,1)
;Create Floor
CreateTexture(5,32,32)
StartDrawing(TextureOutput(5))
Box(0,0,32,32,RGB(250,250,200))
StopDrawing()
CreateMaterial(5,TextureID(5))
MaterialCullingMode(5, #PB_Material_NoCulling)
CreateCube(104,1)
CreateEntity(104,MeshID(104),MaterialID(5),0,-16,0)
ScaleEntity(104,36.5,1,32)
EndProcedure
Procedure DrawCoordinates()
CreateLine3D(100, -100, 0, 0, RGB(0,255,0), 100, 0, 0, RGB(0,255,0))
CreateLine3D(101, 0, -100, 0, RGB(0,0,255), 0, 100, 0, RGB(0,0,255))
CreateLine3D(102, 0, 0, 100, RGB(255,0,0), 0, 0, -100, RGB(255,0,0))
Text3D(100, "X", RGBA(255, 20, 250, 255), #PB_Text3D_HorizontallyCentered | #PB_Text3D_VerticallyCentered)
ScaleText3D(100, 5, 5, 0)
MoveText3D(100, 17, 0, 0)
Text3D(101, "Y", RGBA(0, 255, 255, 255), #PB_Text3D_HorizontallyCentered | #PB_Text3D_VerticallyCentered)
ScaleText3D(101, 5, 5, 0)
MoveText3D(101, 0, 15, 0)
Text3D(102, "Z", RGBA(255, 0, 0, 255), #PB_Text3D_HorizontallyCentered | #PB_Text3D_VerticallyCentered)
ScaleText3D(102, 5, 5, 0)
MoveText3D(102, 0, 0, 60)
EndProcedure