3D Entity System [DE]

Previous topic - Next topic

Quentin

Gernot already did a new update, so disabled entities are not overwritten, unless they're released

Regarding your problem:
a small example would be very helpful :)

bigsofty

Thanks for the offer Quentin, I'll bang up a demo when I'm near my home computer.
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

Thanks Ocean / Kitty Hello for the description. Looks like it would be worth having a play with!

bigsofty

Quote from: bigsofty on 2010-Feb-16
Thanks for the offer Quentin, I'll bang up a demo when I'm near my home computer.

Attaching a camera to an entity was not causing the gimbal lock, "EntityAlignTowards(cam%, target%)" was causing it. I removed this and all was fine.
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)

codegit

Just noticed small mistake in latest source.

FUNCTION EntityFreeMesh: ext
   // find it in the list and just drop it
   FOREACH t IN g3DObj[]
      IF t.ddd = ext
         t.valid_slot% = FALSE
         t.avtice = FALSE
      ENDIF
   NEXT
   // make sure the memory is freed
   X_OBJSTART ext
   X_OBJEND
ENDFUNCTION

t.avtice should be t.active??
=D
------------------------------------------
1 X Acer TravelMate 4270, laptop, XP PRO
1 X Dell Studio 17 laptop, Windows 7
1 X MacBook Pro 2,2 GHz Core 2 Duo, 2 GB RAM, 160 GB HDD, 9400M
2 X iTouch
1 X HTC Desire (Android 2.1)
iPad soon to be added

Quentin

of course it should :)

Kitty Hello

Silly me.
Can you give me an example, where EntityAlignTowards causes a gimbal lock?

bigsofty

#337
This piece of code shows two bugs...

1) An entity once scaled, does not 'pick' properly, the pick routine seems to detect the unscaled mesh. Test this by changing the scale of the cube.
2) Deformation of the entity when an entity uses "EntityAlignTowards()", see the cube deform as it rotates around the axis, only when EntityAlignTowards() is used. This could explain the gimbal lock I had ealier in a camera, as its parent was the cube?

Code (glbasic) Select
GLOBAL camera

camera=EntityCreateCamera()

EntitySetCameraRange(camera, 1, 1000)
EntityEnable(camera, TRUE)

cube = EntityCreateCuboid(30,30,30)
EntityScale(cube,0.2,0.2,0.2) // Take this line out to see Picking working properly
axis = EntityCreateAxes(20)
piv = EntityCreatePivot()
EntitySetPosition(piv, 0, 0, 0)
EntitySetPosition(camera, 0, 13, -100)
EntityParent(cube, axis)
EntityMove(cube, 40, 0, 0)

EntitySetPickable(cube, TRUE);
EntitySetName(cube, "cube")
EntitySetPickable(haupt, TRUE);
EntitySetName(axis, "axis")

WHILE TRUE
EntityRotate(axis, 0.1,0.1,-0.1)
EntityAlignTowards(cube,axis) // Take this line out to stop the cube getting deformed
EntityDrawSystem()


// Camera picking
MOUSESTATE mx, my, b1, b2
PRINT "X", mx-8, my-8
pick = EntityCameraPick(mx, my)
IF pick>=0
PRINT "Cam-Pick: " + EntityGetName$(pick), 0,20
ELSE
PRINT "No pick", 0,20
ENDIF

SHOWSCREEN
WEND

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

See this post please Gernot, this bug affects this lib quite a bit, causing all sort of errors...

http://www.glbasic.com/forum/index.php?topic=4201.0
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

#339
I played with sliding collisions now.
The attached thing is a complete Super Monkey Ball example!!

Video:
http://www.youtube.com/watch?v=2C3PvrPsMAM

Code (glbasic) Select

FUNCTION Monkeyball:
LOCAL ball%, cam%, light
LOCAL world%[]
LOCAL vx, vy, vz // ball speed
LOCAL x%,y%
CLEARSCREEN 0
FOR x=0 TO 7; FOR y=0 TO 7; IF MOD(x+y, 2) THEN DRAWRECT x*8,y*8,8,8,0xffffff; NEXT; NEXT
LOCAL checker% = GENSPRITE()
GRABSPRITE checker,0,0,8*8, 8*8
CLEARSCREEN 0
ball% = EntityCreateSphere(6.0, 16)
EntityCollisionSetRadius(ball, 3.0)
EntityEnableShadow(ball)
EntityApplyTexture(ball, checker)

cam% = EntityCreateCamera()
EntityParent(cam, ball)
EntitySetPosition(cam, 0, 5, 33)
EntityRotate(cam, 0,180,0)

light = EntityCreateLight(RGB(255,255,255) )
EntityMove(light, 0,99,0)
EntityMoveGlobal(ball, 0.1,3,0)

// make a few "world" objects just to test the ball
LOCAL ob%
ob% = EntityCreateCuboid(100,1,100)
EntityApplyTexture(ob, checker)
DIMPUSH world%[], ob

ob% = EntityCreateCylinder(12,2,4,12,3)
EntityApplyTexture(ob, checker)
EntityMove(ob, 10,0,0)
DIMPUSH world%[], ob

ob% = EntityCreateCuboid(30,1,100)
EntityApplyTexture(ob, checker)
EntityMove(ob, -35,1,0)
EntityRotate(ob, 0,0,-20)
DIMPUSH world%[], ob

ob% = EntityCreateCuboid(10,5,10)
EntityApplyTexture(ob, checker)
EntityMove(ob, 30,3,0)
DIMPUSH world%[], ob

