Ejemplo n.º 1
0
Triangle::Triangle( float x1, float y1, float z1,
         float x2, float y2, float z2,
                   float x3, float y3, float z3) :
v1(STPoint3(x1,y1,z1)),
v2(STPoint3(x2,y2,z2)),
v3(STPoint3(x3,y3,z3))
{}
Ejemplo n.º 2
0
void AABB::rescale(const STTransform4& transform)
{
    std::vector<STPoint3> pts;
    pts.push_back(STPoint3(xmin, ymin, zmin));
    pts.push_back(STPoint3(xmin, ymin, zmax));
    pts.push_back(STPoint3(xmin, ymax, zmin));
    pts.push_back(STPoint3(xmin, ymax, zmax));
    pts.push_back(STPoint3(xmax, ymin, zmin));
    pts.push_back(STPoint3(xmax, ymin, zmax));
    pts.push_back(STPoint3(xmax, ymax, zmin));
    pts.push_back(STPoint3(xmax, ymax, zmax));
    pts[0] = transform * pts[0];
    pts[1] = transform * pts[1];
    pts[2] = transform * pts[2];
    pts[3] = transform * pts[3];
    pts[4] = transform * pts[4];
    pts[5] = transform * pts[5];
    pts[6] = transform * pts[6];
    pts[7] = transform * pts[7];
    xmin = xmax = pts[0].x;
    ymin = ymax = pts[0].y;
    zmin = zmax = pts[0].z;
    for(int i = 0;i < 8;++i)
    {
        if(pts[i].x < xmin) xmin = pts[i].x;
        if(pts[i].x > xmax) xmax = pts[i].x;
        if(pts[i].y < ymin) ymin = pts[i].y;
        if(pts[i].y > ymax) ymax = pts[i].y;
        if(pts[i].z < zmin) zmin = pts[i].z;
        if(pts[i].z > zmax) zmax = pts[i].z;
    }
    xcenter = .5f*(xmin + xmax);
    ycenter = .5f*(ymin + ymax);
    zcenter = .5f*(zmin + zmax);
}
Ejemplo n.º 3
0
// position: (x,y), relative midi note: mapped_midi_num, speed s, max_connection_time: t
Note::Note(float x, float y, float z, int mapped_midi_num, float s, int t)
{
    color = STColor4f((float)rand()/RAND_MAX,(float)rand()/RAND_MAX,(float)rand()/RAND_MAX,1.0);
    centerPosition = STPoint3(x,y,z);
    printf("centerPosition.x = %f, centerPosition.y = %f\n", centerPosition.x, centerPosition.y);
    radius = .2;
    width_max = (10 * radius) / .2;
    
    excitement = 0.0;
    speed = s;
    max_connection_time = t;
    
    mapped_midi = mapped_midi_num;
    Spelling my_spell = SpellNote(mapped_midi_num);
    note_space = my_spell.staff_offset;
    accidental = my_spell.accidental;
    
    max_connections = 50;
    
    connection_list.resize(max_connections);
    
    rel_space = note_space;
    // for notes with ledger lines
    if (note_space > 5) {
        rel_space = 4 + (note_space%2);
    }
    if (note_space < -5) {
        rel_space = -4 + (note_space%2);
    }
}
Ejemplo n.º 4
0
void Note::NoteHead()
{
    glTranslatef(centerPosition.x, centerPosition.y, centerPosition.z); 
    glTranslatef(0.0, rel_space * (radius/8.0), 0.0);
    glColor4f(0.0f, 0.0f, 0.0f, 1.0); 
    //glBegin(GL_TRIANGLE_FAN);
    //glVertex3f(0.0, 0.0, 0.0);
    DrawCircle(STPoint3(0.0,0.0,0.0), radius*0.1, 40, 1);
    //glEnd();
    glLineWidth(.3*width_max);
    //glBegin(GL_LINE_STRIP);
    DrawCircle(STPoint3(0.0,0.0,0.), radius*0.1, 40, 0);
    //glEnd();
    if (accidental == 1) {
        DrawSharp();
    }
    else if (accidental == -1) {
        DrawFlat();
    }
}
Ejemplo n.º 5
0
void Note::AttractToZ() {
    
    STPoint3 me = centerPosition;
    STPoint3 ground = STPoint3(me.x, me.y, 0.0);
    STVector3 path = ground - me;
    float mag = path.Length();
    STVector3 dir = path / mag;
    
    // this parameter goes (~ exponentially) from 0.0 = 3D to 1.0 = 2D
    float dimensionality = 0.001; //.06;
    
    centerPosition = me + (ground - me) * dimensionality;
}
Ejemplo n.º 6
0
    //
    // Generate a rectangle shape with the given width and height.  The center
    // of the rectangle is at the origin.  Width is in the x dimension and
    // height is in the y dimension.  Normals are on the -z axis.
    //
    STShape* CreateRect(float width, float height)
    {
        STShape* result = new STShape();

        STVector3 normal(0, 0, -1);

        float halfw = width/2.0f;
        float halfh = height/2.0f;

        result->AddVertex(STShape::Vertex(
            STPoint3(-halfw, -halfh, 0), normal, STPoint2(0, 0)));
        result->AddVertex(STShape::Vertex(
            STPoint3(halfw, -halfh, 0), normal, STPoint2(1, 0)));
        result->AddVertex(STShape::Vertex(
            STPoint3(halfw, halfh, 0), normal, STPoint2(1, 1)));
        result->AddVertex(STShape::Vertex(
            STPoint3(-halfw, halfh, 0), normal, STPoint2(0, 1)));

        result->AddFace(STShape::Face(0, 1, 2));
        result->AddFace(STShape::Face(0, 2, 3));

        return result;
    }
