Bissher habe ich tatsächlich einige Ergebnisse zu Tage gefördert.
Ich habe nun ungefähr ein Drittel geschafft und da es tatsächlich eine Menge arbeit ist habe ich mich gefragt ob es überhaupt jemand benutzen würde, oder ob dass ein Zweckloses unterfangen ist und wenn ja was ihr verändern würdet.
Bisher habe ich nur die Zeichen Klasse fertig, möchte aber schonmal meine Ideen teilen:
Eine World Klasse enthält die ganzen Welt Daten, sowie die Möglichkeit mehr von diesen, von der Festplatte, bei Bedarf, nachzuladen. Jedes Element der World Klasse ruft andere Funktionen in der Zeichen, oder Audio Klasse auf. Die Zeichen Klasse Übernimmt für uns das neu Zeichnen bei jedem neuen Bild. Sie enthät 3 Unterklassen DrawSpace (eine seperate Zeichenoberfläche). Der HauptDrawSpace wird bei jedem neuen Bild gezeichnet. In diesen Können dann wieder andere DrawSpaces oder Modelle gezeichnet werden. Modelle sind an sich nur benannte DrawSpaces die unveränderlich sind, und andere komplexere Zeichen Daten enthalten können.
Modelle kann man auch selber erzeugen. Vorgegeben werden ein paar Grundformen (Quadrat...).
Die ganzen Modelle und DrawSpaces werden mit Daten über Textur und Position genauer bestimmt (die beiden anderen Unterklassen).
Die Position und Textur sind im nachhinein noch veränderbar.
Hier ist bis jetzt das Script:
Danke an Bentschi für die MCode funktion.
Code: Select all
Class Draw
{
__New()
{
This.OpenGL := New OpenGL()
This.Model.Rect:=This.OpenGL.CreateList()
This.OpenGL.TexCoord(0,0),This.OpenGL.Vertex(-0.5,-0.5,0)
This.OpenGL.TexCoord(1,0),This.OpenGL.Vertex(0.5,-0.5,0)
This.OpenGL.TexCoord(1,1),This.OpenGL.Vertex(0.5,0.5,0)
This.OpenGL.TexCoord(0,1),This.OpenGL.Vertex(-0.5,0.5,0)
This.OpenGL.EndList()
}
RegisterModel(Name,DrawSpace)
{
This.Model[Name]:=This.OpenGL.CreateList()
DrawFunc:=DrawSpace[1]
DrawFunc.(This,DrawSpace)
This.OpenGL.EndList()
}
UnregisterModel(Name)
{
This.OpenGL.DeleteList(This.Model.Remove(Name))
}
CreatePositionData()
{
return New This.PositionData()
}
CreateDrawSpace()
{
return New This.DrawSpace(This)
}
CreateTextureData()
{
static Index:=-1
return New This.TextureData(Index++,This.OpenGL.Textures)
}
Class PositionData
{
__New()
{
This.pMat := DllCall("GlobalAlloc", "UInt", 0, "Ptr", 128)
}
__Delete()
{
DllCall("GlobalFree", "ptr", This.Pmat)
}
Translate(X,Y,Z)
{
static TranslateFunc:=MCode( "1,x86:8b442404dd4060dd4068dd4070dd442408dd00d8c9dec4dd4008d8c9dec3dd4010dec9dec1dd442410dd4020d8c9dec4dd4028d8c9dec3dd4030dec9dec1dd442418dd4040d8c9dec4dd4048d8c9dec3dd4050dec9dec1dd5870dd5868dd5860c21c00")
DllCall(TranslateFunc,"Ptr",This.pMat,"Double",X,"Double",Y,"Double",Z)
}
RotateX(Deg)
{
static RotateXFunc:=MCode("1,x86:8b44240489c183c02083c140dd442408d9ebdec968b4000000da34245ad9fbdd00dd01d9c1d8cbd9c1d8cddee9dd18d9c3decad8cadec1dd1983c00883c108dd00dd01d9c1d8cbd9c1d8cddee9dd18d9c3decad8cadec1dd1983c00883c108dd00dd01d9c1d8cbd9c1d8cddee9dd18decadecadec1dd19c20c")
DllCall(RotateXFunc,"Ptr",This.pMat,"Double",Deg)
}
RotateY(Deg)
{
static RotateYFunc:=MCode("1,x86:8b44240489c183c040dd442408d9ebdec968b4000000da34245ad9fbdd00dd01d9c1d8cbd9c1d8cddee9dd18d9c3decad8cadec1dd1983c00883c108dd00dd01d9c1d8cbd9c1d8cddee9dd18d9c3decad8cadec1dd1983c00883c108dd00dd01d9c1d8cbd9c1d8cddee9dd18decadecadec1dd19c20c00")
DllCall(RotateYFunc,"Ptr",This.pMat,"Double",Deg)
}
RotateZ(byref Matrix,Deg)
{
static RotateZFunc:=MCode("1,x86:8b44240489c183c120dd442408d9ebdec968b4000000da34245ad9fbdd00dd01d9c1d8cbd9c1d8cddee9dd18d9c3decad8cadec1dd1983c00883c108dd00dd01d9c1d8cbd9c1d8cddee9dd18d9c3decad8cadec1dd1983c00883c108dd00dd01d9c1d8cbd9c1d8cddee9dd18decadecadec1dd19c20c00")
DllCall(RotateZFunc,"Ptr",This.pMat,"Double",Deg)
}
Scale(byref Matrix,X,Y,Z)
{
static ScaleFunc:=MCode("1,x86:8b442404dd442408dd00d8c9dd1883c008dd00d8c9dd1883c008dd00dec9dd1883c010dd442410dd00d8c9dd1883c008dd00d8c9dd1883c008dd00dec9dd1883c010dd442418dd00d8c9dd1883c008dd00d8c9dd1883c008dd00dec9dd18c21c00")
DllCall(ScaleFunc,"Ptr",This.pMat,"Double",X,"Double",Y,"Double",Z)
}
}
Class DrawSpace
{
__New(Draw)
{
This.Draw:=Draw
}
DrawDrawSpace(DrawSpace,PositionData)
{
This.Insert([This.Draw.DrawSpaceFunc,PositionData])
}
DrawModel(ModelName,PositionData,TextureData)
{
If IsObject(TextureData)
This.Insert([This.Draw.ModelFuncTex,ModelName,PositionData,TextureData])
This.Insert([This.Draw.ModelFunc,ModelName,PositionData])
}
}
Class TextureData
{
__New(Index,Textures)
{
This.Index:=Index
This.Textures:=Textures
}
ChooseTexture(Name)
{
This.Texture:=This.Textures[Name]
}
}
DrawSpaceFunc(Data)
{
ApplyPosition(Data[3])
DrawDrawSpace(Data[2])
RemovePosition(Data[3])
}
ModelFuncTex(Data)
{
This.ApplyPosition(Data[3])
This.ApplyTexture(Data[4])
This.DrawModel(Data[2])
This.RemovePosition(Data[3])
}
ModelFunc(Data)
{
This.ApplyPosition(Data[3])
This.DrawModel(Data[2])
This.RemovePosition(Data[3])
}
ApplyPosition(PositionData)
{
This.OpenGL.PushMatrix()
This.OpenGL.MultMatrix(PositionData.pMat)
}
RemovePosition(PositionData)
{
This.OpenGL.PopMatrix()
}
ApplyTexture(TextureData)
{
static Index
If (TextureData.Index!=Index)
{
This.OpenGL.BindTexture(TextureData.Texture)
Index:=TextureData.Index
}
}
DrawModel(Name)
{
This.OpenGL.CallList(This.Model[Name])
}
DrawDrawSpace(DrawSpace)
{
For Each,Element in DrawSpace
{
DrawFunc:=Element[1]
DrawFunc.(This,Element)
}
}
}
Class OpenGL
{
__New(Settings)
{
This.Textures := new TextureHandler(This)
This.Setings := Settings
This.hgl := DllCall("LoadLibrary", "str", "opengl32")
This.hglu := DllCall("LoadLibrary", "str", "glu32")
This.SwapBuffersProc := DllCall("GetProcAddress","ptr",DllCall("GetModuleHandle","str","gdi32"),"astr","SwapBuffers")
This.BindTextureProc := DllCall("GetProcAddress","ptr",This.hgl,"astr","glBindTexture")
This.LoadIdentityProc := DllCall("GetProcAddress","ptr",This.hgl,"astr","glLoadIdentity")
This.Vertex3dProc := DllCall("GetProcAddress","ptr",This.hgl,"astr","glVertex3d")
This.TexCoord2dProc := DllCall("GetProcAddress","ptr",This.hgl,"astr","glTexCoord2d")
This.EnableProc := DllCall("GetProcAddress","ptr",This.hgl,"astr","glEnable")
This.BeginProc := DllCall("GetProcAddress","ptr",This.hgl,"astr","glBegin")
This.EndProc := DllCall("GetProcAddress","ptr",This.hgl,"astr","glEnd")
This.GenListsProc := DllCall("GetProcAddress","ptr",This.hgl,"astr","glGenLists")
This.NewListProc := DllCall("GetProcAddress","ptr",This.hgl,"astr","glNewList")
This.EndListProc := DllCall("GetProcAddress","ptr",This.hgl,"astr","glEndList")
This.CallListProc := DllCall("GetProcAddress","ptr",This.hgl,"astr","glCallList")
This.DeleteListsProc := DllCall("GetProcAddress","ptr",This.hgl,"astr","glDeleteLists")
This.MultMatrixProc := DllCall("GetProcAddress","ptr",This.hgl,"astr","glMultMatrix")
This.PushMatrixProc := DllCall("GetProcAddress","ptr",This.hgl,"astr","glPushMatrix")
This.PopMatrixProc := DllCall("GetProcAddress","ptr",This.hgl,"astr","glPopMatrix")
}
LoadMipMap(W,H,Ptr)
{
DllCall("opengl32\glGenTextures","Int",1,"UInt*",Texture)
This.BindTexture(Texture)
DllCall("opengl32\glTexParameteri","UInt",0xDE1,"UInt",0x2801,"Int",0x2601)
DllCall("opengl32\glTexParameteri","UInt",0xDE1,"UInt",0x2800,"Int",0x2601)
DllCall("glu32\gluBuild2DMipmaps","UInt",0xDE1,"uint",4,"Int",W,"Int",H,"Int",0x1908,"UInt",0x1401,"Ptr", Ptr)
This.BindTexture(0)
return Texture
}
UnloadMipMap(Texture)
{
If DllCall("opengl32\glIsTexture", "UInt", Texture, "UInt")
DllCall("opengl32\glDeleteTextures","Int",1,"UInt*",Texture)
}
BindTexture(Texture)
{
DllCall(This.BindTextureProc,"UInt",0xDE1,"UInt",Texture)
}
FlushToScreen()
{
DllCall(This.SwapBuffersProc,"UInt",This.Gui.hDC)
DllCall(This.ClearProc,"UInt",0x4100)
This.LoadIdentity()
}
LoadIdentity()
{
DllCall(This.LoadIdentityProc)
}
Enable(Cap)
{
DllCall(This.EnableProc, "UInt", Cap)
}
TexCoord(X,Y)
{
DllCall(This.TexCoord2dProc,"Double",X,"Double",Y)
}
Vertex(X,Y,Z)
{
DllCall(This.Vertex3dProc,"Double",X,"Double",Y,"Double",Z)
}
Begin(Cap=0x7)
{
DllCall(This.BeginProc,"UInt",Cap)
}
End()
{
DllCall(This.EndProc)
}
CreateList()
{
Index:=DllCall(This.GenListsProc,"Int",1)
DllCall(This.NewListProc,"UInt",Index,"UInt",0x1300)
return Index
}
EndList()
{
DllCall(This.EndListProc)
}
DeleteList(Index)
{
DllCall(This.DeleteListsProc,"UInt",Index,"UInt",1)
}
MultMatrix(pMat)
{
DllCall(This.MultMatrixProc,"Ptr",pMat)
}
PushMatrix()
{
DllCall(This.PushMatrixProc)
}
PopMatrix()
{
DllCall(This.PopMatrixProc)
}
}
Class TextureHandler{
__new(OpenGL,Settings){
This.OpenGL := OpenGL
This.Settings := Settings
}
__Delete(){
If IsObject(this.CurrentlyLoaded)
This.UnloadTextures()
}
LoadTextures(File="Tex.tex")
{
This.CurrentlyLoaded:=[]
File := FileOpen(File,"r")
If (!IsObject(File))
Error("Fehler beim laden der Texturdatei`n0400")
Size := File.Length
VarSetCapacity(Texes,Size)
If (!File.Length)
Error("Fehler beim laden der Texturdatei`n0401")
File.RawRead(Texes,Size)
File.Close()
Index := 0
N:=NumGet(Texes,Index,"uint")
If (!N)
Error("Fehler beim laden der Texturdatei`n0402")
Index += 4
Loop %N%
This.CurrentlyLoaded.Insert(This.LoadTexture(Texes,Readindex))
}
LoadTexture(byref Data,byref Index){
W := NumGet(Data,Index,"uint")
Index += 4
H := NumGet(Data,Index,"uint")
Index += 4
If !(W&&H)
Error("Fehler beim Laden einer Textur`n0403")
Name := Strget(&Data+Index,"utf-8")
Index += StrPut(Name,"utf-8")
If !(Name~="^[\w_]{4,15}$")
Error("Fehler beim Laden einer Textur`n0404")
If (IsFunc(This[Name])||This.HasKey(Name))
Error("Fehler beim Laden einer Textur`n0405")
This[Name]:=This.OpenGL.LoadMipMap(W,H,&Data+Index)
Index += W*H*4
return Name
}
UnloadTextures()
{
For each,Texture in CurrentlyLoaded
This.OpenGL.UnloadMipMap(Texture)
This.Remove("CurrentlyLoaded")
}
}
MCode(mcode)
{
c := (A_PtrSize=8) ? "x64" : "x86"
if (!regexmatch(mcode, "^([0-9]+),(" c ":|.*?," c ":)([^,]+)", m))
return
if (!DllCall("crypt32\CryptStringToBinary", "str", m3, "uint", 0, "uint", t:=[4,1][m1], "ptr", 0, "uint*", s, "ptr", 0, "ptr", 0))
return
p := DllCall("GlobalAlloc", "uint", 0, "ptr", s, "ptr")
if (A_Is64bitOS)
DllCall("VirtualProtect", "ptr", p, "ptr", s, "uint", 0x40, "uint*", op)
if (DllCall("crypt32\CryptStringToBinary", "str", m3, "uint", 0, "uint", t, "ptr", p, "uint*", s, "ptr", 0, "ptr", 0))
return p
DllCall("GlobalFree", "ptr", p)
}