Author Topic: 3D Object Building: Cube / Rectangle  (Read 9155 times)

0 Members and 1 Guest are viewing this topic.

Offline Clyde

  • A Little Fuzzy Wuzzy
  • DBF Aficionado
  • ******
  • Posts: 7271
  • Karma: 71
    • View Profile
3D Object Building: Cube / Rectangle
« on: February 08, 2009 »
Hey Ho! :)

Ok, here's the question on my lips and a 3D one ta boot.

You know how a cube or a better definition a 3D rectangle shape is basically created with real and negative scaling on the vertecies for instance something like this: Vertex1=(-SizeX, SizeY, -SizeZ ) obviously with other verts, and based around the position of 0,0,0 ? And then you'd position it after it was created?

What I am attempting to do and which I cant think of the math to use for this ( it may be utterly simple :D )
And that is with Starting And Ending positions for the x,y,z's for all the verts to be used. Create the object at those positions plus also working out what the size / scaling of them would, so I can build and add segments to it.

All I am after is not the whole source for doing this just the workings out / maths to implement for successfully doing this. Unless the process of making the object ( minus 2 sides ; ) it is needed to show me how to do it properly

I am going to look for some public domain code on BlitzBasic.com if people dont know what Im getting at. Im at my parents Today; and on a very low performance machine; so I havent brough any code of to post up.

Cheers and huge humble thanks,
Clyde.
Still Putting The IT Into Gravy
If Only I Knew Then What I Know Now.

Challenge Trophies Won:

Offline hellfire

  • Sponsor
  • Pentium
  • *******
  • Posts: 1294
  • Karma: 466
    • View Profile
    • my stuff
Re: 3D Object Building: Cube / Rectangle
« Reply #1 on: February 08, 2009 »
Quote
What I am attempting to do and which I cant think of the math to use for this
And that is with Starting And Ending positions for the x,y,z's for all the verts to be used.
Clyde, can you please ask a specific question?
Most of your text doesn't make any sense to me.
Challenge Trophies Won:

Offline Clyde

  • A Little Fuzzy Wuzzy
  • DBF Aficionado
  • ******
  • Posts: 7271
  • Karma: 71
    • View Profile
Re: 3D Object Building: Cube / Rectangle
« Reply #2 on: February 08, 2009 »
Ok, I'll slim it down, tried to make it fun to read.

I want to build shapes like a cube / rectangle, and have them added to each other to form a bigger object; and they wont be based around the center of the screen space.  And I dont need 2 of the faces say right and left sides.

Here's one of the sides:

v0=addvertex( -ScaleX,-ScaleY,-ScaleZ )
v1=addvertex( -ScaleX, ScaleY,-ScaleZ )
v2=addvertex(  ScaleX, ScaleY,-ScaleZ )
v3=addvertex(  ScaleX,-ScaleY,-ScaleZ)

Where I have used scale, could be size.

I need to add in the start and ending positions to that.

example ( this will determine the size of the 3D rectangular shape )

x0,y0,z0 = start positions
x1,y1,z1 = where to end at.

But I am stuck on what should be added / changed to the above.

Cheers and hope that more understandable,
Clyde.
« Last Edit: February 08, 2009 by Clyde »
Still Putting The IT Into Gravy
If Only I Knew Then What I Know Now.

Challenge Trophies Won:

Offline hellfire

  • Sponsor
  • Pentium
  • *******
  • Posts: 1294
  • Karma: 466
    • View Profile
    • my stuff
Re: 3D Object Building: Cube / Rectangle
« Reply #3 on: February 08, 2009 »
Your cuboid now reaches from:
-ScaleX..+ScaleX
-ScaleY..+ScaleY
-ScaleZ..+ScaleZ
but instead you want it to be:
x0..x1
y0..y1
z0..z1
So it's just a simple find&replace task.
Challenge Trophies Won:

Offline Clyde

  • A Little Fuzzy Wuzzy
  • DBF Aficionado
  • ******
  • Posts: 7271
  • Karma: 71
    • View Profile
Re: 3D Object Building: Cube / Rectangle
« Reply #4 on: February 08, 2009 »
So:

addvertex( -ScaleX,-ScaleY,-ScaleZ )

Would become:

addvertex( -x0+-x1, -y0+-y1,-z0+-z1) ?
Still Putting The IT Into Gravy
If Only I Knew Then What I Know Now.

Challenge Trophies Won:

Offline Jim

  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 5301
  • Karma: 402
    • View Profile
