3D Entity System [DE]

Previous topic - Next topic

x-tra

Mmmmm das mit den Tasten ist ja nicht schlecht, aber wenn man diese mit Maus bewegen will, oder automatisch!

Schranz0r

gut mit maus steuern wär halt dann MOUSEAXIS(0) bzw. (1) ;)
Hab da noch kleine Probleme ^^
Aber ich bekomm das schon hin ;)
I <3 DGArray's :D

PC:
AMD Ryzen 7 3800X 16@4.5GHz, 16GB Corsair Vengeance LPX DDR4-3200 RAM, ASUS Dual GeForce RTX™ 3060 OC Edition 12GB GDDR6, Windows 11 Pro 64Bit, MSi Tomahawk B350 Mainboard

x-tra

Mann kan doch dort parameter angeben am einfachsten.
Ob die nun für Tasten oder Werte stehen, bliebe jedem selbst überlassen.

Schranz0r

hmm...wenn du einen Taste z.B nimmst dann wird ja nur geprüft ob TRUE, wenn ja, adde den Speed zur Position.....
Nimmst du jetzt einen Wert dazu, hast du das Problem das der immer größer/kleiner wird sprich dein Model/Cam/What ever sehr komisch drauf reagiert ...
I <3 DGArray's :D

PC:
AMD Ryzen 7 3800X 16@4.5GHz, 16GB Corsair Vengeance LPX DDR4-3200 RAM, ASUS Dual GeForce RTX™ 3060 OC Edition 12GB GDDR6, Windows 11 Pro 64Bit, MSi Tomahawk B350 Mainboard

Kitty Hello

Mal langsam - vielleicht versuchen wir einfach das Blitz-dingens nachzubauen? OK?

Schranz0r

öhmm Ok, wird aber wohl nicht ganz so leicht :D
I <3 DGArray's :D

PC:
AMD Ryzen 7 3800X 16@4.5GHz, 16GB Corsair Vengeance LPX DDR4-3200 RAM, ASUS Dual GeForce RTX™ 3060 OC Edition 12GB GDDR6, Windows 11 Pro 64Bit, MSi Tomahawk B350 Mainboard

x-tra

oder wie bei Cobra3D:   MoveEntity(object, x, y, z)     RotateEntity(obj, x, y, z, Bolean)  Bolean= global oder relativ

Schranz0r

I <3 DGArray's :D

PC:
AMD Ryzen 7 3800X 16@4.5GHz, 16GB Corsair Vengeance LPX DDR4-3200 RAM, ASUS Dual GeForce RTX™ 3060 OC Edition 12GB GDDR6, Windows 11 Pro 64Bit, MSi Tomahawk B350 Mainboard

tft

Hi ....

mir ist diese Diskusion nicht ganz klar. Aber fileicht bin ich wie einige hir ebenfals zu sehr verwöhnt. Aber klar ist doch das GLBasic mit einfachheit und nicht mit Simplizität wirbt. Für eine Simple Befehls Reference ist der Preis einfach zu hoch. Da muss schon einiges an Befehls reference dazu kommen. Aber die ansätze sind gut. Also immer schön nerven wenn ihr eine gute Idee habt. Dann entwickelt sich GLBasic auch mal zu einer Sprache die auch anfänger als einfach bezeichen. Meiner Tochter habe ich GLBasic gezeigt. Sie ist nicht besonders Helle, Aber im vergleich zu B3D hat sie in GLBasic überhauptnichts auf die reihe bekommen.

Coole Grüsse TFT

Schranz0r

aha TFT :D


Also Update:

www.styleattax.de/EntitySystem1.2.rar

Kleine Demo mit dem neuen Entity System!!!

Updates sind:

Code (glbasic) Select
ScaleEntity(handle,sx,sy,sz)
SetEntityAlpha(handle, wert) // z.B wert -0.8
SetEntityTexture(handle,textur) // damit kann man z.B 2 Cubes erstellen aus einem Model und verschiede Texturen verpassen!
I <3 DGArray's :D

PC:
AMD Ryzen 7 3800X 16@4.5GHz, 16GB Corsair Vengeance LPX DDR4-3200 RAM, ASUS Dual GeForce RTX™ 3060 OC Edition 12GB GDDR6, Windows 11 Pro 64Bit, MSi Tomahawk B350 Mainboard

