Geometry

Share your ZGE-development tips and techniques here!

Moderator: Moderators

Post Reply
User avatar
Kjell
Posts: 1910
Joined: Sat Feb 23, 2008 11:15 pm

Geometry

Post by Kjell »

8)

A collection of useful ( and not so useful ) procedurally generated meshes. All generated with a Grid2DOnly MeshBox using U and V coordinates ranging from -Pi to Pi ( unless notified ).

First up, a diamond cluster.

Code: Select all

this.V.X = (2+sin(U)*sin(V*4))*sin(V)*-1;
this.V.Y = (2+sin(U)*sin(V*4))*cos(V);
this.V.Z = cos(U)*sin(V*4);
Attachments
Cluster.jpg
Cluster.jpg (42.13 KiB) Viewed 37781 times
Last edited by Kjell on Tue Sep 30, 2008 3:00 pm, edited 1 time in total.
User avatar
Kjell
Posts: 1910
Joined: Sat Feb 23, 2008 11:15 pm

Post by Kjell »

Next, a teardrop.

Code: Select all

this.V.X = 0.5*(1-cos(U))*sin(U)*cos(V);
this.V.Y = 0.5*(1-cos(U))*sin(U)*sin(V);
this.V.Z = cos(U);
Attachments
Teardrop.jpg
Teardrop.jpg (32.03 KiB) Viewed 37768 times
User avatar
Kjell
Posts: 1910
Joined: Sat Feb 23, 2008 11:15 pm

Post by Kjell »

Followed by, a pillow.

Code: Select all

this.V.X = cos(U);
this.V.Y = cos(V);
this.V.Z = (sin(U)*sin(V))/Pi*2;
Attachments
Pillow.jpg
Pillow.jpg (34.56 KiB) Viewed 37767 times
User avatar
Kjell
Posts: 1910
Joined: Sat Feb 23, 2008 11:15 pm

Post by Kjell »

Let's try a spring.

Code: Select all

this.V.X = (Pi+Radius*cos(V))*cos(U*Length);
this.V.Y = (Pi+Radius*cos(V))*sin(U*Length);
this.V.Z = Radius*(sin(V)+Period*U*Length/Pi);
Attachments
Spring.jpg
Spring.jpg (48.05 KiB) Viewed 37766 times
User avatar
jph_wacheski
Posts: 1005
Joined: Sat Feb 16, 2008 8:10 pm
Location: Canada
Contact:

Post by jph_wacheski »

Cool! thanks for posting these,. more fun stuff to play around with!
The more I work with these generative type geometries the better understanding I am developing of the math that defines them,. it is just great to have some starting places for gaining that.

I am wondering if we had a torus prim. if we could get rid of that seam on that very usefull torus bit you post elsewere? You know so the primitve, to begin with, was a solid torus geometry,. and we could use the equations to warp it from there? peace.
iterationGAMES.com
User avatar
Kjell
Posts: 1910
Joined: Sat Feb 23, 2008 11:15 pm

Post by Kjell »

By request, a torus with calculated normals ( unusual subdivisions to illustrate normals ).

Code: Select all

this.V.X = cos(U)*cos(V)*Size+cos(U)*Radius;
this.V.Y = sin(U)*cos(V)*Size+sin(U)*Radius;
this.V.Z = sin(V)*Size;

this.N.X = cos(U)*cos(V)*Size;
this.N.Y = sin(U)*cos(V)*Size;
this.N.Z = this.V.Z;
Attachments
Torus.jpg
Torus.jpg (55.17 KiB) Viewed 37731 times
kattle87
Posts: 402
Joined: Wed Sep 26, 2007 9:06 am
Location: Italy

Post by kattle87 »

I'm posting here also the Sphere and the cylinder with subdivided upper and lower faces. A cylinder is to come if someone ask for it :P

Note: for the cylinder, you can change the variable "VarQ" that indicates how many "circles" you are going to have on upper and lower surface.

