https://msdn.microsoft.com/en-us/librar ... s.85).aspx
Die DirectX Matrizen sind 4x4 Matrizen.
Ich arbeite grade an einer Art Spiele Engine für AHK in openGL.
Da hat es sich geziegt, dass Klassen ganz sinnvoll sind.
Code: Select all
class Matrix
{
__New(Type="Float",Ptr=0)
{
This.FieldSize := (Type="Float")?4:8
This.Type := Type
if (Ptr)
This.Ptr := Ptr
Else
{
This.SetCapacity("Data",(type="Float")?64:128)
This.Ptr := This.GetAddress("Data")
This.loadIdentity()
}
}
address(p*)
{
static off
if (!p.MaxIndex())
return off
off := This.Ptr
For Each,Value in p
off += (Value-1)*(This.FieldSize**Each)
return off
}
setField(Value,Field*)
{
NumPut(Value,(This.address(Field*)+0),0,This.Type)
return Value
}
getField(Field*)
{
return NumGet((This.address(Field*)+0),0,This.Type)
}
loadIdentity()
{
Loop 4
{
x := A_Index
Loop 4
This.setField((x=A_Index)+0,x,A_Index)
}
}
scale(x,y,z)
{
Loop 4
{
This.setField(this.getField(A_Index,1)*x)
This.setField(this.getField(A_Index,2)*y)
This.setField(this.getField(A_Index,3)*z)
}
}
translate(x,y,z)
{
Loop 4
This.SetField(x*This.getField(A_Index,1)+y*This.getField(A_Index,2)+z*This.getField(A_Index,3)+This.getField(A_Index,4))
}
rotate(angle,x,y,z)
{
;Ich kann Rotationen hinzufügen wenn du willst, aber die sind nervig :)
}
OutPut()
{
str := ""
Loop 4
{
str .= "[ "
x := A_Index
Loop 4
str .="[" . This.getField(x,A_Index) . "]" . ((A_Index=4)?"":", ")
str .= " ]`n"
}
return str
}
}
m1 := new Matrix() ;Float und legt seinen eignen Speicher an
m1.Scale(100,-20,10)
m1.Translate(0.3,2.7,-1.3)
Msgbox % m1.OutPut()
Det := 0
m2 :=D3DMatrixInverse(m1,Det)
Msgbox % m2.OutPut()
D3DMatrixInverse(QuellMatrix,byref Determinante = "")
{
ZielMatrix := New Matrix()
If (IsByRef(Determinante))
DllCall("D3DX9_43.dll\D3DXMatrixInverse", "Ptr", ZielMatrix.Ptr, "Ptr", 0, "Ptr", QuellMatrix.Ptr)
Else
DllCall("D3DX9_43.dll\D3DXMatrixInverse", "Ptr", ZielMatrix.Ptr, "Float*", Determinante, "Ptr", QuellMatrix.Ptr)
return ZielMatrix
}