3D Entity System [DE]

Previous topic - Next topic

x-tra

Ja Sebe der Ansatz ist am logischsten.
Ich für meinen Teil hab erstmal nur bisschen was zusammengesucht in der Eile.

Und du hast ja auch C3D wie ich in nem PB Forum las.

Sebe

Ich bin f4ktor im offiziellen Forum und KiBaLabs in deinem. So klein ist die Welt =)
Cobra hab ich mir wg. dem Pascalansatz und dem Entitysystem besorgt. Hätte ich gewusst, dass Gernot das jetzt auch in GLBasic einbaut hätt ich es wahrscheinlich nicht gemacht. Naja, immerhin kann man sich aus anderen Sprachen auch gut Inspirationen holen nicht wahr? ^^

x-tra

Grins ja is auch bissl auf meinem Mist gewachsen, das Beispiel aus der Entity.rar ist mein Code von C3D nur angepasst.

Ja ich habs wegen dem Entity System genommen.

Hier kann ich wenigstens für Linux kompilieren, so hat man mehreres zur Auswahl.



[hat wer noch ideen was man noch mit dem entitysystem anfangen könnte, d.h. welche zuweisungen sind noch sinnvoll?   wenn keine Vorschläge mehr kommen, hats gernot ja fast geschafft]


@gernot: sowas wie: TranslateEntity( entity:element,x:real,y:real,z:real,[useDelta:boolean])
  wäre noch sinnvoll, das gleiche wie moveentity, nur egal wie die rotation ist, das objekt orientiert sich an den globalen koordinaten bei der bewegung.

Turnentity lässt das objekt nicht rotieren, sondern dreht es in einem ruck auf den bestimmten winkel, wenn ich das richtig übersetzt habe(Turns an entity using the supplied pitch, yaw and roll values to increase/decrease the rotation.)

Und auf alle objektbezogenen Befehle müsste ja dann ein (entity:) folgen, wo es sich auf das jeweilige bezieht.


Achja was mir gerade einfällt, wenn ein entity ein parent hat, und dieses entity bewegt wird, egal ob rotation move, oder turn, oder sonstwas, immer zur eigenen achse, da es ein parent hat.

Rotation hingegen sollte es global und relativ geben.

hoffe ich hab mit meinen vorschlägen und bei den vorschlägen nicht zuviel durcheinander geworfen.



[edit] hab mal aus meinem cobra beispiel die 3ds dateien nehmen wollen, da stürzt die erstellte exe ab.daher umwandeln in .ddd und nun keine texurierung mehr, alles grau

hab grad gelesen, muss eine .ddd bei loadmesh sein, aber kannst du nicht .3ds mit einbauen?

Kitty Hello

Ah! Mein "turnentity" heisst derzeit AlignEntity :/
Das mit dem Kollisionsansatz von SEBE mach' ich. Automatisches Abrutschen könnt ihr voll vergessen :D Dafür würde ich echt Newton empfehlen.
Sollte sich einfachst koppeln lassen. Ich werd's mal abchecken.

3DS muss man umwandeln. Wenn's nicht geht, bitte schicken.

Schranz0r

#79
Wie wärs mit so Light Attenuation usw?


und evtl das der nur die nächsten  8 Lichter rendert?
Und oder Fakelight ?!?!?
Hat glaub BB auch...

