GROUPS
Blitz3D Forums/Blitz3D Beginners Area/GROUPS
| ||
Is it possible in Blitz3D so I can only use 1 name for all the cubes I'm making and not have to name each individual one??? thanks |
| ||
Yeah, like this. You can give them whichever name you choose, in this case I named them as cubeList.Graphics3D(800, 600) SetBuffer BackBuffer() Dim cubeList(10) For i = 0 To 9 cubeList(i) = CreateCube() PositionEntity cubeList(i), -25 + (i * 5), 0, 50 RotateEntity cubeList(i), 45, 45, 45 Next camera = CreateCamera() light = CreateLight() Repeat Cls UpdateWorld() RenderWorld() Flip() Until KeyDown(1) End |
| ||
You've got arrays. You've got custom types (linked lists). You've got banks (the entity handle is an integer, so store it in that format). You've also got the manual that came with the program (you can find it via the 'Help' tab in the program's editor (IDE)) which answers all these questions for you. |
| ||
And there's also what Zethrax just said ^, banks are a good thing to play around with. ;) |
| ||
Something like this will work :: ;Please note that I've included a few extra fields here to illustrate the Position / Rotation / etc... Global mynewobj.cube ; We can name the 1st part of this code AFTER Global, whatever we want. It is simply to give the Type a new variable to work with. The 2nd part AFTER the dot is your ACTUAL above Type name being called. We process the Type with For To :: You can do the same with Rotation, Scale the Object, even Color the Object, Read from Files in your For Next instead of Random values, Make different types of cubes transparent or inbetween transparent & opaque... The sky's the limit! EDIT :: @steve_ancell --- Nice example using Dim! ~GF |
| ||
Thanks Guy, I do tend to have a habbit of stashing stuff inside Dims. :D |
| ||
I'm also a fan of stashing stuff inside Dims ;) Good to see a comparison between the use of types and Dims. |
| ||
I usually store other objects inside a type and then make an instance of that type inside an Dim, or array in the case of Monkey-X. If I don't need extra information attached then I just stash the object itself inside the array. |
| ||
I usually store other objects inside a type and then make an instance of that type inside an Dim, or array and what is the usefulness of doing that ? With dim array you can access an instance directly using its index, with customtype, you can access an instance directly using its handle. So not sure what is the advantage to mix the 2 ? |
| ||
Do you need to access the cubes later ? If not, you just don't need to name them wheter using types or arrays. Just parent them to a pivot Once not usefull anymore, just free the pivot, it will release all entities attached. Local ParentCube = CreatePivot() Local cube Cube = CreateCube(ParentCube) PositionEntity Cube, x1,y1,z1 Cube = CreateCube(ParentCube) PositionEntity Cube, x2,y2,z2 Etc ... Repeat Blablabla Until Quit FreeEntity ParentCube And by the way, you can still get the reference to the created cubes using GetChild Local ParentCube = CreatePivot() PositionEntity ( CreateCube(ParentCube), x1,y1,z1 ) PositionEntity ( CreateCube(ParentCube), x2,y2,z2 ) PositionEntity ( CreateCube(ParentCube), x3,y3,z3 ) Etc ... TurnEntity GetChild(ParentCube, 1), 0,90,0 ; turn the first cube TurnEntity GetChild(ParentCube, 2), 0,180,0 ; turn the second cube Repeat Blablabla Until Quit FreeEntity ParentCube |
| ||
@RemiD: I sometimes do that if I need extra information attached, it may or may not be useful to others but is useful to me. It all depends on your needs. ;) [edit]To be more specific, by extra information I mean stuff like: desired speed, dead or dying, friend or foe, and what ever else springs to mind etc... Oh and of course the 2D or 3D content itself.[/edit] |
| ||
@Bobysait: I forgot about pivots, but then again I don't do much 3D stuff; I'm one of those diehard 2D nutjobs. :D |
| ||
@steve_ancell>>it seems useless and unnecessary, but if you are happy, please continue ;) |
| ||
Without seeing the bigger picture a lot of things seem useless and unnecessary LOL... Everyone has their own weird style of coding though Bud! ;) |
| ||
Yeah yeah no worries, i was just curious about the usefulness to store customtype instances in a dim arrays since when you delete an instance of the customtype, then the corresponding index becomes useless (because the associated instance of the customtype does not exist anymore) ? |
| ||
@RemiD it can be usefull if you need to store your type in a certain way, for example a 2 dimensions array, then if you need to know the handle of a particular type in this table you have it. |
| ||
@Flanker>>ok, but in this case, why not store the reference/value directly in the dim arrays entry instead of using a customtype ?Thing_Kind%(99,99) Thing_Collidable(99,99) Thing_Renderer(99,99) Since if you use a dim array to store the handles of instances of a customtype, you lose the advantage of the customtype which is that you don't have to reorganize the list after you have deleted an instance. So yes, but no. (but ok!) |
| ||
@RemiD Because if you don't fill your array entirely, this is lost memory space. This won't happen with types as you store only what is needed. If you don't have much things to store it won't be a problem, but when you have a lot, it helps you. For example, if you have a 512x512x512 classic 3D grid, and in each cells, 10 floats to store, but only 1/4 of the cells will be filled : Dim cell#(511,511,511,9)This will take In this case you'd better use a smaller array to store handles of a type : Dim cellHandle(511,511,511) Type cellVariables Field variable#[9] End TypeThis will take less memory, unless you have a type assiocated with each cell. |
| ||
@RealEyesRealiseRealLies Here is a possible answer to your question: Is it possible in Blitz3D so I can only use 1 name for all the cubes I'm making and not have to name each individual one??? You could create one cube and then use CopyEntity() to replicate it. Copy and paste the following code and give it a whirl :) Graphics3D 1024,600,32,2 : SetBuffer BackBuffer() ; Graphics And Buffer Settings ; ------------------------------------------- Initialisation Camera_1 = CreateCamera() : RotateEntity Camera_1,30,0,0 : Light_1 = CreateLight() Plane_1 = CreatePlane() : PositionEntity Plane_1,0,-20,0 : EntityColor Plane_1,150,50,100 Puck = CreateCylinder() : PositionEntity Puck,0,-18,25 : ScaleEntity Puck,3,1,3 cubes = CreateCube() : Global cube ; ------------------------------------------- main loop While Not KeyHit(1) Cls ; - Controls to move puck -> Keys; Left, Right, Up, Down If KeyDown(203) Then MoveEntity Puck,-1,0,0 If KeyDown(205) Then MoveEntity Puck,1,0,0 If KeyDown(200) Then MoveEntity Puck,0,0,1 If KeyDown(208) Then MoveEntity Puck,0,0,-1 ; - Space bar to place a new cube If KeyHit(57) Then cube = CopyEntity(cubes) : PositionEntity cube,EntityX(Puck),EntityY(Puck),EntityZ(Puck) UpdateWorld RenderWorld Flip Wend I am sure this could be adapted to suit your need. This example only uses two axis so if you needed height you would need to add it in. You could save the coordinates of each cube to a file and then load the cubes back in the same location that you left them. As you can see from the examples in this thread there are indeed many ways to solve your question. Happy coding! :) |
| ||
@Flanker>>yes in this case i understand the usefulness |
| ||
@Bobysait: I forgot about pivots, but then again I don't do much 3D stuff; I'm one of those diehard 2D nutjobs. :D I'm not trying to be impolite at all, but just to mention : my post was not related to anything you could have said here, I was just answering the topic's question. |
| ||
@Bobysait Stay calm fella, I wasn't offended by anything. ;) I do understand what you say about pivots, I just don't practice the 3D side much. |
| ||
@RemiD Here's one reason why I do the object inside array thing. If I were to have a type called Soldier, and I created to variables (goodies and baddies), and I use them to create instances of Soldier; when I use For/Each it will address all objects of the soldier type regardless of what variable they are stored in. By putting objects inside arrays I can address them separately. Below I am attempting to demonstrate what I mean. First code accesses via For/Each (notice that it accesses all things that are Soldier), the second accesses goodies only, and the third accesses just the baddies. OK, I know I only have the "id" field inside the Soldier type, but you could obviously also stash other stuff in there including a 3D object. I hope this sort of clears up why I do it the type in array style. P.S: I know this may look a little off-topic to some but I say it's not. This has a valid place here due to the topic asking about how to store and access 3D objects, I'm just posting this here in a hopefully simpler way. ;) ;This will access the whole lot, this may be undesirable. Graphics 800, 600 SetBuffer BackBuffer() Global goodieCount = 5 Global baddieCount = 5 Global goodies.Soldier Global baddies.Soldier Type Soldier Field id$ End Type For i = 0 To goodieCount goodies.Soldier = New Soldier goodies\id$ = "I'm a goody!" Next For i = 0 To baddieCount baddies.Soldier = New Soldier baddies\id$ = "I'm a baddy, I think you had better RUN!" Next For s.Soldier = Each Soldier Print s\id$ Next WaitKey() End ;This will create both goodies and baddies, and will allow me to access just the goodies. Graphics 800, 600 SetBuffer BackBuffer() Global goodieCount = 5 Global baddieCount = 5 Dim goodies.Soldier(goodieCount) Dim baddies.Soldier(baddieCount) Type Soldier Field id$ End Type For i = 0 To goodieCount goodies(i) = New Soldier goodies(i)\id$ = "I'm a goody!" Next For i = 0 To baddieCount baddies(i) = New Soldier baddies(i)\id$ = "I'm a baddy, I think you had better RUN!" Next For i = 0 To goodieCount Print goodies(i)\id$ Next WaitKey() End ;This will create both goodies and baddies, and will allow me to access just the baddies. Graphics 800, 600 SetBuffer BackBuffer() Global goodieCount = 5 Global baddieCount = 5 Dim goodies.Soldier(goodieCount) Dim baddies.Soldier(baddieCount) Type Soldier Field id$ End Type For i = 0 To goodieCount goodies(i) = New Soldier goodies(i)\id$ = "I'm a goody!" Next For i = 0 To baddieCount baddies(i) = New Soldier baddies(i)\id$ = "I'm a baddy, I think you had better RUN!" Next For i = 0 To baddieCount Print baddies(i)\id$ Next WaitKey() End |
| ||
Well your example is bad imo since you could do :Type Baddie field Life# end type Type Goodie field Life# end type or Baddie_Life#(10) Goodie_Life#(10) or if the list is not too big Type Soldier Field Alignment% ; CBaddie or CGoodie (2 different constants) Field Life# end type or Dim Soldier_Alignment%(10+10) ; CBaddie or CGoodie (2 different constants) Dim Soldier_Life#(10+10) but the example of Flanker is good (to not waste memory) but it could be replaced by something like that : global ThingsCount% = 0 dim Thing_H%(100) Type Thing field Name$ Field Mesh end type ;to create a thing ThingsCount = ThingsCount + 1 TI% = ThingsCount t.Thing = new Thing t\Name = "blahblahblah" t\Mesh = createmesh() ;or loadmesh() Thing_H(TI) = handle(t) ;to access a thing H% = Thing_H%(5) t.Thing = Object.Thing(H) entitycolor(t\Mesh,rand(025,255),rand(025,255),rand(025,255)) there are several ways to achieve the same result, and if it is senseful enough and fast enough, just continue to do it as you want... |
| ||
@RemiD My examples above are very crude and stripped down for the sake of explanation so they would look bad, but, when used in the right situation as part of something, what I do makes perfect sense. Like I said, it depends on what you are doing. |
| ||
@steve>>no worries, you do what you want, as long as it works well and runs fast enough... |
| ||
Fair enough fella ;) |