BASIC

Author Topic: 3D Entity System [DE]  (Read 116146 times)

Offline bigsofty

  • Community Developer
  • Prof. Inline
  • ******
  • Posts: 2628
    • View Profile
Re: 3D Entity System [DE]
« Reply #345 on: 2010-Mar-09 »
Scaled entities are still not being detected properly by EntityCameraPick(), any calls to EntityScale() are not taken into consideration in the EntityPickLine() routine.

I tried to add...
Code: GLBasic [Select]
                X_PUSHMATRIX
                X_MULTMATRIX e.Mg[]
                X_SCALING e.sx,e.sy,e.sz // <-- Added this
                d = X_COLLISIONRAY(e.ddd, e.anim_collision, x,y,z, dx,dy,dz)
                X_POPMATRIX
...but it made no difference.
Cheers,

Ian.

“It is practically impossible to teach good programming style to students that have had prior exposure to BASIC.  As potential programmers, they are mentally mutilated beyond hope of regeneration.”
(E. W. Dijkstra)

Offline Kitty Hello

  • code monkey
  • Administrator
  • Prof. Inline
  • *******
  • Posts: 10714
  • here on my island the sea says 'hello'
    • View Profile
    • http://www.glbasic.com
Re: 3D Entity System [DE]
« Reply #346 on: 2010-Mar-09 »
No. Scaling and collision never worked properly :(

Offline bigsofty

  • Community Developer
  • Prof. Inline
  • ******
  • Posts: 2628
    • View Profile
Re: 3D Entity System [DE]
« Reply #347 on: 2010-Mar-09 »
Oh dear, I have a lot of entities that have been scaled in my program that are now not being detected properly. I will have another look to see if I can spot the problem.
Cheers,

Ian.

“It is practically impossible to teach good programming style to students that have had prior exposure to BASIC.  As potential programmers, they are mentally mutilated beyond hope of regeneration.”
(E. W. Dijkstra)

Offline bigsofty

  • Community Developer
  • Prof. Inline
  • ******
  • Posts: 2628
    • View Profile
Re: 3D Entity System [DE]
« Reply #348 on: 2010-Mar-09 »
OK, I see that the problem is not related to the entity system but to scaled objects in general.

Is there a possibility of a new command that will permanently scale a mesh(Change the internal GLB vertices list for an object) . It would fix a lot of problems with the collision detection and maybe even speed some programs up if as scaling is not required each game loop?
Cheers,

Ian.

“It is practically impossible to teach good programming style to students that have had prior exposure to BASIC.  As potential programmers, they are mentally mutilated beyond hope of regeneration.”
(E. W. Dijkstra)

Offline Kitty Hello

  • code monkey
  • Administrator
  • Prof. Inline
  • *******
  • Posts: 10714
  • here on my island the sea says 'hello'
    • View Profile
    • http://www.glbasic.com
Re: 3D Entity System [DE]
« Reply #349 on: 2010-Mar-10 »
not yet. I think about an idea. Maybe X_TRANSFORM_OBJ id%, mat[], where you can sclae/rotate/move an object's nodes totally as if you loaded it that way with X_LOADOBJ.

Offline Schranz0r

  • Premium User :)
  • Administrator
  • Prof. Inline
  • *******
  • Posts: 5022
  • O Rly?
    • View Profile
Re: 3D Entity System [DE]
« Reply #350 on: 2010-Mar-10 »
Sounds good Gernot!
I <3 DGArray's :D

PC:
AMD Ryzen 7 1700 @3.9GHz, 16GB HyperX Fury 3000MHz Ram, ASUS ROG GTX 1060 STRIX 6GB, Windows 10 Pro 64Bit, MSi Tomahawk B350 Mainboard

Offline bigsofty

  • Community Developer
  • Prof. Inline
  • ******
  • Posts: 2628
    • View Profile
Re: 3D Entity System [DE]
« Reply #351 on: 2010-Mar-10 »
not yet. I think about an idea. Maybe X_TRANSFORM_OBJ id%, mat[], where you can sclae/rotate/move an object's nodes totally as if you loaded it that way with X_LOADOBJ.

Thanks Gernot, that sounds very good!  :good:
Cheers,

Ian.

“It is practically impossible to teach good programming style to students that have had prior exposure to BASIC.  As potential programmers, they are mentally mutilated beyond hope of regeneration.”
(E. W. Dijkstra)

Offline bigsofty

  • Community Developer
  • Prof. Inline
  • ******
  • Posts: 2628
    • View Profile
Re: 3D Entity System [DE]
« Reply #352 on: 2010-Mar-10 »
Small bugget...

Code: GLBasic [Select]
//! Return the local yaw (Y rotation) of the object
// \param entity - the entity entity
// \return the angle
FUNCTION EntityGetYawGlobal%: entity%
LOCAL rx,ry,rz
        IF EntityIsValid(entity)=FALSE THEN END
        EntityGetEulers(g3DObj[Entity].Mg[], rx,ry,rz)
        RETURN ry
ENDFUNCTION