Schranz0r

so leider Doppelpost :D

Download: www.styleattax.de/EntitySystem1.3.rar

Neu dabei:

CreateCube(size,color)
CreateSphere(radius,nodes,color)

Anwendung so:

Code (glbasic) Select
LOCAL Cube AS T3DEntity
LOCAL Textur AS T3DTex
LOCAL CubeModel AS T3DModel

Textur = LoadTexur("meine.png")
CubeModel = CreateCube(1,RGB(0xff, 0xff, 0xff))

Cube = CreateEntity(Textur,CubeModel)

...
// sonst alles wie gehabt( PlaceEntity usw)
...
Hier die EntitySystem.gbas:

Code (glbasic) Select
// A type for a texture
// just holds the lodaed index for LOADSPRITE
TYPE T3DTex
    id_tex
ENDTYPE


// a type for a model (a .ddd file)
// for now it only holds the index (X_LOADOBJ)
TYPE T3DModel
    id_ddd
ENDTYPE


// an entity - that's a .ddd, a texture
// with position, rotation and scaling
TYPE T3DEntity
    tex AS T3DTex     // holds a texture
    ddd AS T3DModel   // holds a model

    active            // is active (or will not be crawn)
    anim_from         // animation from frame
    anim_to           // animation to frame
    anim_speed        // animation speed (interpolation gets done internally, then)
    x;y;z             // global position
    rx;ry;rz          // rotation angles
    cam               // is it a Cam?
    spot_x;spot_y;spot_z // the coordinates for the camera looking for
    sx=1;sy=1;sz=1    // scale factors
    alpha             // alpha transparency value

    M[16]             // matrix - internal use only
ENDTYPE

// GLOBAL objects
GLOBAL g3DObj[] AS T3DEntity    // entities


// Get a LOADSPRITE index, that has no loaded image, yet
FUNCTION GetFreeSpriteID:
LOCAL sx, sy, i
    GETSPRITESIZE i, sx, sy
    WHILE sx>0 OR sy>0
        INC i, 1
        GETSPRITESIZE i, sx, sy
    WEND
    RETURN i
ENDFUNCTION

// Get a X_LOADOBJ index, that has no model, yet
FUNCTION GetFreeModelID:
LOCAL i, nc
    nc = X_NUMFACES(i)
    WHILE nc>0
        INC i, 1
        nc = X_NUMFACES(i)
    WEND
    RETURN i
ENDFUNCTION

// Load a texture as a T3DTex object
FUNCTION LoadTexture AS T3DTex: filename$
LOCAL t AS T3DTex
    t.id_tex = GetFreeSpriteID()
    LOADSPRITE filename$, t.id_tex
    RETURN t
ENDFUNCTION


// Make no texture as an T3DTex object
FUNCTION MakeNullTexture AS T3DTex:
LOCAL t AS T3DTex
    t.id_tex = -1
    RETURN t
ENDFUNCTION

// Load a .ddd file as a T3DModel
FUNCTION LoadModel AS T3DModel: filename$
LOCAL t AS T3DModel
    t.id_ddd = GetFreeModelID()
    X_LOADOBJ filename$, t.id_ddd
    RETURN t
ENDFUNCTION

FUNCTION CreateSphere AS T3DModel: r, n, col
LOCAL i,j, theta1, theta2, theta3, pi
LOCAL t AS T3DModel
t.id_ddd = GetFreeModelID()

pi = ACOS(0)*2
IF r < 0 THEN r = -r
IF n < 4 THEN n = 4

X_AUTONORMALS 2 // smooth edges
X_OBJSTART t.id_ddd
FOR j=0 TO INTEGER(n/2) -1
theta1 = j * 2*pi / n - pi/2;
theta2 = (j + 1) * 2*pi / n - pi/2;
FOR i=0 TO n
theta3 = i * 2*pi / n;
X_OBJADDVERTEX r*COS(theta2) * COS(theta3), r*SIN(theta2), _
r*COS(theta2) * SIN(theta3), i/n, 2*(j+1)/n, col
X_OBJADDVERTEX r*COS(theta1) * COS(theta3), r*SIN(theta1), _
r*COS(theta1) * SIN(theta3), i/n, 2*j/n, col
NEXT
X_OBJNEWGROUP
NEXT
X_OBJEND
RETURN t
ENDFUNCTION