Re: 3D Object Building: Cube / Rectangle
« Reply #5 on: February 08, 2009 »
Say you want a box (not a cube) that is 2X,2Y,2Z in size and is positioned at u,v,w, then it would be

u-X, v-Y, w-Z
u-X, v+Y, w-Z
u+X, v+Y, w-Z
u+X, v-Y, w-Z

for the same face you're talking about.

Effectively, u,v,w becomes the origin instead of 0,0,0.  It's just a case of adding.

Jim
Challenge Trophies Won:

Offline Clyde

  • A Little Fuzzy Wuzzy
  • DBF Aficionado
  • ******
  • Posts: 7271
  • Karma: 71
    • View Profile
Re: 3D Object Building: Cube / Rectangle
« Reply #6 on: February 09, 2009 »
Guys, thankyou I really treasure any information and help thats given to me.

I am after a cube / rectangle mesh, and I have a really terrible head cold, HellFire would you mind showing me changes to be made on the following, as it's not registering with me at the moment. Huge thanks, once I seee it it'll make sense.

Code: [Select]
   
    v0=add_vertex( Object, X0, Y0, Z0, 0,1)
    v1=add_vertex( Object, X0, Y1, Z1, 0,0)
    v2=add_vertex( Object, ScaleX, ScaleY,-ScaleZ,1,0)
    v3=add_vertex( Object, ScaleX,-ScaleY,-ScaleZ,1,1)
   

    v0=add_vertex( Object,-ScaleX,-ScaleY, ScaleZ,0,1)
    v1=add_vertex( Object,-ScaleX, ScaleY, ScaleZ,0,0)
    v2=add_vertex( Object,-ScaleX, ScaleY,-ScaleZ,1,0)
    v3=add_vertex( Object,-ScaleX,-ScaleY,-ScaleZ,1,1)
   

    v0=add_vertex(cube, ScaleX,-ScaleY, ScaleZ,0,1)
    v1=add_vertex(cube, ScaleX, ScaleY, ScaleZ,0,0)
    v2=add_vertex(cube,-ScaleX, ScaleY, ScaleZ,1,0)
    v3=add_vertex(cube,-ScaleX,-ScaleY, ScaleZ,1,1)
   

    v0=add_vertex(cube, ScaleX,-ScaleY,-ScaleZ,0,1)
    v1=add_vertex(cube, ScaleX, ScaleY,-ScaleZ,0,0)
    v2=add_vertex(cube, ScaleX, ScaleY, ScaleZ,1,0)
    v3=add_vertex(cube, ScaleX,-ScaleY, ScaleZ,1,1)
   

    v0=add_vertex(cube,-ScaleX, ScaleY,-ScaleZ,0,1)
    v1=add_vertex(cube,-ScaleX, ScaleY, ScaleZ,0,0)
    v2=add_vertex(cube, ScaleX, ScaleY, ScaleZ,1,0)
    v3=add_vertex(cube, ScaleX, ScaleY,-ScaleZ,1,1)
   


    v0=add_vertex( cube,-ScaleX,-ScaleY, ScaleZ,0,1)
    v1=add_vertex( cube,-ScaleX,-ScaleY,-ScaleZ,0,0)
    v2=add_vertex( cube, ScaleX,-ScaleY,-ScaleZ,1,0)
    v3=add_vertex( cube, ScaleX,-ScaleY, ScaleZ,1,1)
   

Yet again, humungus thanks,
Clyde.
Still Putting The IT Into Gravy
If Only I Knew Then What I Know Now.

Challenge Trophies Won:

Offline hellfire

  • Sponsor
  • Pentium
  • *******
  • Posts: 1294
  • Karma: 466
    • View Profile
    • my stuff
Re: 3D Object Building: Cube / Rectangle
« Reply #7 on: February 09, 2009 »
this:
Code: [Select]
v0=addvertex( -ScaleX,-ScaleY,-ScaleZ )
v1=addvertex( -ScaleX, ScaleY,-ScaleZ )
v2=addvertex(  ScaleX, ScaleY,-ScaleZ )
v3=addvertex(  ScaleX,-ScaleY,-ScaleZ)
becomes:
Code: [Select]
v0=addvertex( x0,y0,z0 )
v1=addvertex( x0,y1,z0 )
v2=addvertex( x1,y1,z0 )
v3=addvertex( x1,y0,z0 )
Because the lower/left/front-corner (-ScaleX,-ScaleY,-ScaleZ) becomes (x0,y0,z0),
the upper/right/back-corner (ScaleX,ScaleY,ScaleZ) becomes (x1,y1,z1).
Challenge Trophies Won:

Offline Clyde

  • A Little Fuzzy Wuzzy
  • DBF Aficionado
  • ******
  • Posts: 7271
  • Karma: 71
    • View Profile
Re: 3D Object Building: Cube / Rectangle
« Reply #8 on: February 10, 2009 »
I think I have it, so where there is a negative value that becomes a X0 etc, and where theres a real number becomes an X1 etc ?
Still Putting The IT Into Gravy
If Only I Knew Then What I Know Now.

Challenge Trophies Won:

Offline Clyde

  • A Little Fuzzy Wuzzy
  • DBF Aficionado
  • ******
  • Posts: 7271
  • Karma: 71
    • View Profile
Re: 3D Object Building: Cube / Rectangle
« Reply #9 on: February 11, 2009 »
OK, I have done this and it does make cubes. Thanks.

Code: [Select]
v0=add_vertex( Object, X0, Y0, Z0,0,1)
    v1=add_vertex( Object, X0, Y1, Z0,0,0)
    v2=add_vertex( Object, X1, Y1, Z0,1,0)
    v3=add_vertex( Object, X1, Y0, Z0,1,1)
   
    add_triangle ( Object,v0,v1,v2 )
    add_triangle ( Object,v2,v3,v0 )
   
    v0=add_vertex( Object, X0, Y0, Z1,0,1)
    v1=add_vertex( Object, X0, Y1, Z1,0,0)
    v2=add_vertex( Object, X0, Y1, Z0,1,0)
    v3=add_vertex( Object, X0, Y0, Z0,1,1)
   
    add_triangle ( Object,v0,v1,v2 )
    add_triangle ( Object,v2,v3,v0 )
   
    v0=add_vertex( Object, X1, Y0, Z1,0,1)
    v1=add_vertex( Object, X1, Y1, Z1,0,0)
    v2=add_vertex( Object, X0, Y1, Z1,1,0)
    v3=add_vertex( Object, X0, Y0, Z1,1,1)
   
    add_triangle ( Object,v0,v1,v2)
    add_triangle ( Object,v2,v3,v0)
   
    v0=add_vertex( Object, X1, Y0, Z0,0,1)
    v1=add_vertex( Object, X1, Y1, Z0,0,0)
    v2=add_vertex( Object, X1, Y1, Z1,1,0)
    v3=add_vertex( Object, X1, Y0, Z1,1,1)
   
    add_triangle ( Object,v0,v1,v2 )
    add_triangle ( Object,v2,v3,v0 )
   
    v0=add_vertex( Object, X0, Y1, Z0,0,1)
    v1=add_vertex( Object, X0, Y1, Z1,0,0)
    v2=add_vertex( Object, X1, Y1, Z1,1,0)
    v3=add_vertex( Object, X1, Y1, Z0,1,1)
   
    add_triangle ( Object,v0,v1,v2 )
    add_triangle ( Object,v2,v3,v0 )

    v0=add_vertex( Object, X0, Y0, Z1,0,1)
    v1=add_vertex( Object, X0, Y0, Z0,0,0)
    v2=add_vertex( Object, X1, Y0, Z0,1,0)
    v3=add_vertex( Object, X1, Y0, Z1,1,1)
   
    add_triangle ( Object,v0,v1,v2 )
    add_triangle ( Object,v2,v3,v0 )


However, this doesnt allow me to link up with the positions sent to the above piece of code, as in the example: x0,y0,z0, x1, y1, z1. What it does is draw a cube on it's own with a gap, and then another standalone cube, and not connecting up to each other to form a complete squarish model.
Still Putting The IT Into Gravy
If Only I Knew Then What I Know Now.

Challenge Trophies Won:

Offline zawran

  • Sponsor
  • Pentium
  • *******
  • Posts: 909
  • Karma: 67
    • View Profile
Re: 3D Object Building: Cube / Rectangle
« Reply #10 on: February 11, 2009 »
If possible, it might help if you could provide a visual reference of what you want the end result to look like. Sometimes its easier to understand an image than text, especially when graphics is the topic.

Offline Clyde

  • A Little Fuzzy Wuzzy
  • DBF Aficionado
  • ******
  • Posts: 7271
  • Karma: 71
    • View Profile
Re: 3D Object Building: Cube / Rectangle
« Reply #11 on: February 11, 2009 »
I know what you mean, It's a bit tricky as I dont have anything to show.

