Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Dark GDK / help with simple code

Author
Message
Lo Wang
15
Years of Service
User Offline
Joined: 8th Mar 2009
Location:
Posted: 8th Mar 2009 07:29
Hello,

for my first goal, i just want to create a six layered paraymid of about 1500 spheres. so i started constucting the first and i quickly noticed that for some reason iam not getting a perfect square even through its 1024 balls with 32 balls on each side. and another strange problem is that when i started creating the 2nd layer above it with 256 balls, 16 on each size, i not only get the same problem, but the second layer doesnt share a corner as it should, but is drifted to the side, and there is a phantom white ball, i call it phantom ball because i have no idea where it came from. heres the code, its pretty simple, please have a look. I appreciate your time. Thanks

[/code]
void DarkGDK ( void )
{
// in this application we are going to create some 3D objects
// and position them on screen

// when starting a Dark GDK program it is useful to set global
// application properties, we begin by turning the sync rate on,
// this means we control when the screen is updated, we also set
// the maximum rate to 60 which means the maximum frame rate will
// be set at 60 frames per second
dbSyncOn ( );
dbSyncRate ( 60 );

int x = 0;
int z = 0;
int x2 = 0;
int z2 = 0;

// make some 3D objects
for ( int i = 0; i < 1024; i++ )
{

// make a sphere
dbMakeObjectSphere ( i, 1 );

// position the object in a random location
dbPositionObject ( i, x, 0, z);

// adjust scaling
dbScaleObject ( i, 400, 400, 400);

// give the object a color
dbColorObject ( i, 0 );

// increase specular power
dbSetObjectSpecularPower ( i, 255 );

// turn off ambient lighting for this object
dbSetObjectAmbient ( i, 0 );

if(x < 320)
{
x += 10;
}
else
{
x = 0;
z += 10;
}

int k = i;

if(k <= 256)
{
// make a sphere
dbMakeObjectSphere ( (k + 1500), 1 );

// position the object in a random location
dbPositionObject ( k, x2, 10, z2);

// adjust scaling
dbScaleObject ( k, 400, 400, 400);

// give the object a color
dbColorObject ( k, dbRgb ( dbRnd ( 255 ), dbRnd ( 255 ), dbRnd ( 255 ) ) );

// increase specular power
dbSetObjectSpecularPower ( k, 255 );

// turn off ambient lighting for this object
dbSetObjectAmbient ( k, 0 );

if(x2 <= 160)
{
x2 += 10;
}
else
{
x2 = 0;
z2 += 10;
}
}
}

// move our camera back so we can view the objects
dbPositionCamera ( 50, 10, -20 );
float fCameraAngleX = 0.0f;
float fCameraAngleY = 0.0f;

// now we come to our main loop, we call LoopGDK so some internal
// work can be carried out by the GDK
while ( LoopGDK ( ) )
{
// display some text on screen
dbText ( 0, 0, "Use the up and down arrow keys to move the camera" );

//// move the camera forwards
//if ( dbUpKey ( ) )
// dbMoveCamera ( 1 );

//// move the camera backwards
//if ( dbDownKey ( ) )
// dbMoveCamera ( -1 );


// move the camera using the arrow keys
dbControlCameraUsingArrowKeys ( 0, 7.0f, 0.3f );

// create a rotation axis based on mouse movement
fCameraAngleX = dbWrapValue ( fCameraAngleX + dbMouseMoveY ( ) * 0.4f );
fCameraAngleY = dbWrapValue ( fCameraAngleY + dbMouseMoveX ( ) * 0.4f );

// rotate camera
dbXRotateCamera ( fCameraAngleX );
dbYRotateCamera ( fCameraAngleY );

// here we make a call to update the contents of the screen
dbSync ( );
}

// before quitting delete our objects
for ( int i = 0; i < 1024; i++ )
dbDeleteObject ( i );

for ( int k = 1500; k < 257500; k++ )
dbDeleteObject ( k );

// and now everything is ready to return back to Windows
return;
}
[code]

Attachments

Login to view attachments
J_C
16
Years of Service
User Offline
Joined: 9th Nov 2007
Location:
Posted: 8th Mar 2009 18:01
Hi Lo Wang

I think the phantom may be this

if(k <= 256)
{
// make a sphere
dbMakeObjectSphere ( (k + 1500), 1 );

k+1500 this object is never posiotioned of textured
so everytime you create this sphere it is in the same place.

you never say k = k + 1500 so you never update the new sphere.
with your code that is using k as the object to update.
AlexZinn
15
Years of Service
User Offline
Joined: 17th Feb 2009
Location:
Posted: 8th Mar 2009 18:24 Edited at: 8th Mar 2009 18:25
em... check this code, it might help you... this will make you a square of Spheres



If someone need something, add me to your msn
Lo Wang
15
Years of Service
User Offline
Joined: 8th Mar 2009
Location:
Posted: 8th Mar 2009 19:14
Thank you both, your posts were very helpful, i understand now why i got that phantom ball and iam using now superkids code to get perfect squares.

Thank you
AlexZinn
15
Years of Service
User Offline
Joined: 17th Feb 2009
Location:
Posted: 8th Mar 2009 19:40
My first usefull helping haha if you need something.. we are here for you

If someone need something, add me to your msn

Login to post a reply

Server time is: 2024-09-30 19:16:26
Your offset time is: 2024-09-30 19:16:26