Code (glbasic) Select
INLINE
    }; //namespace zumachen
        // Funktion definieren
    extern "C" void __stdcall glLightf(int, int, float);
        // Globale Konstanten
    #define GL_LIGHT0 0x4000
    #define GL_CONSTANT_ATTENUATION 0x1207
    #define GL_LINEAR_ATTENUATION             0x1208
    #define GL_QUADRATIC_ATTENUATION          0x1209
        // Namespace aufmachen
    namespace __GLBASIC__ {
ENDINLINE



FUNCTION glLightAttenuation: iLight, constant, linear, quadratic
INLINE
    glLightf(GL_LIGHT0+iLight, GL_CONSTANT_ATTENUATION,  constant);
    glLightf(GL_LIGHT0+iLight, GL_LINEAR_ATTENUATION, linear);
    glLightf(GL_LIGHT0+iLight, GL_QUADRATIC_ATTENUATION, quadratic);
ENDINLINE
ENDFUNCTION

Edit: und evtl das Entity system unterscheidbar machen von der anderen Syntax so wie das X_... bei 3D, nur Mit E_.. oder so ?
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

Das würde ich auch sagen, weil man ja mit dem ganzen X_ Befehlen das nächste Objekt manipuliert, und bei dem E_ System entitybezogen, da könnte man a.) durcheinanderkommen b.) Fehler produzieren

Schranz0r

So Lightrange ist nun drin ;)

Und bei CreateLight() muss man jetzt die Farbe mit angeben!

Download


Code (glbasic) Select
camera=CreateCamera()
EnableEntity(camera, TRUE) // this way you toggle cameras, too
light = CreateLight(RGB(0xff, 0xff, 0x00)) // Yellow Light!
SetLightRange(light,1, 0.001, 0.001)  // Set the range of the Light

ship = LoadMesh("ship.ddd")
terrain = LoadMesh("mario_level.ddd")
MoveEntity(terrain, 0, -3.5, 0)

shipx = 0
shipy = 5
shipz = 0
entx=EntityX(ship)
enty=EntityY(ship)
entz=EntityZ(ship)

PositionEntity(ship, shipx, shipy, shipz)
sc = 0.10
ScaleEntity(ship, sc,sc,sc)

EntityParent(camera, ship)           //entity camera // parent ship
PositionEntity(camera, 0, 5, 20)     // position camera relativ to ship
RotateEntity(camera, 0,90,0)
EntityParent(light, camera)


WHILE TRUE                          //controlling of ship

// Steuerung
IF KEY(203)
RotateEntity(ship, 0, 5, 0)        //noch zu machen ship rotation um eigene achse bei bewegung
ENDIF
IF KEY(205)
RotateEntity(ship, 0, -5, 0)
ENDIF

IF KEY(200) THEN MoveEntity(ship, 0, 0, -1)
IF KEY(208) THEN MoveEntity(ship, 0, 0,  1)
//Steuerung Ende
//Kollision
// IF EntityGroundCollide(ship) THEN MoveEntity(ship, 0, 1, 0)    //Kollision unterhalb Ship

DrawEntitySystem()
X_AMBIENT_LT 0, RGB(0xff, 0xff, 0xff)
X_DRAWAXES 0,0,0
X_MAKE2D
PRINT "Lightcolor: Yellow !!!!",10,10
SHOWSCREEN
WEND
Code (glbasic) Select
// an entity - that's a .ddd, a texture
// with position, rotation and scaling
TYPE T3DEntity

what // what is it? 0=ddd, 1=camera, 2=light,3= Ambientlight
active    // is active (or will not be drawn/used)
M[16]           // local matrix - internal use only
Mg[16] // global, final matrix (after child transformations)

parent=-1 // my parent (-1 if none)
childs[] // child items that are liked to this one

// DDD OBJECT
tex // holds a texture
ddd // holds a model

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
sx=1;sy=1;sz=1  // scale factors
alpha           // alpha transparency value

// CAMERA
znear = 1
zfar  = 1000
fov   = 45

// LIGHT
color=0xffffff // sorry...
constant= -1;linear=-1;quadratic=-1 // for Lightrange

ENDTYPE

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

//! ------------------------------
//! CREATION / REMOVAL
//! ------------------------------


// ------------------------------------------ //
//! Load a texture and return the channel it is stored
// \param filename$ - the file to load. Must be a .bmp or .png file
// \return the index for the texture (used for GETSPRITESIZE e.g.)
// ------------------------------------------ //
FUNCTION LoadTexture: filename$
LOCAL t, sx,sy