Basically its a complete linked shape, made up of sin and cos. The last co-ordinate links to the first one made.

Cheers,
Clyde.
Still Putting The IT Into Gravy
If Only I Knew Then What I Know Now.

Challenge Trophies Won:

Offline zawran

  • Sponsor
  • Pentium
  • *******
  • Posts: 909
  • Karma: 67
    • View Profile
Re: 3D Object Building: Cube / Rectangle
« Reply #12 on: February 11, 2009 »
I think the cylinder function from this entry in the BlitzResearch code archives should work for you: http://blitzmax.com/codearcs/codearcs.php?code=108 , just pass it 4 as the vertical segments and you got cubes connected instead of an cylinder.

Offline Clyde

  • A Little Fuzzy Wuzzy
  • DBF Aficionado
  • ******
  • Posts: 7271
  • Karma: 71
    • View Profile
Re: 3D Object Building: Cube / Rectangle
« Reply #13 on: February 11, 2009 »
Cheers man, thanks alot will give that ago.
Still Putting The IT Into Gravy
If Only I Knew Then What I Know Now.

Challenge Trophies Won:

Offline Clyde

  • A Little Fuzzy Wuzzy
  • DBF Aficionado
  • ******
  • Posts: 7271
  • Karma: 71
    • View Profile
Re: 3D Object Building: Cube / Rectangle
« Reply #14 on: February 26, 2009 »
Righty, I have vertex data for x,y,z values stored in an array ( verts*3 ). *3 due to x,y,z
I also have the Face / Connection Data in a similar fashion ( Faces*3 ) *3 as P1,P2,P3

I am trying to build the object, with add_verts and add_triangles.
But am getting it wrong all the time trying to link up the faces ( 3 points ) with the correct vertex's. Id love it for ya to show me the proper way to build it properly please dudes.

Cheers and all the very best Clyde,
Clyde.
Still Putting The IT Into Gravy
If Only I Knew Then What I Know Now.

Challenge Trophies Won:

Offline Jim

  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 5301
  • Karma: 402
    • View Profile
Re: 3D Object Building: Cube / Rectangle
« Reply #15 on: February 26, 2009 »
We still have no idea what you've tried or what the resulting object is supposed to look like!

Jim
Challenge Trophies Won:

Offline zawran

  • Sponsor
  • Pentium
  • *******
  • Posts: 909
  • Karma: 67
    • View Profile
Re: 3D Object Building: Cube / Rectangle
« Reply #16 on: February 26, 2009 »
Quote
Righty, I have vertex data for x,y,z values stored in an array ( verts*3 ). *3 due to x,y,z
I also have the Face / Connection Data in a similar fashion ( Faces*3 ) *3 as P1,P2,P3

What data is this, how did you get the data? Was it calculated, read from an object file? You would need to know beforehand the relation between vertex points and faces, otherwise how would you know what the object is going to be and which vertices the faces are using?

This data that you have, is the face data in order with vertex data? If so then it would be a matter of doing a bunch of AddVertex() until you have gone through the entire vertex array, then followed by a bunch of AddTriangle() until you are through the face array.

From reading through the posts, it seems that its not really clear what exactly you are trying to accomplish. Do you have a link to an image showing the end result, or a drawing/description of what it should be like?


Offline Clyde

  • A Little Fuzzy Wuzzy
  • DBF Aficionado
  • ******
  • Posts: 7271
  • Karma: 71
    • View Profile
Re: 3D Object Building: Cube / Rectangle
« Reply #17 on: February 27, 2009 »
Mission Accomplished!
Still Putting The IT Into Gravy
If Only I Knew Then What I Know Now.

Challenge Trophies Won:

Offline Jim

  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 5301
  • Karma: 402
    • View Profile
Re: 3D Object Building: Cube / Rectangle
« Reply #18 on: February 27, 2009 »
Can you post your answer so everyone can benefit?  :kewl:

Jim
Challenge Trophies Won:

Offline Clyde

  • A Little Fuzzy Wuzzy
  • DBF Aficionado
  • ******
  • Posts: 7271
  • Karma: 71
    • View Profile
Re: 3D Object Building: Cube / Rectangle
« Reply #19 on: March 01, 2009 »
Yeah sure, im not on my regular PC, but will defineatly post it up, or if you really like I could turn it into a tutorial.
Still Putting The IT Into Gravy
If Only I Knew Then What I Know Now.

Challenge Trophies Won: