3D Entity System [EN]

Previous topic - Next topic

Moru

#15
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.

Quentin

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.

Moru

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 :-)

Kitty Hello

New command EntityMoveGlobal2D - places an entity on the screen's pixel coordinates.

Crivens

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.

Kitty Hello

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).

Crivens

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.

Kitty Hello

Ah, that way. Interesting idea.

Crivens

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.

Kitty Hello

Update. Object stays at 2d pixel position.

Crivens

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.

Kitty Hello

New update fixed the EntitySetPosition2D command and adds an example how to use it.

Crivens

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.

Kitty Hello

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.

Crivens

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.