About Monkey 2 › Forums › Monkey 2 Programming Help › What are BoxF?
This topic contains 3 replies, has 3 voices, and was last updated by
DruggedBunny
5 months, 2 weeks ago.
-
AuthorPosts
-
October 29, 2018 at 5:12 am #15547
I’m trying to understand why when creating a simple cube, I have to use BoxF which receives two parameters, could someone help me with a simple explanation?
November 1, 2018 at 10:24 am #15549BoxF is an alias for Box<Float>, Box type allow us to set cubic bounds.
It has many constructors, see the sources:
https://github.com/blitz-research/monkey2/blob/develop/modules/std/geom/box.monkey2
November 2, 2018 at 11:02 pm #15555I greatly appreciate your response, I just want to understand that, although the examples use it, I can not understand its parameters when creating a cube. A simple explanatory example?, with the objective of understanding the matter better since the documentation does not say much.
Thank you.
November 3, 2018 at 1:44 am #15556I’ve only used the form defining opposite corners of a cube/box:
Monkey1New Boxf (x0, y0, z0, x1, y1, z1)In real-world use, this might look like:
Monkey12Local cube:Model = Model.CreateBox (New Boxf (-0.5, -0.5, -0.5, 0.5, 0.5, 0.5), 1, 1, 1, New PbrMaterial (Color.White))… where x0, y0, z0 define one extreme corner — in this case being left 0.5, down 0.5, towards camera 0.5 — and x1, y1, z1 define the opposite corner; in this case right 0.5 (forming total width of 1.0), up 0.5 and forward 0.5.
For further clarity, you might store the box as a Boxf and pass it to CreateBox:
Monkey123Local cube_box:Boxf = New Boxf (-0.5, -0.5, -0.5, 0.5, 0.5, 0.5)Local cube:Model = Model.CreateBox (cube_box, 1, 1, 1, New PbrMaterial (Color.White))As far as I can tell, you only really need 1, 1, 1 for the x, y, z segments — you might pass in more if you want to manipulate the cube’s vertices into another shape.
So the box is:
- -0.5 to 0.5 horizontally – New Boxf (x0, -0.5, -0.5, x1, 0.5, 0.5);
- -0.5 to 0.5 vertically – New Boxf (-0.5, y0, -0.5, 0.5, y1, 0.5);
- -0.5 to 0.5 depth-wise – New Boxf (-0.5, -0.5, z0, 0.5, 0.5, z1).
… meaning it measures 1.0 in all directions.
Another way to define it, if you want to specify a particular size:
Monkey12Local size:Float = 10.0Local box:Boxf = New Boxf (-size * 0.5, -size * 0.5, -size * 0.5, size * 0.5, size * 0.5, size * 0.5)Or…
Monkey12Local box:Boxf = New Boxf (-width * 0.5, -height * 0.5, -depth * 0.5, width * 0.5, height * 0.5, depth * 0.5)The parameters define opposite corners of the cube:
Monkey1New Boxf (-, -, -, +, +, +)… and if you find you still struggle, just wrap Model.CreateBox into a CreateCube function (like Blitz3D!), passing in the width, height, depth and a PbrMaterial (plus potentially the optional parent entity), and returning the Model.
-
AuthorPosts
You must be logged in to reply to this topic.