WHILE TRUE
// Draw all entites, using entity camera
EntityDrawSystem()
LOCAL spd = 0.1
// move the ball
LOCAL dt = 17.0 * 0.01 // [ms] per frame
LOCAL mx,my,b1,b2
MOUSESTATE mx, my, b1, b2
mx=MIN(340,MAX(300,mx))
my=MIN(260,MAX(220,my))
X_MAKE2D
DRAWRECT 300,220,40,40,RGB(128,255,128)
DRAWRECT mx-4,my-4,8,8,RGB(255,255,255)
INC vx, .25*(mx-320)*spd*dt
INC vz, .25*(my-240)*spd*dt
EntityMove(ball, vx*dt, vy*dt, vz*dt)

vx = vx*0.99
vz = vz*0.99
vy = (vy - 9.81*dt*spd) * 0.95

// sliding collision with all objects
FOREACH o IN world[]
LOCAL nx, ny, nz
IF EntityCollisionSlide(ball, o, nx, ny, nz)
// mirror the velocity at the contact surface!
// v=v - s*n * dot(v,n) / len(n)
LOCAL lenn = SQR(nx*nx+ny*ny+nz*nz)
LOCAL dot = (vx*nx+vy*ny+vz*nz) / lenn
vx = (vx-2*nx*dot)*.95
vy = (vy-2*ny*dot)*.95
vz = (vz-2*nz*dot)*.95

IF vy > 0 // bounced upwards
vy = vy*.60
ENDIF
ENDIF
NEXT
SHOWSCREEN
WEND
ENDFUNCTION


bigsofty

One word, "WOW!", very nice work Gernot!  :good:

P.S. has the scaling collision ray bug been solved?
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)

Schranz0r

@ Gernot:

Also gibts ne neue Gbas für das Entity?
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

codegit

GLBASIC, just gets better and better.  :enc:  =D
------------------------------------------
1 X Acer TravelMate 4270, laptop, XP PRO
1 X Dell Studio 17 laptop, Windows 7
1 X MacBook Pro 2,2 GHz Core 2 Duo, 2 GB RAM, 160 GB HDD, 9400M
2 X iTouch
1 X HTC Desire (Android 2.1)
iPad soon to be added

Schranz0r

Quote from: Kitty Hello on 2010-Feb-25
I played with sliding collisions now.
The attached thing is a complete Super Monkey Ball example!!

Video:
http://www.youtube.com/watch?v=2C3PvrPsMAM

Code (glbasic) Select

FUNCTION Monkeyball:
LOCAL ball%, cam%, light
LOCAL world%[]
LOCAL vx, vy, vz // ball speed
LOCAL x%,y%
CLEARSCREEN 0
FOR x=0 TO 7; FOR y=0 TO 7; IF MOD(x+y, 2) THEN DRAWRECT x*8,y*8,8,8,0xffffff; NEXT; NEXT
LOCAL checker% = GENSPRITE()
GRABSPRITE checker,0,0,8*8, 8*8
CLEARSCREEN 0
ball% = EntityCreateSphere(6.0, 16)
EntityCollisionSetRadius(ball, 3.0)
EntityEnableShadow(ball)
EntityApplyTexture(ball, checker)

cam% = EntityCreateCamera()
EntityParent(cam, ball)
EntitySetPosition(cam, 0, 5, 33)
EntityRotate(cam, 0,180,0)

light = EntityCreateLight(RGB(255,255,255) )
EntityMove(light, 0,99,0)
EntityMoveGlobal(ball, 0.1,3,0)

// make a few "world" objects just to test the ball
LOCAL ob%
ob% = EntityCreateCuboid(100,1,100)
EntityApplyTexture(ob, checker)
DIMPUSH world%[], ob

ob% = EntityCreateCylinder(12,2,4,12,3)
EntityApplyTexture(ob, checker)
EntityMove(ob, 10,0,0)
DIMPUSH world%[], ob

ob% = EntityCreateCuboid(30,1,100)
EntityApplyTexture(ob, checker)
EntityMove(ob, -35,1,0)
EntityRotate(ob, 0,0,-20)
DIMPUSH world%[], ob

ob% = EntityCreateCuboid(10,5,10)
EntityApplyTexture(ob, checker)
EntityMove(ob, 30,3,0)
DIMPUSH world%[], ob

WHILE TRUE
// Draw all entites, using entity camera
EntityDrawSystem()
LOCAL spd = 0.1
// move the ball
LOCAL dt = 17.0 * 0.01 // [ms] per frame
LOCAL mx,my,b1,b2
MOUSESTATE mx, my, b1, b2
mx=MIN(340,MAX(300,mx))
my=MIN(260,MAX(220,my))
X_MAKE2D
DRAWRECT 300,220,40,40,RGB(128,255,128)
DRAWRECT mx-4,my-4,8,8,RGB(255,255,255)
INC vx, .25*(mx-320)*spd*dt
INC vz, .25*(my-240)*spd*dt
EntityMove(ball, vx*dt, vy*dt, vz*dt)

vx = vx*0.99
vz = vz*0.99
vy = (vy - 9.81*dt*spd) * 0.95

// sliding collision with all objects
FOREACH o IN world[]
LOCAL nx, ny, nz
IF EntityCollisionSlide(ball, o, nx, ny, nz)
// mirror the velocity at the contact surface!
// v=v - s*n * dot(v,n) / len(n)
LOCAL lenn = SQR(nx*nx+ny*ny+nz*nz)
LOCAL dot = (vx*nx+vy*ny+vz*nz) / lenn
vx = (vx-2*nx*dot)*.95
vy = (vy-2*ny*dot)*.95
vz = (vz-2*nz*dot)*.95

IF vy > 0 // bounced upwards
vy = vy*.60
ENDIF
ENDIF
NEXT
SHOWSCREEN
WEND
ENDFUNCTION


NEW GBAS?
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, I updated the archive.