3D Entity System [DE]

Previous topic - Next topic

bigsofty

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)

Kitty Hello

No. Scaling and collision never worked properly :(

bigsofty

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)

bigsofty

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)

Kitty Hello

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.

Schranz0r

Sounds good Gernot!
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

bigsofty

Quote from: Kitty Hello 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)

bigsofty

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)

FutureCow

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?

FutureCow

#354
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


Slydog

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]

FutureCow

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!

Kitty Hello

I think EntityMove moves from the current position in some direction, whereas EntityMoveGlobal sets the absolute position at once.

kanonet

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

Kitty Hello

Danke! Hab's dazugefügt.