bei Purebasic 5.11 (32bit) unter Windows 7 (64bit) mit DirectX 9 oder OpenGL ist mir aufgefallen das die Funktion FetchOrientation() immer einen Speicherzugriffsfehler verursacht, wenn man die Ausrichtung einer Kamera oder eines Nodes haben möchte.
Hier ein Beispiel:
Code: Alles auswählen
EnableExplicit
Structure fVector3
x.f
y.f
z.f
EndStructure
Structure fQuaternion
x.f
y.f
z.f
w.f
EndStructure
Define.i sprite, tempTexture, tempMaterial, tempMesh, camera, light, node, entity, currentObject
Define.f lz, lzdir = 1
Define.fVector3 camPos, lgtPos, nodPos, entPos
Declare DisplayInfoSprite()
; init
InitEngine3D()
InitSprite()
InitKeyboard()
OpenWindow(0,0,0,1024,768,"Bug FetchOrientation",#PB_Window_SystemMenu|#PB_Window_ScreenCentered)
OpenWindowedScreen(WindowID(0), 0, 0, WindowWidth(0), WindowHeight(0), 0, 0, 0, #PB_Screen_WaitSynchronization)
; create objects
sprite = CreateSprite(#PB_Any, 400, 200)
StartDrawing(SpriteOutput(sprite))
Box(0, 0, 300, 150, 0)
DrawText(5, 5, "Press F1 to F4 to fetch the orientation of", RGB(192,192,192))
DrawText(5, 25, "the entity (cube), the light, the camera or a node", RGB(192,192,192))
DrawText(5, 45, "orientation of entity", RGB(192,192,192))
DrawText(5, 65, "x = ", RGB(192,192,192))
DrawText(5, 85, "y = ", RGB(192,192,192))
DrawText(5, 105, "z = ", RGB(192,192,192))
DrawText(5, 125, "w = ", RGB(192,192,192))
StopDrawing()
tempTexture = CreateTexture(#PB_Any, 64, 64)
StartDrawing(TextureOutput(tempTexture))
Box(0, 0, 64, 64, RGB(128, 128, 128))
Box(0, 31, 64, 3, RGB(255, 255, 255))
Box(31, 0, 3, 64, RGB(255, 255, 255))
StopDrawing()
tempMaterial = CreateMaterial(#PB_Any, TextureID(tempTexture))
tempMesh = CreateCube(#PB_Any, 50)
entity = CreateEntity(#PB_Any, MeshID(tempMesh), MaterialID(tempMaterial), 0, 0, 0)
RotateEntity(entity, 0, 45, 0, #PB_Relative)
node = CreateNode(#PB_Any, 0, 50, 0)
; create light
light = CreateLight(#PB_Any, RGB(225, 225, 225), 0, 100, 0, #PB_Light_Directional)
LightLookAt(light, 0,0,0)
; create camera
camera = CreateCamera(#PB_Any, 0, 0, 100, 100)
MoveCamera(camera, 0, 100, 250, #PB_Absolute)
RotateCamera(camera, -15, 0, 0, #PB_Relative)
AmbientColor(RGB(32,32,32))
FreeMesh(tempMesh)
FreeMaterial(tempMaterial)
FreeTexture(tempTexture)
Repeat
While WindowEvent() : Wend
If ExamineKeyboard()
If KeyboardReleased(#PB_Key_F1)
currentObject = 1
ElseIf KeyboardReleased(#PB_Key_F2)
currentObject = 2
ElseIf KeyboardReleased(#PB_Key_F3)
currentObject = 3
ElseIf KeyboardReleased(#PB_Key_F4)
currentObject = 4
EndIf
EndIf
RotateEntity(entity, 0, -0.1, 0, #PB_Relative)
RotateNode(node, 0, 0.1, 0, #PB_Relative)
lz + lzdir
If lz < -50
lzdir = 1
ElseIf lz > 50
lzdir = -1
EndIf
LightLookAt(light, lz, 0, 0)
RenderWorld()
DisplayInfoSprite()
FlipBuffers()
Until KeyboardReleased(#PB_Key_Escape)
End
Macro GetOrientation(Object, Quaternion)
If IsNode(Object)
FetchOrientation(NodeID(Object))
ElseIf IsEntity(Object)
FetchOrientation(EntityID(Object))
ElseIf IsCamera(Object)
FetchOrientation(CameraID(Object))
ElseIf IsLight(Object)
FetchOrientation(LightID(Object))
EndIf
Quaternion\x = GetX()
Quaternion\y = GetY()
Quaternion\z = GetZ()
Quaternion\w = GetW()
EndMacro
Procedure DisplayInfoSprite()
Shared sprite, camera, light, node, entity, currentObject
Static.b init
Static.i color
Protected.fQuaternion orientation
If init = 0
color = RGB(192,192,192)
currentObject = 1
init = 1
EndIf
StartDrawing(SpriteOutput(sprite))
Box(0, 0, 300, 150, 0)
DrawText(5, 5, "Press F1 to F4 to fetch the orientation of", color)
DrawText(5, 25, "the entity (cube), the light, the camera or a node", color)
Select currentObject
Case 1 : DrawText(5, 45, "orientation of entity:", color) : GetOrientation(entity, orientation)
Case 2 : DrawText(5, 45, "orientation of node:", color) : GetOrientation(node, orientation)
Case 3 : DrawText(5, 45, "orientation of light:", color) : GetOrientation(light, orientation)
Case 4 : DrawText(5, 45, "orientation of camera:", color) : GetOrientation(camera, orientation)
EndSelect
DrawText(5, 65, "x = "+StrF(orientation\x,1), color)
DrawText(5, 85, "y = "+StrF(orientation\y,1), color)
DrawText(5, 105, "z = "+StrF(orientation\z,1), color)
DrawText(5, 125, "w = "+StrF(orientation\w,1), color)
StopDrawing()
DisplayTransparentSprite(sprite, 0, 0)
EndProcedure
F2 = Node (Absturz)
F3 = Light
F4 = Kamera (Absturz)
Evtl. kann das jemand mit der neuen Beta ausprobieren oder es überhaupt bestätigen.