1 registered members (AndrewAMD),
1,241
guests, and 6
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
|
Re: From a simple 3D Sphere to a real-size Planet. Need help!
[Re: joao13pt]
#423157
05/24/13 19:18
05/24/13 19:18
|
Joined: Mar 2013
Posts: 30 Portugal
joao13pt
OP
Newbie
|
OP
Newbie
Joined: Mar 2013
Posts: 30
Portugal
|
I've been checking this website that shows how to convert a cube to a sphere, and, the result was this algorithm:
function cube_to_sphere(ENTITY* model)
{
int i = ent_status(model,0);
for (; i>0; i--)
{
CONTACT* c = ent_getvertex(model,NULL,i);
c.x = (c.x * (sqrt(1 - ((c.y^2)/2) - ((c.z^2)/2) + (((c.y^2)*(c.z^2))/3))));
wait(2);
c.y = (c.y * (sqrt(1 - ((c.x^2)/2) - ((c.z^2)/2) + (((c.x^2)*(c.z^2))/3))));
wait(2);
c.z = (c.z * (sqrt(1 - ((c.x^2)/2) - ((c.y^2)/2) + (((c.x^2)*(c.y^2))/3))));
wait(2);
c.v = NULL; // set c.v to NULL to change c.x,y,z
ent_setvertex(model,c,i);
wait(4);
}
}
The math in c.x, c.y and c.z comes from this image found in the website previously mentioned, and the result was waaaaay to horrific for me to post pics here, basically, each of the cube's 768 vertices were scattered around the level I even added some wait() functions to slow the process down, thinking it could be the math "happenning" too fast, but the result was still awfull Im a little tired to think where i made the mistake, i've been failling this algorithm for transforming a cube to a sphere for about a month, and now i really think i need extra help Thanks in advance!
|
|
|
Re: From a simple 3D Sphere to a real-size Planet. Need help!
[Re: MasterQ32]
#423193
05/25/13 13:18
05/25/13 13:18
|
Joined: Mar 2013
Posts: 30 Portugal
joao13pt
OP
Newbie
|
OP
Newbie
Joined: Mar 2013
Posts: 30
Portugal
|
Didn't work aswell.. i don't think you understand what im trying to achieve So, i have an actuall cube model, it has 768 faces in total I want to convert each of it's vertices's (x,y,z) values that make it have the shape of a cube, into values that form a sphere basically i want to wrap this cube into a sphere Thus that whole complicated math using vec_normalize(c.x, 1) and doing the same for c.y and c.z isn't helping, because im not actually telling the program to turn it into a sphere, im just reducing it's size Please explain the whole process to me, i'd be very gratefull, something is missing in my way of thinking and it's driving me crazy Thank you ----------------------------- EDIT ------------------------- Exactly 10 seconds after writing the above post, i decided to try just changing the c.x, then just the c.y and then just the c.z just to watch it fail again and it work right away with the c.x thank you so very much! I've been waiting for ever to have this result! thank you thank you thank you man! Aparently i was confusing c.x,y,z with actual x,y,z values was i thinking right or wrong? Because i just changed the vertice's X (c.x) value and the cube turned into a sphere I was not expecting it, but it worked out and THANK YOU! here's the inicial cube And the final sphere
Last edited by joao13pt; 05/25/13 14:00.
|
|
|
Re: From a simple 3D Sphere to a real-size Planet. Need help!
[Re: MasterQ32]
#423227
05/25/13 19:08
05/25/13 19:08
|
Joined: Mar 2013
Posts: 30 Portugal
joao13pt
OP
Newbie
|
OP
Newbie
Joined: Mar 2013
Posts: 30
Portugal
|
Sorry about that, i really wans't thinking in what i was saying It only works because of your help! thank you again! Now i'll continue to create my virtual universe
|
|
|
Re: From a simple 3D Sphere to a real-size Planet. Need help!
[Re: joao13pt]
#423756
06/04/13 21:35
06/04/13 21:35
|
Joined: Jul 2001
Posts: 6,904
HeelX
Senior Expert
|
Senior Expert
Joined: Jul 2001
Posts: 6,904
|
it wont update it's shadow I guess you mean the shading? When you just move the vertices around, the normals won't be updated. Try ent_fixnormals.
|
|
|
Re: From a simple 3D Sphere to a real-size Planet. Need help!
[Re: MasterQ32]
#423757
06/04/13 22:16
06/04/13 22:16
|
Joined: Mar 2013
Posts: 30 Portugal
joao13pt
OP
Newbie
|
OP
Newbie
Joined: Mar 2013
Posts: 30
Portugal
|
just use vec_normalize(c.x, 1); here instead of the whole normalization code I transform it into a sphere like you told me to, using this:
function cube_to_sphere(ENTITY* model)
{
int i = ent_status(model,0);
for (; i>0; i--)
{
CONTACT* c = ent_getvertex(model,NULL,i);
vec_normalize(c.x, 112);
c.v = NULL; // set c.v to NULL to change c.x,y,z
ent_setvertex(model,c,i);
wait(5);
}
ent_fixnormals(model, 0); // THIS PART OF THE CODE WAS ADDED AFTER READING THE PREVIOUS REPLY
}
The ent_fixnormals() worked out! thank you again for all your help fellow programmers!
|
|
|
Re: From a simple 3D Sphere to a real-size Planet. Need help!
[Re: joao13pt]
#423984
06/08/13 23:15
06/08/13 23:15
|
Joined: Mar 2013
Posts: 30 Portugal
joao13pt
OP
Newbie
|
OP
Newbie
Joined: Mar 2013
Posts: 30
Portugal
|
Im sorry if i'm being annoying, i keep coming here with problems and questions and doubts But now i need guidance to achieve my next goal, the one i was fearing most from the start, the part where i make my "procedural" planet, procedural: tessellation, face subdivision algorithms (this last one, im sure i could handle, i just can't freaking find any algorithm online nor any explanation of how to do it) and all of those things I need advice on where to start By now i've researched ALOT actually about procedural planets and all that stuff, and i've come to a (possibly wrong?) conclusion that real-time face subdivision is made through shaders, is it? I really don't have the smallest clue on where to start, so any help from this community will be kindly apreciated Thank you!
|
|
|
|