FUNCTION CreateCube AS T3DModel: sz, col
LOCAL t AS T3DModel
t.id_ddd = GetFreeModelID()
X_AUTONORMALS 1 // For a cube, hard edges
sz=sz/2
X_OBJSTART t.id_ddd
// Front Face
X_OBJADDVERTEX  sz, -sz,  sz, 1, 0, col
X_OBJADDVERTEX -sz, -sz,  sz, 0, 0, col
X_OBJADDVERTEX  sz,  sz,  sz, 1, 1, col
X_OBJADDVERTEX -sz,  sz,  sz, 0, 1, col
X_OBJNEWGROUP
// Back Face
X_OBJADDVERTEX -sz,  sz, -sz, 1, 1, col
X_OBJADDVERTEX -sz, -sz, -sz, 1, 0, col
X_OBJADDVERTEX  sz,  sz, -sz, 0, 1, col
X_OBJADDVERTEX  sz, -sz, -sz, 0, 0, col
X_OBJNEWGROUP
// Top Face
X_OBJADDVERTEX -sz,  sz,  sz, 0, 0, col
X_OBJADDVERTEX -sz,  sz, -sz, 0, 1, col
X_OBJADDVERTEX  sz,  sz,  sz, 1, 0, col
X_OBJADDVERTEX  sz,  sz, -sz, 1, 1, col
X_OBJNEWGROUP
// Bottom Face
X_OBJADDVERTEX  sz, -sz, -sz, 0, 1, col
X_OBJADDVERTEX -sz, -sz, -sz, 1, 1, col
X_OBJADDVERTEX  sz, -sz,  sz, 0, 0, col
X_OBJADDVERTEX -sz, -sz,  sz, 1, 0, col
X_OBJNEWGROUP
// Right face
X_OBJADDVERTEX  sz,  sz, -sz, 1, 1, col
X_OBJADDVERTEX  sz, -sz, -sz, 1, 0, col
X_OBJADDVERTEX  sz,  sz,  sz, 0, 1, col
X_OBJADDVERTEX  sz, -sz,  sz, 0, 0, col
X_OBJNEWGROUP
// Left Face
X_OBJADDVERTEX -sz, -sz,  sz, 1, 0, col
X_OBJADDVERTEX -sz, -sz, -sz, 0, 0, col
X_OBJADDVERTEX -sz,  sz,  sz, 1, 1, col
X_OBJADDVERTEX -sz,  sz, -sz, 0, 1, col
X_OBJNEWGROUP
X_OBJEND
RETURN t
ENDFUNCTION


// Release Memory for a T3DTex
FUNCTION FreeTexture: ext AS T3DTex
    LOADSPRITE "", ext.id_tex
    // try to find the texture and set it to '-1'
    FOREACH t IN g3DObj[]
        IF t.tex.id_tex = ext.id_tex
            t.tex.id_tex = -1
        ENDIF
    NEXT
ENDFUNCTION

// Release Memory for a T3DModel
FUNCTION FreeModel: ext AS T3DModel
    // find it in the list and just drop it
    FOREACH t IN g3DObj[]
        IF t.ddd.id_ddd = ext.id_ddd
            DELETE t
        ENDIF
    NEXT
    // make sure the memory is freed
    X_OBJSTART ext.id_ddd
    X_OBJEND
ENDFUNCTION

// Release a entity
FUNCTION FreeEntity: handle
    g3DObj[handle].active=FALSE
ENDFUNCTION



FUNCTION CreateEntity AS T3DEntity: tex AS T3DTex, m AS T3DModel
LOCAL t AS T3DEntity
t.tex=tex
    t.ddd=m
    RETURN t
ENDFUNCTION

FUNCTION CreateCamera AS T3DEntity:
LOCAL t AS T3DEntity
RETURN t
ENDFUNCTION

// Adds one to the visual list
// returns "handle" to that object
FUNCTION AddEntity: e AS T3DEntity
    e.active = TRUE
    UpdateMatrix(e)
LOCAL i
    FOREACH t IN g3DObj[]
        IF t.active=FALSE
            t = e
            RETURN i
        ENDIF
        INC i, 1
    NEXT

    DIMPUSH g3DObj[], e
    RETURN LEN(g3DObj[])-1
ENDFUNCTION

// remove an entity
FUNCTION RemoveEntity: handle
    DIMDEL g3DObj[], handle
ENDFUNCTION

FUNCTION ScaleEntity: handle, sx, sy, sz
g3DObj[handle].sx = sx
g3DObj[handle].sy = sy
g3DObj[handle].sz = sz
ENDFUNCTION

FUNCTION SetEntityAlpha: handle, value
g3DObj[handle].alpha = value
ENDFUNCTION

FUNCTION SetEntityTexture: handle, tex_id AS T3DTex
g3DObj[handle].tex = tex_id
ENDFUNCTION


// Set global X,Y,Z position of an entity
FUNCTION PlaceEntity: handle, x,y,z
    g3DObj[handle].x=x
    g3DObj[handle].y=y
    g3DObj[handle].z=z
    // update the model matrix for showing, later
    UpdateMatrix(g3DObj[handle])
ENDFUNCTION

FUNCTION PlaceCam: handle, x,y,z, look_x, look_y, look_z
g3DObj[handle].cam=TRUE
    g3DObj[handle].x=x
    g3DObj[handle].y=y
    g3DObj[handle].z=z
    g3DObj[handle].rx=-90
g3DObj[handle].spot_x = look_x
g3DObj[handle].spot_y = look_y
g3DObj[handle].spot_z = look_z
UpdateMatrix(g3DObj[handle])
ENDFUNCTION


// Move relative by dx,dy,dz
FUNCTION MoveEntity: handle, dx,dy,dz
    INC g3DObj[handle].x,dx
    INC g3DObj[handle].y,dy
    INC g3DObj[handle].z,dz
    UpdateMatrix(g3DObj[handle])
ENDFUNCTION

// Set global rotation angles
FUNCTION SetEntityRotation: handle, rx,ry,rz
    g3DObj[handle].rx=rx
    g3DObj[handle].ry=ry
    g3DObj[handle].rz=rz    
   
    g3DObj[handle].spot_x = rx
    g3DObj[handle].spot_y = ry
    g3DObj[handle].spot_z = rx

    UpdateMatrix(g3DObj[handle])
ENDFUNCTION

// rotate relative to current rotations
FUNCTION RotateEntity: handle, drx,dry,drz
    INC g3DObj[handle].rx,drx
    INC g3DObj[handle].ry,dry
    INC g3DObj[handle].rz,drz    
    UpdateMatrix(g3DObj[handle])
    IF g3DObj[handle].ry > 90 THEN g3DObj[handle].ry = 90
IF g3DObj[handle].ry < -90 THEN g3DObj[handle].ry = -90
    g3DObj[handle].spot_x = g3DObj[handle].x+COS(g3DObj[handle].rx)
    g3DObj[handle].spot_y = g3DObj[handle].y-SIN(g3DObj[handle].ry)
    g3DObj[handle].spot_z = g3DObj[handle].z+SIN(g3DObj[handle].rx)
       
ENDFUNCTION

// Create Displacement and rotation matrix
// for faster drawing and getting rid of gimbal locking
// ... if you don't understand this, just believe me
// it works, OK?
// It just creates a matrix which you can use with
// X_MULTMATRIX instead of X_MOVEMENT, X_ROTATION, X_SCALING, ...
FUNCTION UpdateMatrix: e AS T3DEntity
LOCAL sa,sb,sc, ca,cb,cc
LOCAL sacb, cacb
    DIM M[16]
    ca       = COS(-e.rx);
    sa       = SIN(-e.rx);
    sb       = COS(e.ry);
    cb       = SIN(e.ry);
    cc       = COS(-e.rz);
    sc       = SIN(-e.rz);

    sacb=sa*cb
    cacb=ca*cb

    e.M[0]  =   sb * cc;
    e.M[1]  =  -sb * sc;
    e.M[2]  =  -cb;

    e.M[4]  = -sacb * cc + ca * sc;
    e.M[5]  =  sacb * sc + ca * cc;
    e.M[6]  =  -sa * sb;

    e.M[8]  =  cacb * cc + sa * sc;
    e.M[9]  = -cacb * sc + sa * cc;
    e.M[10] =   ca * sb;

    e.M[12]= e.x
    e.M[13]= e.y
    e.M[14]= e.z
    e.M[15]= 1;
ENDFUNCTION

// Set the amination start and end value
// -> the model will then anmiate in between these values
//    forever
FUNCTION SetAnimation: handle, key_from, key_to, speed
    g3DObj[handle].anim_from=key_from
    g3DObj[handle].anim_to=key_to
    g3DObj[handle].anim_speed=speed
ENDFUNCTION

// This draws everything
FUNCTION DrawWorld:

    FOR transparent = 0 TO 1

        // look at each entity
        FOREACH t IN g3DObj[]
            // ignore disabled entities
            IF t.active=FALSE THEN CONTINUE
           
            // if Cam set Cam
IF t.cam = TRUE

X_CAMERA t.x, t.y, t.z, t.spot_x, t.spot_y, t.spot_z
ENDIF
            // first draw all opaque
            // then (2nd pass) draw all with alpha
            IF (t.alpha AND transparent=0) OR (t.alpha=0 AND transparent) THEN CONTINUE

            // some transparency
            ALPHAMODE t.alpha

            // apply texture
            X_SETTEXTURE t.tex.id_tex, -1

            // do the matrix magic
            X_PUSHMATRIX
            X_SCALING t.sx,t.sy,t.sz
            X_MULTMATRIX t.M[]


            // Get the current animation
            LOCAL pos
            pos = MOD(GETTIMERALL() * t.anim_speed, 1000)/1000
            X_DRAWANIM t.ddd.id_ddd, t.anim_from, t.anim_to, pos, TRUE
            X_POPMATRIX
        NEXT
    NEXT
ENDFUNCTION

// ------------------------------------------ //
//! Return the x position of the entity
// ------------------------------------------ //
FUNCTION GetEntityX: entity
    RETURN g3DObj[entity].x
ENDFUNCTION

// ------------------------------------------ //
//! Return the y position of the entity
// ------------------------------------------ //
FUNCTION GetEntityY: entity
    RETURN g3DObj[entity].y
ENDFUNCTION

// ------------------------------------------ //
//! Return the z position of the entity
// ------------------------------------------ //
FUNCTION GetEntityZ: entity
    RETURN g3DObj[entity].z
ENDFUNCTION
I <3 DGArray's :D

PC:
AMD Ryzen 7 3800X 16@4.5GHz, 16GB Corsair Vengeance LPX DDR4-3200 RAM, ASUS Dual GeForce RTX™ 3060 OC Edition 12GB GDDR6, Windows 11 Pro 64Bit, MSi Tomahawk B350 Mainboard

BumbleBee

@tft
Also im 2D Bereich ist ja wohl GLBasic nicht schwerer als Blitz. Der 3D Bereich mag am Anfang etwas verwirrend sein, aber später gehts doch dann (vielleicht). ;) Wer z.B. C++ kann der sagt auch das ist einfach. Also was ist jetzt einfach oder schwer?  Wenn man's kann ist es ja nicht schwer. Klar ist es eine Umstellung wenn man von 'ner anderen Sprache kommt aber man kann sich doch irgendwann daran gewöhnen. Im wahren Leben muß man sich doch auch öfters mal auf neue Sachen umstellen. Da hilft auch kein Jammern.:D Und Gernot hat's halt nun mal so gemacht. Und das es nicht für jeden Mist einen eigenen Befehl gibt find ich gut. Sonst herrscht bald das Chaos.

Sry, gehört ja eigentlich gar nicht hier rein.:D

Cheers
The day will come...

CPU Intel(R) Core(TM) i5-3570k, 3.4GHz, AMD Radeon 7800 , 8 GB RAM, Windows 10 Home 64Bit

tft

Hi ...

Ich wollte keine beurteilung abgeben. Sondern lediglich auf die Situation aufmerksam machen. Aber vileicht bin ich mit meinen 42 Jahren ja auch schon zu weit weg von Jungen Denkmustern. Auf jedenfall ist irgendwas an GLBasic Kompliziert. Sodas  die jenigen.... meist Schüler aus der Schule meiner Tochter (Ich erteile Programier Kurse) Ganz klar einfacher mit Blitz zurande kommen als mit GLBasic. Und alle sagen einhellig. Das sich GLBasic nicht gut Intuitiv erfassen läst. Einer vom Gymi meinte das liegt am Editor. Ich selber kann dazu nichts weiter sagen. Ich komme damit klar.

Gruss TFT

Schranz0r

Na der Typ hat mal keine ahnung vom Gymi!
Die wirklich grausamste IDE(Editor) die ich kenne ist die von BB !!!!

In GLB hat man halt mehr möglichkeiten als in BB, da ist das Entitysystem schon fix, hier nicht, und man kann es noch ändern nach wunsch!
In BB ein neues schreiben wär auch "fast" unmöglich, da die Types Laarmarschig sind wie sau!

Kennt man sich ein wenig mit GLB und Functionen/Types aus, dann ist in GLB ALLES möglich!!! Selbst DX wenns sein muss!
Und wenns mal wirklich keine Lösung gibt, in der Normalen Syntax, dann ballert man Inline rein (c++)!
I <3 DGArray's :D

PC:
AMD Ryzen 7 3800X 16@4.5GHz, 16GB Corsair Vengeance LPX DDR4-3200 RAM, ASUS Dual GeForce RTX™ 3060 OC Edition 12GB GDDR6, Windows 11 Pro 64Bit, MSi Tomahawk B350 Mainboard

x-tra

Ich muss jetzt auch mal meinen Senf dazu abgeben.

Bin ja selbst total begeisterter GLB Nutzer, aber es gibt halt auch nen Wermutstropfen.
Und sollts auch anders von mir kommen, das implementierte Entity System.

Ich probier grad selber mit Cobra3D rum und ohne GLB schlecht reden zu wollen, würde ich es (starres Entity System hin oder her) momentan sogar GLB vorziehen.

Ich würde aber lieber GLB gerade wegen seiner Multiplattformfähigkeit nutzen wollen.

Und die Intuitive Bedienbarkeit ist, nicht unbedingt Gui abhängig.

Also im Grunde, um GLB tatsächlich als die einfache Sprache darzustellen die es sein sollte, wäre doch ein (zusätzliches) Entitysystem dringend notwendig.

Und um den ganzen ein I-Tüpfelchen aufzusetzen, in der syntax drin, nicht erst irgendwie einbinden.

Denn objektiv betrachten machen all diese Kleinigkeiten GLB leider nicht so easy für den Einstieg.

In Corba hab ich für die paar Tage basteln mehr hinbekommen bzw. gerade für Einsteiger viel leichter zu verstehen.

Also und ich denke ich spreche so einigen aus dem Herzen, was ist das Problem solche ein System zu integrieren als zusätzliches Feature sozusagen.

Sei es Cobra3D oder auch Blitz, beide werben damit und warum sollte es nicht auch hier als zusätzliches Feature Verkaufsfördernd wirken und zum Wachsen der Community beitragen.

So, das lag mir jetzt einfach mal auf dem Herzen, weil eine Einbindung von so einem system von Hand eben nicht das gleich ist, als wenn all diese Befehle schon von Haus aus dabei sind.

Für uns vielleicht nicht, aber für Neulinge macht das einen Unterschied, aus deren Sicht gesehen.

Ich würde an Gernots Stelle die kompletten Entity Befehel aus Blitz, oder Cobra3D komplett so übernehmen, oder zumindest ähnliche Bezeichnung, Syntax, jedoch gleiche Wirkung.

Es führt wesentlich schneller zum Erfolg, und genau das wollen wir doch alle, oder?


So, jetzt könnt ihr mich steinigen und sagen, dass das von Schranz0r in Entwicklung stehende System ausreicht, und eingebunden werden kann, aber das ist dann kein Feature sondern eben eine Behelfslösung.

Ich habe ja schon dannach gefragt, und das wird auch mein letztes Statement dazu sein, da es wohl keine feste Einbindung in die systax geben wird.