Code: GLBasic [Select]
//! Return the local yaw (Y rotation) of the object
// \param entity - the entity entity
// \return the angle
FUNCTION EntityGetYawGlobal%: entity%
LOCAL rx,ry,rz
        IF EntityIsValid(entity)=FALSE THEN END
        EntityGetEulers(g3DObj[entity].Mg[], rx,ry,rz) //<- "Entity" becomes "entity"
        RETURN ry
ENDFUNCTION
Cheers,

Ian.

“It is practically impossible to teach good programming style to students that have had prior exposure to BASIC.  As potential programmers, they are mentally mutilated beyond hope of regeneration.”
(E. W. Dijkstra)

Offline FutureCow

  • HelpEditor
  • Prof. Inline
  • ******
  • Posts: 680
    • View Profile
Re: 3D Entity System [DE]
« Reply #353 on: 2010-Oct-11 »
Okay, my 3D matrix mathematics knowledge is less than 0 but I'm finding that EntityGetYaw is returning values I don't expect.
If I do a complete circle, EntityGetYaw returns values from 0 to 90, then 90 to 0, then 0 to -90 then -90 to 0.

Therefore I have 2 places where I'm facing the same angle (eg. there are two locations where EntityGetYaw will return 45 for example, but those 2 locations are 90 degrees out from each other).

Also, EntityGetYaw and EntityGetYawGlobal contain the same code - is that the way it should be?

Offline FutureCow

  • HelpEditor
  • Prof. Inline
  • ******
  • Posts: 680
    • View Profile
Re: 3D Entity System [DE]
« Reply #354 on: 2010-Oct-13 »
Can someone please outline the difference between EntityMove and EntityMoveGlobal?