// find free sprite slot
GETSPRITESIZE t, sx, sy
WHILE sx>0 OR sy>0
INC t, 1
GETSPRITESIZE t, sx, sy
WEND

LOADSPRITE filename$, t
GETSPRITESIZE t, sx, sy
IF sx = 0 THEN DEBUG "failed to load: "+filename$+"\n"
RETURN t
ENDFUNCTION

// ------------------------------------------ //
//! Make a non-texure.
// \return -1
// ------------------------------------------ //
FUNCTION MakeNullTexture:
RETURN -1
ENDFUNCTION

// ------------------------------------------ //
//! Free the memory used for a texture and
//! apply no texture to all entities, that had this
//! texture assigned.
// \param ext - the texture index
// \return nothing
// ------------------------------------------ //
FUNCTION FreeTexture: ext
LOADSPRITE "", ext
// try to find the texture and set it to '-1'
FOREACH t IN g3DObj[]
IF t.tex = ext
t.tex = -1
ENDIF
NEXT
ENDFUNCTION



// ------------------------------------------ //
//! Loads a mesh object (.dda or .ddd) and creates an entity from it.
// \sa DuplicateEntity
// \param filename$ - the file to load. Must be .dda or .ddd file.
// \return the entity handle
// ------------------------------------------ //
FUNCTION LoadMesh: filename$
LOCAL t AS T3DEntity
LOCAL nc
t.what = 0
t.tex=-1
t.ddd=0

// Get free object slot
nc = X_NUMFACES(t.ddd)
WHILE nc>0
INC t.ddd, 1
nc = X_NUMFACES(t.ddd)
WEND

X_LOADOBJ filename$, t.ddd
IF X_NUMFACES(t.ddd) = 0 THEN DEBUG "failed to load: "+filename$+"\n"

RETURN AddEntity(t)
ENDFUNCTION

// ------------------------------------------ //
//! this function frees all resources for a loaded .ddd
//! object. All entities with this object get disabled.
// \param ext - the ddd index
// ------------------------------------------ //
FUNCTION FreeMesh: ext
// find it in the list and just drop it
FOREACH t IN g3DObj[]
IF t.ddd = ext THEN t.active = FALSE
NEXT
// make sure the memory is freed
X_OBJSTART ext
X_OBJEND
ENDFUNCTION

// ------------------------------------------ //
//! This function removes an entity from the world
//! This is getting done by disabling the object.
//! You must never use the handle for this object again, though
//! since this might change in a next version.
// \param handle - an entity handle
// ------------------------------------------ //
FUNCTION FreeEntity: handle
// must not delete it, since
// the indices would change
g3DObj[handle].active=FALSE
ENDFUNCTION

// ------------------------------------------ //
//! Creates an entity that represents a light.
//! The position is at 0,0,0 and the color is white.
//! The light is a 360 degree bulb light.
// \param color - set RGB color of the light
// \return the entity handle
// ------------------------------------------ //
FUNCTION CreateLight:color
LOCAL t AS T3DEntity
t.what = 2
t.color = color
RETURN AddEntity(t)
ENDFUNCTION

// ------------------------------------------ //
//! Set the range of a light.
// \param handle - a handle to an entity
// \param constant - How constant are the shining
// \param linear - i dont know(ask Gernot)
// \param quadratic - i dont know(ask Gernot)
// ------------------------------------------ //
FUNCTION SetLightRange: handle, constant, linear, quadratic
g3DObj[handle].constant = constant
g3DObj[handle].linear = linear
g3DObj[handle].quadratic= quadratic
ENDFUNCTION

// ------------------------------------------ //
//! Creates an entity that represents a camera.
//! You can have several cameras, though the one used for
//! scene rendering is the one you enabled last. This function
//! enalbes the new camera, thus making it the default camera.
// \return the entity handle
// ------------------------------------------ //
FUNCTION CreateCamera:
LOCAL t AS T3DEntity
LOCAL e
t.what = 1
e = AddEntity(t)
EnableEntity(e, TRUE)
RETURN e
ENDFUNCTION

