Wie immer danke für den Tip, man muss nur noch das Entity (in meinem Fall) um 90 ° drehen, dann klappts auch. Hier ein kleines Beispiel:
Code: Alles auswählen
EnableExplicit
Structure fQuaternion
x.f
y.f
z.f
w.f
EndStructure
Structure fVector3
x.f
y.f
z.f
EndStructure
Define.f distance1, distance2
Define.i tempTexture, tempMaterial, tempMesh, camera, light, entPoint1, entPoint2, entPoint3, entPoint4, entLine1, entLine2, meshHelpline
Define.fVector3 point1, point2, point3, point4, linecenter1, linecenter2
Define.fQuaternion helpline
; init
InitEngine3D()
InitSprite()
InitKeyboard()
OpenWindow(0,0,0,1024,768,"Winkel zwischen zwei Punkten",#PB_Window_SystemMenu|#PB_Window_ScreenCentered)
OpenWindowedScreen(WindowID(0), 0, 0, WindowWidth(0), WindowHeight(0), 0, 0, 0, #PB_Screen_WaitSynchronization)
MaterialFilteringMode(#PB_Default, #PB_Material_Anisotropic, 8)
; create line entities
tempTexture = CreateTexture(#PB_Any, 1, 1)
StartDrawing(TextureOutput(tempTexture))
DrawingMode(#PB_2DDrawing_AlphaBlend)
Box(0,0,1,1,RGBA(255,255,0,192))
StopDrawing()
tempMaterial = CreateMaterial(#PB_Any, TextureID(tempTexture))
MaterialShadingMode(tempMaterial, #PB_Material_Phong)
MaterialBlendingMode(tempMaterial, #PB_Material_AlphaBlend)
tempMesh = CreateCylinder(#PB_Any, 1, 1)
entLine1 = CreateEntity(#PB_Any, MeshID(tempMesh), MaterialID(tempMaterial))
tempTexture = CreateTexture(#PB_Any, 1, 1)
StartDrawing(TextureOutput(tempTexture))
DrawingMode(#PB_2DDrawing_AlphaBlend)
Box(0,0,1,1,RGBA(255,0,255,192))
StopDrawing()
tempMaterial = CreateMaterial(#PB_Any, TextureID(tempTexture))
MaterialShadingMode(tempMaterial, #PB_Material_Phong)
MaterialBlendingMode(tempMaterial, #PB_Material_AlphaBlend)
entLine2 = CreateEntity(#PB_Any, MeshID(tempMesh), MaterialID(tempMaterial))
; create entities for point positions
tempTexture = CreateTexture(#PB_Any, 1, 1)
StartDrawing(TextureOutput(tempTexture))
Plot(0,0,RGB(0,255,128))
StopDrawing()
tempMaterial = CreateMaterial(#PB_Any, TextureID(tempTexture))
MaterialBlendingMode(tempMaterial, #PB_Material_Phong)
tempMesh = CreateSphere(#PB_Any, 4)
entPoint1 = CreateEntity(#PB_Any, MeshID(tempMesh), MaterialID(tempMaterial))
entPoint2 = CreateEntity(#PB_Any, MeshID(tempMesh), MaterialID(tempMaterial))
tempTexture = CreateTexture(#PB_Any, 1, 1)
StartDrawing(TextureOutput(tempTexture))
Plot(0,0,RGB(0,128,255))
StopDrawing()
tempMaterial = CreateMaterial(#PB_Any, TextureID(tempTexture))
MaterialBlendingMode(tempMaterial, #PB_Material_Phong)
entPoint3 = CreateEntity(#PB_Any, MeshID(tempMesh), MaterialID(tempMaterial))
entPoint4 = CreateEntity(#PB_Any, MeshID(tempMesh), MaterialID(tempMaterial))
; create light
light = CreateLight(#PB_Any, RGB(225, 225, 225), 0, 250, 0, #PB_Light_Directional)
LightLookAt(light, 0,0,0)
; create camera
camera = CreateCamera(#PB_Any, 0, 0, 100, 100)
MoveCamera(camera, 0, 200, 0, #PB_Absolute)
RotateCamera(camera, -90, 0, 0, #PB_Relative)
AmbientColor(RGB(32,32,32))
FreeMesh(tempMesh)
FreeMaterial(tempMaterial)
FreeTexture(tempTexture)
; create the two points
point1\x = -100
point1\y = 0
point1\z = 0
point2\x = 50
point2\y = -20
point2\z = -50
MoveEntity(entPoint1, point1\x, point1\y, point1\z, #PB_Absolute)
MoveEntity(entPoint2, point2\x, point2\y, point2\z, #PB_Absolute)
point3\x = -50
point3\y = -20
point3\z = -50
point4\x = 50
point4\y = 50
point4\z = 50
MoveEntity(entPoint3, point3\x, point3\y, point3\z, #PB_Absolute)
MoveEntity(entPoint4, point4\x, point4\y, point4\z, #PB_Absolute)
; calc center point and distance
linecenter1\x = (point1\x + point2\x) / 2
linecenter1\y = (point1\y + point2\y) / 2
linecenter1\z = (point1\z + point2\z) / 2
MoveEntity(entLine1, linecenter1\x, linecenter1\y, linecenter1\z, #PB_Absolute)
distance1 = Sqr(Pow(point1\x - point2\x, 2) + Pow(point1\y - point2\y, 2) + Pow(point1\z - point2\z, 2))
ScaleEntity(entLine1, 1, distance1, 1, #PB_Relative)
EntityLookAt(entLine1, point1\x, point1\y, point1\z)
RotateEntity(entLine1, 90, 0, 0, #PB_Relative)
linecenter2\x = (point3\x + point4\x) / 2
linecenter2\y = (point3\y + point4\y) / 2
linecenter2\z = (point3\z + point4\z) / 2
MoveEntity(entLine2, linecenter2\x, linecenter2\y, linecenter2\z, #PB_Absolute)
distance2 = Sqr(Pow(point3\x - point4\x, 2) + Pow(point3\y - point4\y, 2) + Pow(point3\z - point4\z, 2))
ScaleEntity(entLine2, 1, distance2, 1, #PB_Relative)
EntityLookAt(entLine2, point4\x, point4\y, point4\z)
RotateEntity(entLine2, 90, 0, 0, #PB_Relative)
; this does not work
; meshHelpline = CreateLine3D(#PB_Any, point3\x, point3\y, point3\z, RGB(255,255,255), point4\x, point4\y, point4\z, RGB(255,255,255))
; FetchOrientation(MeshID(meshHelpline))
; helpline\x = GetX()
; helpline\y = GetY()
; helpline\z = GetZ()
; helpline\w = GetW()
; SetOrientation(EntityID(entLine2), helpline\x, helpline\y, helpline\z, helpline\w)
Repeat
While WindowEvent() : Wend
ExamineKeyboard()
RenderWorld()
FlipBuffers()
Until KeyboardReleased(#PB_Key_Escape)
End