Ejemplo n.º 7
0
bool Triangle::intersectionWithRay(Ray r, Intersection *outIntersection)
{
    float a = v[0].x - v[1].x;
    float b = v[0].y - v[1].y;
    float c = v[0].z - v[1].z;
    float d = v[0].x - v[2].x;
    float e = v[0].y - v[2].y;
    float f = v[0].z - v[2].z;
    float g = r.d.x;
    float h = r.d.y;
    float i = r.d.z;
    float j = v[0].x - r.e.x;
    float k = v[0].y - r.e.y;
    float l = v[0].z - r.e.z;
    
    float ak_jb = a * k - j * b;
    float jc_al = j * c - a * l;
    float bl_kc = b * l - k * c;
    float ei_hf = e * i - h * f;
    float gf_di = g * f - d * i;
    float dh_eg = d * h - e * g;
    
    float M = a * ei_hf + b * gf_di + c * dh_eg;
    
    float t = -(f * ak_jb + e * jc_al + d * bl_kc) / M;
    if (!r.isValidT(t))
        return false;
    
    float gamma = (i * ak_jb + h * jc_al + g * bl_kc) / M;
    if (gamma < 0 || gamma > 1)
        return false;
    
    float beta = (j * ei_hf + k * gf_di + l * dh_eg) / M;
    if (beta < 0 || beta > 1 - gamma)
        return false;
    
    outIntersection->t = t;
    outIntersection->position = STPoint3((1.0f - beta - gamma) * STVector3(v[0]) + beta * STVector3(v[1]) + gamma * STVector3(v[2]));
    outIntersection->normal = STVector3::Cross(v[2] - v[0], v[1] - v[0]);
    outIntersection->normal.Normalize();
    
    return true;
}
Ejemplo n.º 8
0
GLuint scene_list1 = 0;
GLuint scene_list2 = 0;

GLuint cubeMap;

// current rotation angle
static float h_angle = 0.0;
static float v_angle = MY_PI/2;

bool mouseInit = false;
float lastTime = 0.0;
STPoint2 cur_mouse = STPoint2(0.0,0.0);
STPoint2 last_mouse = STPoint2(0.0,0.0);
STVector2 mouse_move = STVector2(0.0,0.0);

STPoint3 current_location = STPoint3(-10,2,0);
STPoint3 statue_location = STPoint3(0,2.92,0);

STVector3 Up = STVector3(0.0,1.0,0.0);
STVector3 current_forward = STVector3(sin(v_angle)*cos(h_angle),cos(v_angle),sin(v_angle)*sin(h_angle));
STVector3 current_right = STVector3::Cross(current_forward, Up);

// globals for keyboard control
bool go_forward = false;
bool go_backward = false;
bool go_left = false;
bool go_right = false;
bool go_up = false;
bool go_down = false;

struct meshObject {