// ------------------------------------------ //
//! This creates a full copy of an entity as a new entity.
//! If the entity is a camera, the new entity is _not_ the
//! default camera.
// \param original - a handle to an entity
// \return the new entity handle
// ------------------------------------------ //
FUNCTION DuplicateEntity: original
DIMPUSH g3DObj[], g3DObj[original]

// camera - disable the new one
IF g3DObj[LEN(g3DObj)-1].what = 1
EnableEntity(LEN(g3DObj)-1, FALSE)
ENDIF

RETURN LEN(g3DObj)-1
ENDFUNCTION


// ------------------------------------------ //
//! Adds an entity one to the global list. This is for internal purposes, only.
// \param e - a T3DEtnity TYPE
// \return "handle" to that object
// ------------------------------------------ //
FUNCTION AddEntity: e AS T3DEntity
e.active = TRUE
UpdateMatrix(e, FALSE)
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



//! ------------------------------
//! MOVE / ROTATE / SCALE / ENABLE
//! ------------------------------

// ------------------------------------------ //
//! With this function you can enable or disable an entity.
//! disabled entities will not be considered in the rendering
//! process. If you enable a camera, it get's the default
//! rendering camera. If you disable all cameras, nothing
//! get's rerndered. Thus, you should only enable the current
//! camera, but never disable one.
// \param handle - the handle to the entity
// \param onoff  - Enable (TRUE) or disable (FALSE) the entity
// ------------------------------------------ //
FUNCTION EnableEntity: handle, onoff
// is it a camera? Disable all cameras, first
IF g3DObj[handle].what = 1
FOREACH o IN g3DObj[]
IF o.what=1 THEN o.active=FALSE
NEXT
ENDIF

// enable/disable the entity
g3DObj[handle].active=onoff
ENDFUNCTION



// ------------------------------------------ //
//! Sets X,Y,Z position of an entity.
// \param handle - handle to an entity
// \param x,y,z - new position
// ------------------------------------------ //
FUNCTION PositionEntity: 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], FALSE)
ENDFUNCTION

//! Moves an entity relative by dx,dy,dz coordinates.
// \param handle - handle to an entity
// \param dx,dy,dz - offset to current position
FUNCTION MoveEntity: handle, dx,dy,dz
LOCAL x,y,z
x = g3DObj[handle].Mg[0] * dx + g3DObj[handle].Mg[4] * dy + g3DObj[handle].Mg[ 8] * dz
y = g3DObj[handle].Mg[1] * dx + g3DObj[handle].Mg[5] * dy + g3DObj[handle].Mg[ 9] * dz
z = g3DObj[handle].Mg[2] * dx + g3DObj[handle].Mg[6] * dy + g3DObj[handle].Mg[10] * dz

INC g3DObj[handle].x,x
INC g3DObj[handle].y,y
INC g3DObj[handle].z,z
UpdateMatrix(g3DObj[handle], FALSE)
ENDFUNCTION

// ------------------------------------------ //
//! Set global rotation angles.
// \param handle - handle to an entity
// \param rx,ry,rz - euler rotation angles around global axes.
// ------------------------------------------ //
FUNCTION AlignEntity: handle, rx,ry,rz
g3DObj[handle].rx=rx
g3DObj[handle].ry=ry
g3DObj[handle].rz=rz
UpdateMatrix(g3DObj[handle], FALSE)
ENDFUNCTION

// ------------------------------------------ //
//! Rotate additional to the current rotation of an entity.
// \param handle - handle to an entity
// \param rx,ry,rz - euler rotation angles around global axes.
// ------------------------------------------ //
FUNCTION RotateEntity: handle, drx,dry,drz
INC g3DObj[handle].rx,drx
INC g3DObj[handle].ry,dry
INC g3DObj[handle].rz,drz
UpdateMatrix(g3DObj[handle], FALSE)
ENDFUNCTION

