D3D9 Matrix Inverse

Post a reply


In an effort to prevent automatic submissions, we require that you complete the following challenge.
Smilies
:D :) ;) :( :o :shock: :? 8-) :lol: :x :P :oops: :cry: :evil: :twisted: :roll: :!: :?: :idea: :| :mrgreen: :geek: :ugeek: :arrow: :angel: :clap: :crazy: :eh: :lolno: :problem: :shh: :shifty: :sick: :silent: :think: :thumbup: :thumbdown: :salute: :wave: :wtf: :yawn: :facepalm: :bravo: :dance: :beard: :morebeard: :xmas: :HeHe: :trollface: :cookie: :rainbow: :monkeysee: :monkeysay: :happybday: :headwall: :offtopic: :superhappy: :terms: :beer:
View more smilies

BBCode is ON
[img] is OFF
[flash] is OFF
[url] is ON
Smilies are ON

Topic review
   

Expand view Topic review: D3D9 Matrix Inverse

Re: D3D9 Matrix Inverse

Post by nnnik » 08 Jul 2016, 06:49

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
}

Re: D3D9 Matrix Inverse

Post by just me » 08 Jul 2016, 03:39

Moin,

in Deinem C++ Beispiel ist m die Quellmatrix und minv die Zielmatrix. Der Rückgabewert der Funktion ist im Erfolgsfall identisch mit der Adresse der Zielmatrix, im Fehlerfall 0.

Re: D3D9 Matrix Inverse

Post by Barbossa155 » 08 Jul 2016, 02:46

das ist schonmal sehr hilfreich
praktisch sieht es in meinem C++ Programm so aus:

Code: Select all

D3DXMATRIX	m ( (float *)(0xB6FA2C) ); // matrix

// Matrix Inverten
D3DXMATRIX minv;
memset ( &minv, 0, sizeof ( D3DXMATRIX ) ); // 64
m._44 = 1.0f;
D3DXMatrixInverse ( &minv, NULL, &m );
Determinante brauche ich in dem Falle nicht.

Was meinst du genau mit ZielMatrix, und was ist dann der Ausgabewert?
(Ist dann in dem Falle die Quellmatrix nicht gleich die Zielmatrix?)

Re: D3D9 Matrix Inverse

Post by just me » 07 Jul 2016, 16:41

Vielleicht:

Code: Select all

If DllCall("D3DX9_43.dll\D3DXMatrixInverse", "Ptr", &ZielMatrix, "Ptr", 0, "Ptr", &QuellMatrix, "UPtr")
; oder mit Determinante
If DllCall("D3DX9_43.dll\D3DXMatrixInverse", "Ptr", &ZielMatrix, "FloatP", Determinante, "Ptr", &QuellMatrix, "UPtr")

Re: D3D9 Matrix Inverse

Post by Barbossa155 » 07 Jul 2016, 08:24

also es sieht so aus:

Code: Select all

dwM := 0xB6FA2C
readRaw(dwM, 64, gscreenmatrix) ; ließt nur den Pointer aus size = 64
   	m_11 := NumGet(gscreenmatrix, 0*4, "Float")
        m_12 := NumGet(gscreenmatrix, 1*4, "Float")
        m_13 := NumGet(gscreenmatrix, 2*4, "Float")
        m_21 := NumGet(gscreenmatrix, 4*4, "Float")
        m_22 := NumGet(gscreenmatrix, 5*4, "Float")
        m_23 := NumGet(gscreenmatrix, 6*4, "Float")
        m_31 := NumGet(gscreenmatrix, 8*4, "Float")
        m_32 := NumGet(gscreenmatrix, 9*4, "Float")
        m_33 := NumGet(gscreenmatrix, 10*4, "Float")
        m_41 := NumGet(gscreenmatrix, 12*4, "Float")
        m_42 := NumGet(gscreenmatrix, 13*4, "Float")
        m_43 := NumGet(gscreenmatrix, 14*4, "Float")
kannst du damit vielleicht mehr anfangen?
Ich weiss was ich reinschreiben muss etc.
In welcher DLL das ganze liegt, weiss ich leider nicht

ob etwa die

Header
D3dx9math.h
Library
D3dx9.lib

etwas bringen, herauszufinden wo es liegt?

Re: D3D9 Matrix Inverse

Post by just me » 07 Jul 2016, 08:01

Moin,

wenn Du weißt, in welcher Dll die Funktion liegt und was man in die Matrix schreiben muss, ist das kein Problem. D3DXMATRIX bzw. D3DMATRIX sind Speicherbereiche aus 4 * 4 Gleitkommazahlen (FLOAT's) . Die Funktion erwartet einen Pointer auf den Zielbereich, optional einen Pointer auf eine Gleitkommazahl als Determinante (wofür auch immer), und einen Pointer auf den Quellbereich. Bei fehlerfreier Ausführung gibt sie den Pointer auf den Zielbereich zurück. Füllen und Auslesen geht mit NumPut() / NumGet().

Mit Matrizen hatte ich schon immer so meine Probleme. ;)

D3D9 Matrix Inverse

Post by Barbossa155 » 07 Jul 2016, 07:00

Hallo

Wahrscheinlich ein bisschen komisch für euch warum ich das frage...
Ist es möglich in AHK so eine Funktion hier zu erstellen, mit einem Ausgabewert?

Code: Select all

D3DXMATRIX* D3DXMatrixInverse(
  _Inout_       D3DXMATRIX *pOut,
  _Inout_       FLOAT      *pDeterminant,
  _In_    const D3DXMATRIX *pM
);
Brauche das für diverse Sachen im Memory Bereich.

Danke.

Top