Ich möchte folgende Funktion nach FreeBasic übersetzen, aber ich bekomme eine Speicherschutzverletzung.
AutoIt
Func Translate3Dto2D(ByRef $tStruct, $iPos, $fRotX, $fRotY, $fRotZ, $fCenterX = 0, $fCenterY = 0, $fScale = 1, $fZDeepCorrection = 500)
Local Const $fCosRotX = Cos($fRotX), $fSinRotX = Sin($fRotX), _
$fCosRotY = Cos($fRotY), $fSinRotY = Sin($fRotY), _
$fCosRotZ = Cos($fRotZ), $fSinRotZ = Sin($fRotZ), _
$f1 = $fCosRotY * $tStruct.x(($iPos)), _
$f2 = $fSinRotX * $tStruct.y(($iPos)), _
$f3 = $fCosRotX * $tStruct.z(($iPos)), _
$f4 = $fCosRotX * $tStruct.y(($iPos)), _
$f5 = $fSinRotX * $tStruct.z(($iPos)), _
$f6 = $f1 - $fSinRotY * ($f2 + $f3), _
$fXPos = ($fCosRotZ * $f6 - $fSinRotZ * ($f4 - $f5)) * $fScale, _
$fYPos = ($fSinRotZ * $f6 + $fCosRotZ * ($f4 - $f5)) * $fScale, _
$fZPos = ($fSinRotY * $tStruct.x(($iPos)) + $fCosRotY * ($f2 + $f3)) * $fScale, _
$fZPerspCorrection = 1 / ($fZPos / $fZDeepCorrection + 1)
$tStruct.fX(($iPos)) = $fXPos * $fZPerspCorrection + $fCenterX
$tStruct.fY(($iPos)) = $fYPos * $fZPerspCorrection + $fCenterY
$tStruct.fZ(($iPos)) = $fZPos
EndFunc ;==>Translate3Dto2D
Alles anzeigen
Die Struct wird über eine andere Funktion erstellt und ist dynamisch.
AutoIt
Local Const $iCountX = Int($aDim[0] / $iStep), $iCountY = Int($aDim[1] / $iStep)
Local Const $tagData = "struct;float x[" & $iCountX & "];float y[" & $iCountX & "];float z[" & $iCountX & "];float fX[" & $iCountX & "];float fY[" & $iCountX & "];float fZ[" & $iCountX & "];uint pen[" & $iCountX & "];endstruct"
Hier der fehlerhafter FreeBasic Code:
Code
/'
Type tagData
x (1 To 10000) As Single
y (1 To 10000) As Single
z (1 To 10000) As Single
fX (1 To 10000) As Single
fY (1 To 10000) As Single
fZ (1 To 10000) As Single
pen As UInteger
End Type
'/
Extern "Windows-MS"
Sub Translate3Dto2D(tStruct As Ptr, iPos As Integer, fRotX As Single, fRotY As Single, fRotZ As Single, fCenterX As Single = 0, fCenterY As Single = 0.0, fScale As Single = 1.0, fZDeepCorrection As Single = 500.0) Export
Dim As Single fCosRotX, fSinRotX, fCosRotY, fSinRotY, fCosRotZ, fSinRotZ, f1, f2, f3, f4, f5, f6, fXPos, fYPos, fZPos, fZPerspCorrection
fCosRotX = Cos(fRotX)
fSinRotX = Sin(fRotX)
fCosRotY = Cos(fRotY)
fSinRotY = Sin(fRotY)
fCosRotZ = Cos(fRotZ)
fSinRotZ = Sin(fRotZ)
/'
f1 = fCosRotY * tStruct->x(iPos)
f2 = fSinRotX * tStruct->y(iPos)
f3 = fCosRotX * tStruct->z(iPos)
f4 = fCosRotX * tStruct->y(iPos)
f5 = fSinRotX * tStruct->z(iPos)
f6 = f1 - fSinRotY * (f2 + f3)
fXPos = (fCosRotZ * f6 - fSinRotZ * (f4 - f5)) * fScale
fYPos = (fSinRotZ * f6 + fCosRotZ * (f4 - f5)) * fScale
fZPos = (fSinRotY * tStruct->x(iPos) + fCosRotY * (f2 + f3)) * fScale
fZPerspCorrection = 1 / (fZPos / fZDeepCorrection + 1)
tStruct->fX(iPos) = fXPos * fZPerspCorrection + fCenterX
tStruct->fY(iPos) = fYPos * fZPerspCorrection + fCenterY
tStruct->fZ(iPos) = fZPos
'/
End Sub
End Extern
Alles anzeigen
Im Prinzip will ich die Schleife per freeBasic beschleunigen!
Meine Lösung siehe Post#20. Vielen Dank an @eukalyptus für die Hilfestellungen!
Vielen Dank.