Posts Tagged ‘math’

h1

quaternions page is up + good times

September 29, 2008

Let me get this out of the way – there is a new article about quaternion rotations up.  Yes, I know I haven’t showed you how to convert to/from them, so it’s useless except as a theoretical paper.  This will soon change, but TOMORROW.  GOD IM TIRED BLARG.

Also to get out of the way, 2D Boy is almost about to release World of Goo, which I’m really geeking about right now.  If you order before they release it, you get a profanity sound effects pack.  FUCK!  😀

So I’ve had some good times this past week, which is interesting, seeing as how it literally started out with me on suicide watch.  I made a full recovery on Tuesday, ironically because of a Dream Theater song I was listening to.  A Change of Seasons, and there’s this part that’s like “I’m sick of all you hypocrites!  I don’t need your sympathy to get me through the day! Seasons change, and so can I!…” and it was really inspiring.  My main problem, I suddenly realized, was in expecting sympathy for my problems.  Whereas in a perfect world I would certainly get some sympathy for the kind of shit I deal with, I realized expecting it from everyone will only make me feel let down.

Then I went skating on Thursday with James, Colleen, and Phillip on 80’s night, and we listened to music from the past (i.e. real music) the whole time while skating.  On Friday I saw James again, and we basically played Destroy All Humans and such the whole time, but after that we went back to the rink on Saturday and enjoyed a roller derby match!  Go RoCo!  That was actually a really good time.  Then the next morning I went to YRUU (that’s youth religious unitarian universalists) again and didn’t get picked on really by that girl, so it was actually pretty cool.  I had a long conversation afterwards with cool people who like Transformers, Spore, D&D, and other incredibly geeky stuff, making me feel at home.  Tomorrow Chuck and Life are on network television, followed by a Tuesday at programming club, where I really just can’t feel better.  I’m on a roll of engaging in non-suckage!  😀

But my point is, I really forget just how much I can do when I’m in good spirits.  I wrote that whole fucking quaternions article in about an hour!  I mean, that is just crazy fast.  Of course it’s not quite finished, but I could have easily just slapped all the functions up there, and didn’t.  In fact, it was like a mini paper on quaternions before it even gets to rotation, and then there’s an extensive discussion on that.

When I get up tomorrow, I’ll get straight to work on the menus and hopefully have a usable thing soon.  And then I really will get to work on the game.  I’m still deciding if it should be pure 2D (aside from the menus obviously) or if I should go all slick and shiny 3D interface on you people, with bells, whistles, and cabbage.  All puppies need cabbage to slaughter freemasons!  Ahhh, I’m like, intoxicated with not feeling awful.  I almost forgot what that was like, you know?  ❤

Advertisements
h1

quaternions, I can make them work!

September 23, 2008

Now that I have arc ball working, I will show you what a quaternion is.  I have a couple of screenshots too, and they are here:

It looks like this initially.

It looks like this initially.

Now we've grabbed the arcball at the center.  The white circle represents the sphere in 4D hyperspace, and the red point is the point on the sphere we've grabbed.

Now we have a white circle showing us the grabable sphere of the arcball. The red point is where we've grabbed it.

As we've dragged the red dot, notice how what we've really done is simply dragged that point over on the arcball, and as the point is dragged, so rotates the sphere, and as the sphere rotates, so does the model.

As we've dragged the red dot, notice how what we've really done is simply dragged that point over on the arcball, and as the point is dragged, so rotates the sphere, and as the sphere rotates, so does the model.

Basically what a quaternion is is a 4 dimensional vector that exists in space over the real numbers.  For the purposes I use it for (rotation) it’s basically is superior, because it can do perfect great circle rotation easily.  The reason is that it isn’t constrained by the Euler representation’s axes (pitch, yaw, roll) which make the question of arbitrary axis smooth rotation much harder.  You have to do something like 3 different space transforms in order to do the rotation, and then you have to go back.  Whereas a quaternion essentially produces an imaginary axis that can rotate as though there were no space transform, because the other elements of the vector are relativistic.  It is very hard to imagine what this looks like, because it’s, you know, hyperspace.  Once the rotation operation has been derived through all that complex imaginary number crap, though, all the imaginary elements are gone, so nothing special is needed for the algorithm.  This wiki page has info on quaternions, and this NeHeGL example is a good demo of how it works.

h1

I made it work zomg happy :3

September 17, 2008