For Ville: try using "int" instead of "float" for VarP and tell me if it's working for you. I get different results. Is this because of truncate on integer divisions? If yes, it's fine :)
Attachments
Sphere_Cylinder.zgeproj
(2.79 KiB) Downloaded 1431 times
In the fall of 1972 President Nixon announced that the rate of increase of inflation was decreasing. This was the first time a sitting president used the third derivative to advance his case for reelection.
-=Hugo Rossi=-
User avatar
jph_wacheski
Posts: 1005
Joined: Sat Feb 16, 2008 8:10 pm
Location: Canada
Contact:

Post by jph_wacheski »

Excellent! These are both great and usefull!! I apretiate the normal correctness, for perfect smoothing.

Keep 'em coming,. can you design a routine for a Icosphere?!?!

Hay,. I was just wundering about using renderMesh components to buils animated object,. would they be faster to animate? can closed shapes be made using these techneques??

I'm still looking for a way to do nice poly-trails,. you know 3d ribbons,. that fade in width,. and alpha preferably,. . I can get the points and build a list in arrays but havent figured how to draw them,.
iterationGAMES.com
User avatar
Kjell
Posts: 1910
Joined: Sat Feb 23, 2008 11:15 pm

Post by Kjell »

8)

Using this one myself all the time ( for collision representation ).

Code: Select all

ZZDC<?xml version="1.0" encoding="iso-8859-1" ?>
<Mesh Name="CapsuleMesh">
  <Producers>
    <MeshBox Scale="0.5 0.5 1" XCount="15" Grid2DOnly="255"/>
    <MeshExpression AutoNormals="0">
      <Expression>
<![CDATA[float RX, SX, CX;

RX = this.V.X*PI*2;

SX = sin(RX); CX = cos(RX);

this.V.X = SX/2;
this.V.Z = CX/2;

this.N.X = this.V.X;
this.N.Y = 0;
this.N.Z = this.V.Z;]]>
      </Expression>
    </MeshExpression>
    <MeshBox Scale="0.5 0.5 1" XCount="15" YCount="3" Grid2DOnly="255"/>
    <MeshExpression AutoNormals="0">
      <Expression>
<![CDATA[float RX, SX, CX,
      RY, SY, CY;

RX = this.V.X*PI*2;
RY = this.V.Y*PI/2-PI/4;

SX = sin(RX); CX = cos(RX);
SY = sin(RY); CY = cos(RY);

this.V.X = SX*CY/2;
this.V.Y = SY/2;
this.V.Z = CX*CY/2;

this.N.X = this.V.X;
this.N.Y = this.V.Y;
this.N.Z = this.V.Z;

this.V.Y -= 0.5;]]>
      </Expression>
    </MeshExpression>
    <MeshCombine/>
    <MeshBox Scale="0.5 0.5 1" XCount="15" YCount="3" Grid2DOnly="255"/>
    <MeshExpression AutoNormals="0">
      <Expression>
<![CDATA[float RX, SX, CX,
      RY, SY, CY;

RX = this.V.X*PI*2;
RY = this.V.Y*PI/2+PI/4;

SX = sin(RX); CX = cos(RX);
SY = sin(RY); CY = cos(RY);

this.V.X = SX*CY/2;
this.V.Y = SY/2;
this.V.Z = CX*CY/2;

this.N.X = this.V.X;
this.N.Y = this.V.Y;
this.N.Z = this.V.Z;

this.V.Y += 0.5;]]>
      </Expression>
    </MeshExpression>
    <MeshCombine/>
  </Producers>
</Mesh>
I'm aware you can generate a capsule out of a single plane as well, but this mesh is easier to modify :wink:
Attachments
Capsule.jpg
Capsule.jpg (17.88 KiB) Viewed 37146 times
User avatar
jph_wacheski
Posts: 1005
Joined: Sat Feb 16, 2008 8:10 pm
Location: Canada
Contact:

Post by jph_wacheski »

Very cool,. this reminded me that the mesh component now has the nifty Graph feature! Curious, how have you have implemented Capsule Collision? Can it be added to the standard ZGE collision tests or is it dependent on a bunch of your own code?
iterationGAMES.com
User avatar
Kjell
Posts: 1910
Joined: Sat Feb 23, 2008 11:15 pm

Post by Kjell »