What I'm doing is
Load 3D Model (entity)
Move/rotate entity so it's where I want it to be
Assign parent to entity (so that any future changes to the parent's location/rotation affect this entity)

What happens is that when I assign the parent, my entity moves from where I put it. How do I assign a parent to an entity but keep the location/rotation it currently has? It's causing me SO many problems as I have a big chain of objects where each object is the child of another object. The minute I change the location of one I spend hours of trial and error moving all the rest to try and line them up again - it's driving me nuts!!!


And two bugs - the "Mg" below should be just "M"

Code: GLBasic [Select]
FUNCTION EntityGetYaw%: entity%
LOCAL rx,ry,rz
    IF EntityIsValid(entity)=FALSE THEN END
    EntityGetEulers(g3DObj[entity].Mg[], rx,ry,rz)                     // THIS LINE IS WRONG
    RETURN ry
ENDFUNCTION

//! Return the local pitch (Z rotation) of the object
//! relative to the parent object (if any)
// \param entity - the entity entity
// \return the angle
FUNCTION EntityGetPitch%: entity%
LOCAL rx,ry,rz
    IF EntityIsValid(entity)=FALSE THEN END
    EntityGetEulers(g3DObj[entity].Mg[], rx,ry,rz)                     // THIS LINE IS WRONG
    RETURN rz
ENDFUNCTION
« Last Edit: 2010-Oct-13 by FutureCow »

Offline Slydog

  • Prof. Inline
  • *****
  • Posts: 930
  • KodeSource
    • View Profile
    • KodeSource
Re: 3D Entity System [DE]
« Reply #355 on: 2010-Oct-13 »
I'll tell you upfront that I've never used the Entity System.

But, from the function names, I would assume 'EntityMove' moves an entity relative to its parent, and 'EntityMoveGlobal' moves an entity relative to the world's (0,0,0) location.

If you haven't tried using 'EntityMoveGlobal' for your problem, give that a try using the world coordinates you already have.  If I'm wrong on what these functions do, you may have another option.

If you can, place the parent at (0,0,0) with no rotation, and then apply the transformations to the children, so the children won't inherit the parent's transformation.  (Then move/rotate the parent back to normal after)
My current project (WIP) :: TwistedMaze <<  [Updated: 2015-11-25]

Offline FutureCow

  • HelpEditor
  • Prof. Inline
  • ******
  • Posts: 680
    • View Profile
Re: 3D Entity System [DE]
« Reply #356 on: 2010-Oct-14 »
Hmmm...  That sounds like a good starting point Slydog - I'll test to see if that's what the difference is between the standard and the global move.

I'll have a look at my code in regards to the order I'm moving things, hopefully if I move all the children before parents that might fix the problem - I thought I'd tried that but I'll try again. Thanks for the post!

If anyone else has anything to add in the meantime, please let me know.

KittyHello - if you're looking at this forum, can you update the code for the bug I listed? Thanks!

Offline Kitty Hello

  • code monkey
  • Administrator
  • Prof. Inline
  • *******
  • Posts: 10714
  • here on my island the sea says 'hello'
    • View Profile
    • http://www.glbasic.com
Re: 3D Entity System [DE]
« Reply #357 on: 2010-Oct-14 »
I think EntityMove moves from the current position in some direction, whereas EntityMoveGlobal sets the absolute position at once.

Offline kanonet

  • Administrator
  • Prof. Inline
  • *******
  • Posts: 1142
    • View Profile
    • My GLBasic code archiv
Re: 3D Entity System [DE]
« Reply #358 on: 2010-Dec-08 »
Ich habe dem Entitysystem bei mir eine Funktion hinzugefügt, mit der man (ddd-)Objekte auf eine bestimmte Größe skalieren kann. Im Gegensatz zu EntityScale gibt man dabei keinen Skalierungsfaktor an, sondern die gewünschte (absolute) Größe des Objekts, es ist also nicht nötig die genaue Ursprungsgröße zu kennen.
Da die Funktion lediglich selbst die entsprechenden Skalierungsfaktoren ausrechnet und dann spiechert, sollte sie keine Konflikte oder Verlangsamungen innerhalb des ES auslösen und sich somit perfekt integrieren. Einzig zu beachten wäre: Animationen werden vermutlich ignoriert, bzw. ich habe keine Ahnung, wie die Funktion auf eine animiertes Objekt wirken würde.

Vielleicht nützt es ja dem einen oder anderen, daher hier der Code:
Code: GLBasic [Select]
// ------------------------------------------ //
//! Scales an entity. Object will fit in an Box with the Size sx, sy, sz.
//! The scaling is only applied TO the final entity.
//! Parents and childs will not be affected at all.
// \param entity - entity to an entity
// \param sx,sy,sz - new size if the object
// ------------------------------------------ //
FUNCTION EntityFit%: entity%, sx,sy,sz
        IF EntityIsValid(entity)=FALSE THEN RETURN
        LOCAL count, face[]
        count = X_NUMFACES( g3DObj[entity].ddd )
        LOCAL maxX = -1000000000
        LOCAL maxY = -1000000000
        LOCAL maxZ = -1000000000
        LOCAL minX = 1000000000
        LOCAL minY = 1000000000
        LOCAL minZ = 1000000000
        FOR i = 0 TO count - 1
                X_GETFACE g3DObj[entity].ddd , 0 , i , face[]
                IF minX > ( face[ 0 ][ 0 ] ) THEN minX = ( face[ 0 ][ 0 ] )
                IF minX > ( face[ 1 ][ 0 ] ) THEN minX = ( face[ 1 ][ 0 ] )
                IF minX > ( face[ 2 ][ 0 ] ) THEN minX = ( face[ 2 ][ 0 ] )
                IF minY > ( face[ 0 ][ 1 ] ) THEN minY = ( face[ 0 ][ 1 ] )
                IF minY > ( face[ 1 ][ 1 ] ) THEN minY = ( face[ 1 ][ 1 ] )
                IF minY > ( face[ 2 ][ 1 ] ) THEN minY = ( face[ 2 ][ 1 ] )
                IF minZ > ( face[ 0 ][ 2 ] ) THEN minZ = ( face[ 0 ][ 2 ] )
                IF minZ > ( face[ 1 ][ 2 ] ) THEN minZ = ( face[ 1 ][ 2 ] )
                IF minZ > ( face[ 2 ][ 2 ] ) THEN minZ = ( face[ 2 ][ 2 ] )
                IF maxX < ( face[ 0 ][ 0 ] ) THEN maxX = ( face[ 0 ][ 0 ] )
                IF maxX < ( face[ 1 ][ 0 ] ) THEN maxX = ( face[ 1 ][ 0 ] )
                IF maxX < ( face[ 2 ][ 0 ] ) THEN maxX = ( face[ 2 ][ 0 ] )
                IF maxY < ( face[ 0 ][ 1 ] ) THEN maxY = ( face[ 0 ][ 1 ] )
                IF maxY < ( face[ 1 ][ 1 ] ) THEN maxY = ( face[ 1 ][ 1 ] )
                IF maxY < ( face[ 2 ][ 1 ] ) THEN maxY = ( face[ 2 ][ 1 ] )
                IF maxZ < ( face[ 0 ][ 2 ] ) THEN maxZ = ( face[ 0 ][ 2 ] )
                IF maxZ < ( face[ 1 ][ 2 ] ) THEN maxZ = ( face[ 1 ][ 2 ] )
                IF maxZ < ( face[ 2 ][ 2 ] ) THEN maxZ = ( face[ 2 ][ 2 ] )
        NEXT
        g3DObj[entity].sx=sx/ABS(maxX-minX)
        g3DObj[entity].sy=sy/ABS(maxY-minY)
        g3DObj[entity].sz=sz/ABS(maxZ-minZ)
ENDFUNCTION

(Die Grundsätzliche Idee der Umsetzung stammt aus Helmlos' Analyse3DObject)
Lenovo Thinkpad T430u: Intel i5-3317U, 8GB DDR3, NVidia GeForce 620M, Micron RealSSD C400 @Win7 x64

Offline Kitty Hello

  • code monkey
  • Administrator
  • Prof. Inline
  • *******
  • Posts: 10714
  • here on my island the sea says 'hello'
    • View Profile
    • http://www.glbasic.com
Re: 3D Entity System [DE]
« Reply #359 on: 2010-Dec-08 »
Danke! Hab's dazugefügt.