// ------------------------------------------ //
//! Scales an entity. The scaling is only applied to the final entity.
//! Parents and childs will not be affected at all.
// \param handle - handle to an entity
// \param sx,sy,sz - Scale factors for local axes
// ------------------------------------------ //
FUNCTION ScaleEntity: handle, sx,sy,sz
g3DObj[handle].sx=sx
g3DObj[handle].sy=sy
g3DObj[handle].sz=sz
ENDFUNCTION

// ------------------------------------------ //
//! Set the amination start and end value
//! -> the model will then anmiate in between these values forever.
// \param handle - handle to the entity
// \param key_from - first animation keyframe
// \param key_to - last animation keyframe
// \param speed - number of seconds the animation from key_from to key_to will take
// ------------------------------------------ //
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


// ------------------------------------------ //
//! Return the x position of the entity
// \param entity - handle to the entity
// \return the X coordinate for that entity.
// ------------------------------------------ //
FUNCTION EntityX: entity
    RETURN g3DObj[entity].x
ENDFUNCTION

// ------------------------------------------ //
//! Return the y position of the entity
// \param entity - handle to the entity
// \return the Y coordinate for that entity.
// ------------------------------------------ //
FUNCTION EntityY: entity
    RETURN g3DObj[entity].y
ENDFUNCTION

// ------------------------------------------ //
//! Return the z position of the entity
// \param entity - handle to the entity
// \return the Z coordinate for that entity.
// ------------------------------------------ //
FUNCTION EntityZ: entity
    RETURN g3DObj[entity].z
ENDFUNCTION


//! ------------------------------
//! ADOPTION
//! ------------------------------


// ------------------------------------------ //
//! This function "pins" one entity to another. Thus, when you move the
//! parent object, the child moves/rotates correspondingly.
//! The position and rotation coordinates of the child object are
//! relative to the parent then.
// \param entity - handle to an entity
// \param parent - handle to the object that will be parent (-1 to release)
// ------------------------------------------ //
FUNCTION EntityParent: entity, parent

// remove old parent relationship
IF g3DObj[entity].parent>=0
// remove from parent's list
FOREACH c IN g3DObj[g3DObj[entity].parent].childs[]
IF c = entity THEN DELETE c
NEXT
ENDIF

// Set the new parent
g3DObj[entity].parent = parent

// add new relation
IF parent>=0
// see if the entity already _is_ a child
FOREACH c IN g3DObj[parent].childs[]
IF c = entity THEN RETURN
NEXT
// nopers, add it
DIMPUSH g3DObj[parent].childs[], entity
ENDIF
UpdateMatrix(g3DObj[entity], TRUE)
ENDFUNCTION


//! ------------------------------
//! DRAWING
//! ------------------------------


// ------------------------------------------ //
//! This function is called to draw the whole 3D entity system for you.
// ------------------------------------------ //
FUNCTION DrawEntitySystem:
LOCAL camgood=FALSE
// Set camera
FOREACH o IN g3DObj[]
IF o.what=1 AND o.active
camgood=TRUE
X_MAKE3D o.znear, o.zfar, o.fov
X_CAMERAUP o.Mg[4], o.Mg[5], o.Mg[6]
X_CAMERA o.Mg[12], o.Mg[13], o.Mg[14], _
o.Mg[12]+o.Mg[0], o.Mg[13]+o.Mg[1], o.Mg[14]+o.Mg[2]
DEBUG "Cam:"+FORMAT$(0,1,o.Mg[12])+", "+FORMAT$(0,1, o.Mg[13]) _
+", "+FORMAT$(0,1, o.Mg[14])+", "+FORMAT$(0,1, o.Mg[12]+o.Mg[0]) _
+", "+FORMAT$(0,1, o.Mg[13]+o.Mg[1])+", "+FORMAT$(0,1, o.Mg[14]+o.Mg[2]) _
+"\n"
BREAK
ENDIF
NEXT
IF camgood=FALSE THEN RETURN