:roll:

Using my own collision libraries .. couldn't wait for that Raycast ( and the rest ) forever :P

K
User avatar
diki
Posts: 140
Joined: Thu Sep 11, 2008 7:53 pm
Location: GMT+1
Contact:

Post by diki »

Kjell wrote:my own collision libraries
ach, the envy!

;)
User avatar
jph_wacheski
Posts: 1005
Joined: Sat Feb 16, 2008 8:10 pm
Location: Canada
Contact:

Post by jph_wacheski »

I still suck with mesh math,. anyone able to generate this more correctly??

Code: Select all

ZZDC<?xml version="1.0" encoding="iso-8859-1" ?>
<Mesh Name="g_Z">
  <Producers>
    <MeshBox Grid2DOnly="255"/>
    <MeshExpression>
      <Expression>
<![CDATA[//V : current vertex
//N : current normal (turn off AutoNormals when modifying normals)
//C : current color (turn on VertexColors)
//TexCoord : current texture coordinate (turn on HasTexCoords)

v.y*=0.035;
v.x*=0.5;
v.x+=0.019;
v.y+=.385;]]>
      </Expression>
    </MeshExpression>
    <MeshBox Grid2DOnly="255"/>
    <MeshExpression>
      <Expression>
<![CDATA[//V : current vertex
//N : current normal (turn off AutoNormals when modifying normals)
//C : current color (turn on VertexColors)
//TexCoord : current texture coordinate (turn on HasTexCoords)

v.x*=0.07;

if (v.y<-.5) v.y+=.65;
if (v.y<-.25) v.x-=.45;
if (v.y>.5) v.y-=.65;
if (v.y>.25) v.x+=.45;]]>
      </Expression>
    </MeshExpression>
    <MeshCombine/>
    <MeshBox Grid2DOnly="255"/>
    <MeshExpression>
      <Expression>
<![CDATA[//V : current vertex
//N : current normal (turn off AutoNormals when modifying normals)
//C : current color (turn on VertexColors)
//TexCoord : current texture coordinate (turn on HasTexCoords)

v.y*=0.035;
v.x*=0.5;
v.x-=0.019;
v.y-=.385;]]>
      </Expression>
    </MeshExpression>
    <MeshCombine/>
    <MeshTransform Scale="1 1.3 1"/>
  </Producers>
</Mesh>
iterationGAMES.com
User avatar
Kjell
Posts: 1910
Joined: Sat Feb 23, 2008 11:15 pm

Post by Kjell »

Hi jph,
jph_wacheski wrote:I still suck with mesh math, anyone able to generate this more correctly??
The letter "Z" isn't really a geometric primitive .. however, you could do something like this.

Code: Select all

ZZDC<?xml version="1.0" encoding="iso-8859-1" ?>
<Mesh Name="Mesh">
  <Producers>
    <MeshBox Scale="2 0.5 1" XCount="3" Grid2DOnly="255"/>
    <MeshExpression AutoNormals="0">
      <Expression>
<![CDATA[//

float Y = this.V.Y;

switch(this.V.X+2+(0.5-Y)*5)
{ 
  case 0: 
  case 9: 
    this.V.Y *=  4; 
    break; 

  case 1: 
  case 8: 
    this.V.X *= -2; 
    this.V.Y *=  4; 
    break; 

  case 2: 
  case 7: 
    this.V.X  =  Y*4;
    this.V.Y *=  3; 
    break; 

  case 3: 
  case 6: 
    this.V.X *= -1.2; 
    this.V.Y *= -3; 
    break; 

  case 4: 
  case 5: 
    this.V.Y *= -3; 
    break; 
}]]>
      </Expression>
    </MeshExpression>
  </Producers>
</Mesh>
K
User avatar
jph_wacheski
Posts: 1005
Joined: Sat Feb 16, 2008 8:10 pm
Location: Canada
Contact:

Post by jph_wacheski »

it is a primitive 'Z' I guess, as opposed to a modern one, lol.

anyway, thanks,. that is much better than my lame hack. I always learn stuff from your examples, this one is no different in that. cheers.
iterationGAMES.com
Post Reply