Author Topic: 3D Entity System [EN]  (Read 20590 times)

Offline Moru

  • Administrator
  • Prof. Inline
  • *******
  • Posts: 1749
    • View Profile
    • Homepage
Re: 3D Entity System [EN]
« Reply #15 on: 2009-Feb-09 »
MAX_RANGE is from your code, is 1000.
DynLoadSprite is something I've been using long so I just keept using it. Didn't know there was anything in the entity layer that could do it, thanks for the tip :-)

Ok, this is the complete (cut off the 2D unimportant stuff and actually tested the project :-)

Code: GLBasic [Select]
// --------------------------------- //
// Project: Help-Forum
// Start: Sunday, February 08, 2009
// IDE Version: 6.156

Init3d()
END


TYPE OBJECT                                     // The 3D objects
        obj                                             // Object ID
        x; y; z                                 // Position
        dx; dy; dz                              // delta for movement
        rx; ry; rz                              // rotation
ENDTYPE


GLOBAL MAX_RANGE = 1000
GLOBAL camera[] AS OBJECT


FUNCTION Init3d:
        LOCAL cam AS OBJECT

        RESTORE cameras
        FOR n = 0 TO 4
                READ cam.x, cam.y, cam.z
                READ cam.rx, cam.ry, cam.rz
                cam.obj = EntityCreateCamera()
                EntitySetCameraRange(cam.obj, 1, MAX_RANGE)
                EntitySetPosition(cam.obj, cam.x, cam.y, cam.z)
                EntitySetRotation(cam.obj, cam.rx, cam.ry, cam.rz)
                DIMPUSH camera[], cam           // Add the camera to the array of cams
                DEBUG "obj:"+camera[n].obj+"\n"
        NEXT
        active_cam = 4                                  // The last added camera is the active camera

        light = EntityCreateLight(RGB(255,255,255))
        EntityMove(light, -150, 150, 150)

ENDFUNCTION


STARTDATA cameras:
        DATA 35, 70, 150        // Position of camera 0
        DATA 25, 180, 0         // rotation
        DATA 35, 70, -150       // Position of camera 1
        DATA 25, 0, 0           // rotation
        DATA 35, 70, 150        // Position of camera 2
        DATA 25, 180, 0         // rotation
        DATA 35, 70, 150        // Position of camera 3
        DATA 25, 180, 0         // rotation
        DATA 35, 70, 150        // Position of camera 4
        DATA 25, 180, 0         // rotation
ENDDATA
 

Edit: EntityLoadTexture() is not doing what I want it to do, it doesn't load animations... and since sprites and animations share the index I have to write my own routine to load animations anyway.
« Last Edit: 2009-Feb-09 by Moru »

Offline Quentin

  • Prof. Inline
  • *****
  • Posts: 899
    • View Profile
Re: 3D Entity System [EN]
« Reply #16 on: 2009-Feb-09 »
ahh yeah, now it seems to be clear.

my fault. I thought entity id's starts by 1, but they start at 0

Regarding your cameras:
Seems to be a bug of the entity system. You can create more than one camera. BUT: If you create the second camera, the first one is disabled. (active = FALSE). Thus if you create the third camera, it will overwrite the first one, as the state of the first camera is inactive. :((

Code: GLBasic [Select]
FUNCTION EntityCreateCamera:
LOCAL t AS T3DEntity
LOCAL e
        t.what = 1
        t.name$="camera"
        e = EntityAddInternal(t)
        //EntityEnable(e, TRUE)
        RETURN e
ENDFUNCTION
 

This is a modified version of EntityCreateCamera. The command EntityEnable is commented. So you must call EntityEnable is your code to set the current camera. Now the cameras are numbered correctly from 0 to 4 in the debug window.
BUT in case you create new Entity objects after the camera creation the inactive cameras will be overwritten again. Too bad. Until Gernot has fixed this, you will have to work with only one camera. In most cases this should be sufficient. You can easily turn your camera if every direction you want. Just remember camera positions and rotation angles in your cam TYPE and use EntitySetPosition and EntitySetRotation for replacement.

Hope this will help you.

Offline Moru

  • Administrator
  • Prof. Inline
  • *******
  • Posts: 1749
    • View Profile
    • Homepage
Re: 3D Entity System [EN]
« Reply #17 on: 2009-Feb-09 »
No problem, that was the way I was going to do this before I saw that you can have more than one camera. Thought I could make it easy for myself :-)

Offline Kitty Hello

  • code monkey
  • Administrator
  • Prof. Inline
  • *******
  • Posts: 10649
  • here on my island the sea says 'hello'
    • View Profile
    • http://www.glbasic.com
Re: 3D Entity System [EN]
« Reply #18 on: 2011-Sep-07 »
New command EntityMoveGlobal2D - places an entity on the screen's pixel coordinates.

Offline Crivens

  • Prof. Inline
  • *****
  • Posts: 913
    • View Profile
Re: 3D Entity System [EN]
« Reply #19 on: 2011-Sep-07 »
Cool. So I should call this every showscreen loop to keep a 3D object at the same position on the screen? Where can I download the updated version from?

Cheers
Current fave quote: Cause you like musicians and I like people with boobs.

Offline Kitty Hello

  • code monkey
  • Administrator
  • Prof. Inline
  • *******
  • Posts: 10649
  • here on my island the sea says 'hello'
    • View Profile
    • http://www.glbasic.com
Re: 3D Entity System [EN]
« Reply #20 on: 2011-Sep-08 »
Link is the same as in post #1.
Once you have set the position and don't move the camera, the object will stay there (that's the point of the ES).