// Lights
LOCAL iLight
FOREACH o IN g3DObj[]
IF o.what=2
X_SPOT_LT iLight, o.color, o.Mg[12], o.Mg[13], o.Mg[14], _
o.Mg[12]+o.Mg[0], o.Mg[13]+o.Mg[1], o.Mg[14]+o.Mg[2], 360
IF o.constant > 0 OR o.linear > 0 OR o.quadratic > 0
glLightAttenuation(iLight, o.constant, o.linear, o.quadratic)
ENDIF
INC iLight, 1
ENDIF
NEXT

FOR transparent = 0 TO 1
// look at each entity
FOREACH t IN g3DObj[]
// ignore disabled entities
IF t.active=FALSE OR t.what>0 THEN CONTINUE

// 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, -1

X_DRAWAXES t.Mg[12], t.Mg[13], t.Mg[14]
X_PRINT "OBJ"+t.parent+", c"+LEN(t.childs[]),  t.Mg[12], t.Mg[13], t.Mg[14], 0
// do the matrix magic
X_PUSHMATRIX
X_MULTMATRIX t.Mg[]

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



//! ------------------------------
//! MATRIX OPERATIONS
//! ------------------------------

// ------------------------------------------ //
//! Multiply a 4x4 matrix. The product may be a[] or b[]
//! internal use, only.
// \param product[] - the result
// \param a[], b[] - input matrix factors
// ------------------------------------------ //
FUNCTION MultMatrix4x4: product[], a[], b[]
LOCAL i
FOR i = 0 TO 3
LOCAL ai0=a[0*4+i],  ai1=a[1*4+i],  ai2=a[2*4+i],  ai3=a[3*4+i]
product[0*4+i] = ai0 * b[0*4+0] + ai1 * b[0*4+1] + ai2 * b[0*4+2] + ai3 * b[0*4+3]
product[1*4+i] = ai0 * b[1*4+0] + ai1 * b[1*4+1] + ai2 * b[1*4+2] + ai3 * b[1*4+3]
product[2*4+i] = ai0 * b[2*4+0] + ai1 * b[2*4+1] + ai2 * b[2*4+2] + ai3 * b[2*4+3]
product[3*4+i] = ai0 * b[3*4+0] + ai1 * b[3*4+1] + ai2 * b[3*4+2] + ai3 * b[3*4+3]
NEXT
ENDFUNCTION



//! Inverse of a matrix
//! B[] = A[]^-1
FUNCTION InverseMatrix: A[], invM[]
DIMDATA invM[], A[0], A[4], A[8], 0, _
A[1], A[5], A[9], 0, _
A[2], A[6], A[10],0, _
-(A[0]*A[12]+A[1]*A[13]+A[ 2]*A[14]), _
-(A[4]*A[12]+A[5]*A[13]+A[ 6]*A[14]), _
-(A[8]*A[12]+A[9]*A[13]+A[10]*A[14]), _
1
ENDFUNCTION


//! vertex[4] = vertex[4] * M[16]  - Multiply Vertex by Matrix
//? vertex[4] = vertex[4] * M[16]  - Multipliziert Vektor mit Matrix
// \sa NewtonMultMatrix
FUNCTION TransformVertex: vertex[], M[]
LOCAL out[]
DIM out[4]
out[0] = M[0] * vertex[0] + M[4] * vertex[1] + M[ 8] * vertex[2] + M[12]
out[1] = M[1] * vertex[0] + M[5] * vertex[1] + M[ 9] * vertex[2] + M[13]
out[2] = M[2] * vertex[0] + M[6] * vertex[1] + M[10] * vertex[2] + M[14]
vertex[] = out[]
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, ...
//!
//! This function also takes care, if an entity has a parent
//! and it calls itself for every attached child.
// \param e - a T3DEntity TYPE
// \param only_glob - Only update the global matrix (when parent changes)
// ------------------------------------------ //
FUNCTION UpdateMatrix: e AS T3DEntity, only_glob
LOCAL sa,sb,sc, ca,cb,cc
LOCAL sacb, cacb
IF only_glob = FALSE
   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
    ENDIF

