Sunday, November 14, 2010

Oy veh

Well, if you've been paying attention, you may have noticed that for the first time since I started this blog, I skipped a day's worth of posting. The reason behind this absence of updating is that I figured out why I was having trouble connecting to my friend's Minecraft server - I had to update my NIC drivers.

So instead of toiling away with my code, I have instead been mining out an underground city and constructing a giant castle above ground.


Awesome, I know.

So I've only had minimal opportunity to work on my code. I'm adding spheres to the object addition, but my vertex generation seems to be lacking. This is what I have:

for(b=0; b<=180-space; b+=space)
    {   
        for(a=0; a<=360-space; a+=space)
        {                   
            vertex->x = radius * sin(b*conv) * cos (a*conv);
            vertex->y = radius * cos(b*conv);
            vertex->z = radius * sin(b*conv) * sin (a*conv);
            uvcoord->u = b / 180.0f;
            uvcoord->v = a / 360.0f;
            
            vertex->next = new myVector(vertex);
            vertex=vertex->next;
            vertex->x = radius * sin(b*conv) * cos ((a+space)*conv);
            vertex->y = radius * cos(b*conv);
            vertex->z = radius * sin(b*conv) * sin ((a+space)*conv);
            uvcoord->next = new myUV(uvcoord);
            uvcoord=uvcoord->next;
            uvcoord->u = b / 180.0f;
            uvcoord->v = (a+space) / 360.0f;
            
            vertex->next = new myVector(vertex);
            vertex=vertex->next;
            vertex->x = radius * sin((b+space)*conv) * cos((a+space)*conv);
            vertex->y = radius * cos((b+space)*conv);
            vertex->z = radius * sin((b+space)*conv) * sin((a+space)*conv);
            uvcoord->next = new myUV(uvcoord);
            uvcoord=uvcoord->next;
            uvcoord->u = (b+space) / 180.0f;
            uvcoord->v = (a+space) / 360.0f;
            
            vertex->next = new myVector(vertex);
            vertex=vertex->next;
            vertex->x = radius * sin((b+space)*conv) * cos (a*conv);
            vertex->y = radius * cos((b+space)*conv);
            vertex->z = radius * sin((b+space)*conv) * sin (a*conv);
            uvcoord->next = new myUV(uvcoord);
            uvcoord=uvcoord->next;
            uvcoord->u = (b+space) / 180.0f;
            uvcoord->v = a / 360.0f;
        }
    }   


For some reason, this is resulting in an object that looks like this:

Now, the code is based on this:
In three dimensional space, converting from polar coordinates to cartesian is as follows:

 (0° ≤ θ ≤ 180°) and ( 0° ≤ φ ≤ 360°)
The y coordinate is just r cos θ (where 0° ≤ θ ≤ 180°).
The x coordinate is the vector projected into the x-z plane times the cos of phi, or r sin θ cos φ.
The z coordinate is the vector projected into the x-z plane times the sin of phi, or r sin θ sin φ.

So in the code snippet above, I'm generating a quad polygon based on four vertices.
But it, as you can clearly see in the screenshot above, is leaving gaps. I don't know why. 

What I do know is that it's 10:30 and I have to be up at 5am tomorrow to go to work. So with that, I bid thee goodnight.

1 comment:

  1. Figured this one out just now (at 5:45AM).

    At the end of the loop, I'm not creating a new vertex, so when the loop begins again, the last vertex of the last loop iteration gets overwritten with the new vertex data. Now I have a full sphere!

    Just need to work on the texture mapping. But that's fairly unimportant at the moment.

    ReplyDelete