Offline Crivens

  • Prof. Inline
  • *****
  • Posts: 913
    • View Profile
Re: 3D Entity System [EN]
« Reply #21 on: 2011-Sep-08 »
Sorry, should have added that my game has the camera moving around all the time. I assume then you need to keep calling that routine every time the camera moved. Would be nice though if you could set the 2D coords for a 3D object and then the ES would sort it out for you for each draw loop.

Cheers
Current fave quote: Cause you like musicians and I like people with boobs.

Offline Kitty Hello

  • code monkey
  • Administrator
  • Prof. Inline
  • *******
  • Posts: 10649
  • here on my island the sea says 'hello'
    • View Profile
    • http://www.glbasic.com
Re: 3D Entity System [EN]
« Reply #22 on: 2011-Sep-08 »
Ah, that way. Interesting idea.

Offline Crivens

  • Prof. Inline
  • *****
  • Posts: 913
    • View Profile
Re: 3D Entity System [EN]
« Reply #23 on: 2011-Sep-08 »
Yeah, I was just worried about using the movement commands inside the ES drawing routine as I really didn't know what I was doing in that bit, especially about when to move the object etc.

Cheers
Current fave quote: Cause you like musicians and I like people with boobs.

Offline Kitty Hello

  • code monkey
  • Administrator
  • Prof. Inline
  • *******
  • Posts: 10649
  • here on my island the sea says 'hello'
    • View Profile
    • http://www.glbasic.com
Re: 3D Entity System [EN]
« Reply #24 on: 2011-Sep-09 »
Update. Object stays at 2d pixel position.

Offline Crivens

  • Prof. Inline
  • *****
  • Posts: 913
    • View Profile
Re: 3D Entity System [EN]
« Reply #25 on: 2011-Sep-09 »
Hmm, dunno if I'm doing it wrong but it doesn't seem to stay in the same place. I setup an object like this:-
Code: GLBasic [Select]
GLOBAL testobj%,testtexture%,testtexturex%,testtexturey%
testtexture=EntityLoadTexture("home.png")
testobj=EntityCreatePlain(10,10)
EntityApplyTexture(testobj,testtexture,-1)
EntityRotate(testobj,90,0,0)
EntitySetPosition2D(testobj,10,10,-1)
And it put the object in the middle of the screen. And then when I moved around it didn't stay in the same place on the screen. I put some debug into the main drawall section and can see the values of wx and wy changing all the time but it doesn't seem to have an effect. Note my camera has moved around and rotated a load if this effects anything. Plus is there a way to say lets put a 3D object at this point on the screen at this rotation? Main reason is so that we can use 3D objects as text, HUD images etc. If an object rotates with the rest of the game then it won't work. And can you turn lighting off on a selected object with the ES system, but every other object in the game is effected by lighting? Just so can then do the HUD objects without worry about lighting effects on them.

Note my code above is outside the main game loop and nothing else is ever done with the object.

Cheers
Current fave quote: Cause you like musicians and I like people with boobs.

Offline Kitty Hello

  • code monkey
  • Administrator
  • Prof. Inline
  • *******
  • Posts: 10649
  • here on my island the sea says 'hello'
    • View Profile
    • http://www.glbasic.com
Re: 3D Entity System [EN]
« Reply #26 on: 2011-Nov-10 »
New update fixed the EntitySetPosition2D command and adds an example how to use it.

Offline Crivens

  • Prof. Inline
  • *****
  • Posts: 913
    • View Profile
Re: 3D Entity System [EN]
« Reply #27 on: 2011-Nov-10 »
Damn. Stupid sunny holiday stopping me from using GLB!  Hmm nevermind will console myself with sun, beach, and sea... Rats... :)

Thanks a lot Gernot! Will check it out when I get back.

Cheers
Current fave quote: Cause you like musicians and I like people with boobs.

Offline Kitty Hello

  • code monkey
  • Administrator
  • Prof. Inline
  • *******
  • Posts: 10649
  • here on my island the sea says 'hello'
    • View Profile
    • http://www.glbasic.com
Re: 3D Entity System [EN]
« Reply #28 on: 2011-Nov-10 »
Yes. Great  :glare: It's November here in Germany. The most ugly time of the year, and you talk about beaches...
First thing I do when I win in a lottery is move to Florida.

Offline Crivens

  • Prof. Inline
  • *****
  • Posts: 913
    • View Profile
Re: 3D Entity System [EN]
« Reply #29 on: 2011-Nov-11 »
Heh it's November in Cyprus too. Just it's very nice weather :) Apparently we may get some rain on Wednesday. Otherwise around 24c and sunny :)

Cheers
Current fave quote: Cause you like musicians and I like people with boobs.