I got this sucka working!  That’s right, a sphere NOT MADE WITH LATITUDE AND LONGITUDE.  Great pwn4ge, what is this miracle?  I’ll tell you.  Basically, what I’ve done is taken an icosahedron and recursively subdivided with level of detail.  You may have seen something like this in the OpenGL red book.  But I swear I didn’t see it in there.  I later found out it was in there.  It turned out their method was better than mine, so I went over to optimizing theirs.  I have my result here, and with a precalculated icosahedron mesh for the tesselating.

Here: (sphere.c)

#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <GL/gl.h>

#define _A 0.525731112119133606f
#define _B 0.850650808352039932f

static unsigned int icosa_indices[20][3]=
{
{0,4,1},{0,9,4},{9,5,4},{4,5,8},{4,8,1},
{8,10,1},{8,3,10},{5,3,8},{5,2,3},{2,7,3},
{7,10,3},{7,6,10},{7,11,6},{11,0,6},{0,1,6},
{6,1,10},{9,0,11},{9,11,2},{9,2,5},{7,2,11}
};

static float icosa_verts[12][3]=
{
{-_A,0.0,_B},{_A,0.0,_B},{-_A,0.0,-_B},{_A,0.0,-_B},
{0.0,_B,_A},{0.0,_B,-_A},{0.0,-_B,_A},{0.0,-_B,-_A},
{_B,_A,0.0},{-_B,_A,0.0},{_B,-_A,0.0},{-_B,-_A,0.0}
};

static void normalize_vert(float *a)
{
float d=sqrtf(a[0]*a[0]+a[1]*a[1]+a[2]*a[2]);
a[0]/=d; a[1]/=d; a[2]/=d;
}

static void draw_recursive_tri(float *a,float *b,float *c,unsigned int div,float r)
{
if (div==0)
{
glNormal3fv(a);
glVertex3f(a[0]*r,a[1]*r,a[2]*r);

glNormal3fv(b);
glVertex3f(b[0]*r,b[1]*r,b[2]*r);

glNormal3fv(c);
glVertex3f(c[0]*r,c[1]*r,c[2]*r);
}
else
{
register unsigned int i;
float ab[3],ac[3],bc[3];
for (i=0; i<3; i++)
{
ab[i]=(a[i]+b[i])/2.0f;
ac[i]=(a[i]+c[i])/2.0f;
bc[i]=(b[i]+c[i])/2.0f;
}

normalize_vert(ab);
normalize_vert(ac);
normalize_vert(bc);

draw_recursive_tri(a,ab,ac,div-1,r);
draw_recursive_tri(b,bc,ab,div-1,r);
draw_recursive_tri(c,ac,bc,div-1,r);
draw_recursive_tri(ab,bc,ac,div-1,r);
}
}

void rat_draw_sphere(unsigned int detail,float radius)
{
register unsigned int i;
glBegin(GL_TRIANGLES);
for (i=0; i<20; i++)
draw_recursive_tri
(
icosa_verts[icosa_indices[i][0]],
icosa_verts[icosa_indices[i][1]],
icosa_verts[icosa_indices[i][2]],
detail,radius
);
glEnd();
}

h1

icosahedrons and geodesics

September 17, 2008

Quick post before I leave to get an allergy shot.  I seem to have found a likely solution for my sphere constructing blues.  Basically, an icosahedron, which is very easy to construct, can be subdivided many times and remain geodesic.  This is the method I will try.  I also will provide links to a couple of pages I found useful in my sphere quest.

http://www.coolgroups.com/icosa/

Aaaannd… I can’t find the other one again.  Booooo.

Gotta go.

h1

Opeth wins, still having sphere trouble

September 17, 2008

Opeth‘s newest album is Watershed, and I just got the opportunity to listen to it.  This thing is incredible, definitely Opeth‘s most ambitious and heavy album yet.  It has a lot more stuff in it that seems to be in metal’s more extreme sub-genres, and yet touches on music which is even more beautiful than any purely acoustic or otherwise soft things they’ve done.  There are parts that even reflect elements of jazz and psychedelic rock.  This album is pure poetry.  I highly recommend it.

And back in apple dancer land, the insane asylum where my happy goat lives, I’m still having trouble with the whole great circles sphere tessellation thing.  I refuse to fall back on lattitude and longitude circles because I’m an efficiency whore.  I’ll get this thing.