IF e.parent=-1
e.Mg[] = e.M[]
ELSE
MultMatrix4x4(e.Mg[], g3DObj[e.parent].Mg[], e.M[])
ENDIF

// If you have childs, update their global matrix, too
FOREACH c IN e.childs[]
UpdateMatrix(g3DObj[c], TRUE)
NEXT
ENDFUNCTION



INLINE
    }; //namespace zumachen
        // Funktion definieren
    extern "C" void __stdcall glLightf(int, int, float);
        // Globale Konstanten
    #define GL_LIGHT0 0x4000
    #define GL_CONSTANT_ATTENUATION 0x1207
    #define GL_LINEAR_ATTENUATION             0x1208
    #define GL_QUADRATIC_ATTENUATION          0x1209
        // Namespace zumachen
    namespace __GLBASIC__ {
ENDINLINE



FUNCTION glLightAttenuation: iLight, constant, linear, quadratic
INLINE
    glLightf(GL_LIGHT0+iLight, GL_CONSTANT_ATTENUATION,  constant);
    glLightf(GL_LIGHT0+iLight, GL_LINEAR_ATTENUATION, linear);
    glLightf(GL_LIGHT0+iLight, GL_QUADRATIC_ATTENUATION, quadratic);
ENDINLINE
ENDFUNCTION
Da muss mir Gernot bei der Beschreibung helfen ^^

Code (glbasic) Select
// ------------------------------------------ //
//! Set the range of a light.
// \param handle - a handle to an entity
// \param constant - How constant are the shining
// \param linear - i dont know(ask Gernot)
// \param quadratic - i dont know(ask Gernot)
// ------------------------------------------ //
FUNCTION SetLightRange: handle, constant, linear, quadratic
g3DObj[handle].constant = constant
g3DObj[handle].linear = linear
g3DObj[handle].quadratic= quadratic
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

Kitty Hello

ok, cool. Mit M_ ist evtl. ganz cool. Oder: immer mit Entity beginnen?

x-tra

Entity is einfacher

Kitty Hello

OK, dreh' ich also um - EntityMove statt MoveEntity

x-tra

nochmal zum thema kollisionen.

bei bb3d ist das so

entitytype ship, 1
entitytype kugel, 2

usw.

und dann eben entitycollision 1,2,......    könnten art reaktion usw. folgen z.b. ob nur ein rückgabewert gegeben werden soll(intersection-kollision ohne reaktion aktiver art) oder bei kollision alle x,y,z einen schritt zurück bzw. alte position, sprung in anderen programmteil aufgrund zugeteilter reaktion usw. usw.

Schranz0r

Ne Gernot !

Bei dem 3D ist doch jetz immer so :

X_ Movement
X_Rotation
...

Beim Entity solls so ein:

E_Move
E_Rotate
E_LoadMash
...

so denk ich mir das
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

stell dir vor es kommt jemand von BB3D hier rüber und muss sich kaum umgewöhnen.

Wäre einfacher oder.

Schranz0r

stell dir vor, das hier ist aber kein BB !
Man sollte schon noch seinen eigen Stil weiterführen, sonnst kannst bald überall lesen GLBasic klaut die Befehlsyntax von BlitzBasic....

Wo wir wieder an dem Punkt sind, das Gernot nicht will, mit BB über einen Kamm geschoren zu werden!
Diese BB'ler sollen ruhig bei BB bleiben, da ist zu 80% eh nur schund dabei! Und zu 100% die Admins!
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

nun er wollte ja das entity system zu 100% übernehmen.
die die bb können hättens hier leichter, ich find das ist wichtig wenn man sich gleich daheim fühlt bei einer sprache.