Here is a function I have been developing to make new objects from spheres.
#include "DarkGDK.h"
struct Points{
float x;
float y;
float z;
};
Points Path[100];
void Lathe(int object, int start, int end, int res);
void MakeWineGlass(int Object);
void MakeBeerGlass(int Object);
void MakeBowlingPin(int Object);
// the main entry point for the application is this function
void DarkGDK ( void ){
dbSetWindowTitle ( "Lathe by John James" );
dbSyncRate(60);
dbSyncOn();
dbMakeLight(1);
dbPositionLight(1,500,1000,0);
dbAutoCamOff ();
dbSyncOn ( );
dbSyncRate ( 60 );
dbAutoCamOff();
dbPositionCamera(15,10,-25);
dbPointCamera(5,5,5);
MakeWineGlass(100);
MakeBeerGlass(110);
MakeBowlingPin(120);
// our main loop
while ( LoopGDK ( ) ){
dbControlCameraUsingArrowKeys( 0,5,1 );
dbSync ( );
}
// return back to windows
return;
}
void MakeWineGlass(int Object){
// assign points values that represent the glass
// think in terms of graph paper simple profile
Path[3].x = 0.0; Path[3].y = 1.1 ; Path[3].z = 0.0;
Path[4].x = 1.2; Path[4].y = 1.5 ; Path[4].z = 0.0;
Path[5].x = 1.3; Path[5].y = 1.5 ; Path[5].z = 0.0;
Path[6].x = 0.1; Path[6].y = 1.0 ; Path[6].z = 0.0;
Path[7].x = 0.1; Path[7].y = 0.3 ; Path[7].z = 0.0;
Path[8].x = 1.0; Path[8].y = 0.1 ; Path[8].z = 0.0;
Path[9].x = 1.0; Path[9].y = 0.0 ; Path[9].z = 0.0;
Path[10].x = 0.0; Path[10].y = 0.0 ; Path[10].z = 0.0;
Lathe (Object,3,10,32);
dbColorObject(Object,dbRGB(100,200,100));
dbPositionObject(Object,5,5,5);
for (int i = 0; i < 6; i++){
dbCloneObject(Object+i,Object);
dbPositionObject(Object+i,i*3,0,0);
}
}
void MakeBeerGlass(int Object){
Path[0].x = 0.0; Path[0].y = 0.0 ; Path[0].z = 0.0;
Path[1].x = 1.5; Path[1].y = 0.0 ; Path[1].z = 0.0;
Path[2].x = 1.6; Path[2].y = 1.2 ; Path[2].z = 0.0;
Path[3].x = 2.0; Path[3].y = 3.0 ; Path[3].z = 0.0;
Path[4].x = 1.9; Path[4].y = 6.0 ; Path[4].z = 0.0;
Path[5].x = 1.8; Path[5].y = 6.0 ; Path[5].z = 0.0;
Path[6].x = 1.9; Path[6].y = 3.0 ; Path[6].z = 0.0;
Path[7].x = 1.5; Path[7].y = 1.5 ; Path[7].z = 0.0;
Path[8].x = 1.4; Path[8].y = 0.1 ; Path[8].z = 0.0;
Path[9].x = 0.0; Path[9].y = 0.1 ; Path[9].z = 0.0;
Lathe (Object,0,10,8);
dbPositionObject(Object,-5,0,0);
dbColorObject(Object,dbRGB(100,100,200));
dbGhostObjectOn(Object,0);
for (int i = 0; i < 6; i++){
dbInstanceObject(Object+i,Object);
dbPositionObject(Object+i,i*-5,0,0);
dbGhostObjectOn(Object+i);
}
}
void MakeBowlingPin(int Object){
Path[0].x = 0.0; Path[0].y = 0.0 ; Path[0].z = 0.0;
Path[1].x = 1.5; Path[1].y = 0.0 ; Path[1].z = 0.0;
Path[2].x = 2.1; Path[2].y = 3.0 ; Path[2].z = 0.0;
Path[3].x = 1.3; Path[3].y = 6.0 ; Path[3].z = 0.0;
Path[4].x = 1.3; Path[4].y = 7.0 ; Path[4].z = 0.0;
Path[5].x = 1.2; Path[5].y = 7.2 ; Path[5].z = 0.0;
Path[6].x = 1.1; Path[6].y = 7.3 ; Path[6].z = 0.0;
Path[7].x = 0.7; Path[7].y = 7.4 ; Path[7].z = 0.0;
Path[8].x = 0.0; Path[8].y = 7.5 ; Path[8].z = 0.0;
Lathe (Object,0,8,16);
dbColorObject(Object,dbRGB(200,50,50));
dbPositionObject(Object,0,0,10);
for (int i = 0; i < 6; i++){
dbCloneObject(Object+i,Object);
dbPositionObject(Object+i,i*-6,0,10);
}
}
void Lathe(int Obj, int start, int end, int res){
int Rows = 1 + (end - start);
int count;
float Height =1;
float xPosition, yPosition, zPosition;
int Vertex=0;
float Angle;
dbMakeObjectSphere( Obj, Height, Rows, res);
dbLockVertexDataForLimb( Obj, 0, 1);
count = dbGetVertexDataVertexCount();
for (int MyY = start; MyY <= end; MyY++){
for (int MyX = 0; MyX <= res; MyX++){
Angle = dbWrapValue(180+((360 / res) * MyX));
xPosition = dbNewXValue(0,Angle,Path[MyY].x);
zPosition = dbNewZValue(0,Angle,Path[MyY].x);
dbSetVertexDataPosition( Vertex, xPosition,Path[MyY].y , zPosition);
Vertex++;
}
}
dbUnlockVertexData();
dbMakeMeshFromObject (Obj,Obj);
dbDeleteObject(Obj);
dbMakeObject(Obj,Obj,1);
dbDeleteMesh(Obj);
}
Use it as you please but if you make an improvement please share
All the best
Codger
System
MacBook Pro
Windows XP Home on Boot Camp