Beispiel #1
0
void set_matrix_3d(
    float *matrix, int width, int height,
    float x, float y, float z, float rx, float ry,
    float fov, int ortho, int radius)
{
    float a[16];
    float b[16];
    float aspect = (float)width / height;
    float znear = 0.125;
    float zfar = radius * 32 + 64;
    mat_identity(a);
    mat_translate(b, -x, -y, -z);
    mat_multiply(a, b, a);
    mat_rotate(b, cosf(rx), 0, sinf(rx), ry);
    mat_multiply(a, b, a);
    mat_rotate(b, 0, 1, 0, -rx);
    mat_multiply(a, b, a);
    if (ortho) {
        int size = ortho;
        mat_ortho(b, -size * aspect, size * aspect, -size, size, -zfar, zfar);
    }
    else {
        mat_perspective(b, fov, aspect, znear, zfar);
    }
    mat_multiply(a, b, a);
    mat_identity(matrix);
    mat_multiply(matrix, a, matrix);
}
Beispiel #2
0
CCamera::CCamera()
{
   p_LastKeyPos=0;
   p_Znear=2.0f;
   p_Zfar=2000.0f;  // distanza dei piani di clipping dall'asse z
   p_AspectRatio=640.0f/480.0f;
   p_CurrentAngX=0;
   p_CurrentAngY=0;
   p_CurrentAngZ=0;

   vect_set(&p_CurrentTargetPosition, 0, 0, 0);
   p_CurrentRoll=0;
   p_CurrentFov=(Pi__/2.0f);
   p_CurrentTanFov=1.0f;

   vect_set(&p_LeftFrustrumNormal, 0, 0, 0);
   vect_set(&p_RightFrustrumNormal, 0, 0, 0);
   vect_set(&p_UpFrustrumNormal, 0, 0, 0);
   vect_set(&p_DownFrustrumNormal, 0, 0, 0);

   p_TargetTrack=(CPosTrack *)NULL;
   p_RollTrack=(CRollTrack *)NULL;
   p_FovTrack=(CRollTrack *)NULL;

   mat_identity(&p_ViewMatrix);
   mat_identity(&p_InverseViewMatrix);

   p_Type=TARGETED_CAMERA;
}
Beispiel #3
0
void update_matrix_3d(
    float *matrix, float x, float y, float z, float rx, float ry)
{
    float a[16];
    float b[16];
    int width, height;
    glfwGetFramebufferSize(window, &width, &height);
    glViewport(0, 0, width, height);
    float aspect = (float)width / height;
    mat_identity(a);
    mat_translate(b, -x, -y, -z);
    mat_multiply(a, b, a);
    mat_rotate(b, cosf(rx), 0, sinf(rx), ry);
    mat_multiply(a, b, a);
    mat_rotate(b, 0, 1, 0, -rx);
    mat_multiply(a, b, a);
    if (ortho) {
        int size = 32;
        mat_ortho(b, -size * aspect, size * aspect, -size, size, -256, 256);
    }
    else {
        mat_perspective(b, fov, aspect, 0.1, 1024.0);
    }
    mat_multiply(a, b, a);
    mat_identity(matrix);
    mat_multiply(matrix, a, matrix);
}
Beispiel #4
0
void set_matrix_3d(
    float *matrix, int width, int height,
    float x, float y, float z, float rx, float ry, float fov, int ortho)
{
    float a[16];
    float b[16];
    float aspect = (float)width / height;
    mat_identity(a);
    mat_translate(b, -x, -y - 0.1, -z);
    mat_multiply(a, b, a);
    mat_rotate(b, cosf(rx), 0, sinf(rx), ry);
    mat_multiply(a, b, a);
    mat_rotate(b, 0, 1, 0, -rx);
    mat_multiply(a, b, a);
    if (ortho) {
        int size = 32;
        mat_ortho(b, -size * aspect, size * aspect, -size, size, -256, 256);
    }
    else {
        mat_perspective(b, fov, aspect, 1 / 8.0, 256.0);
    }
    mat_multiply(a, b, a);
    mat_identity(matrix);
    mat_multiply(matrix, a, matrix);
}
void palGenericLink::Init(palBodyBase *parent, palBodyBase *child,
	const palVector3& pivotLocation,
	const palVector3& linearLowerLimits,
	const palVector3& linearUpperLimits,
	const palVector3& angularLowerLimits,
	const palVector3& angularUpperLimits)
{
	/* Even though we'll only use the location of the pivot and not
	 * its orientation, we need to account for rotation of the parent
	 * and child bodies because we need the location of the pivot in
	 * their frames of reference, which might be rotated. (For
	 * example, if the parent is translated by (-5,0,0) and rotated 90
	 * degrees clockwise about z, the global origin isn't just
	 * translated for the parent to (5,0,0), it's rotated to be at
	 * (0,5,0) in the parent's coordinate system.) */
	palMatrix4x4 worldToParent;
	mat_invert(&worldToParent, &parent->GetLocationMatrix());
	palVector3 pivotInParent;
	vec_mat_transform(&pivotInParent, &worldToParent, &pivotLocation);

	palMatrix4x4 worldToChild;
	mat_invert(&worldToChild, &child->GetLocationMatrix());
	palVector3 pivotInChild;
	vec_mat_transform(&pivotInChild, &worldToChild, &pivotLocation);

	palMatrix4x4 frameInParent;
	mat_identity(&frameInParent);
	palMatrix4x4 frameInChild;
	mat_identity(&frameInChild);

	mat_set_translation(&frameInParent, pivotInParent.x, pivotInParent.y, pivotInParent.z);
	mat_set_translation(&frameInChild, pivotInChild.x, pivotInChild.y, pivotInChild.z);

	Init(parent, child, frameInParent, frameInChild, linearLowerLimits, linearUpperLimits, angularLowerLimits, angularUpperLimits);
}
void ParticleRenderer::display()
{
    glEnable(GL_BLEND);
    glBlendFunc(GL_SRC_ALPHA, GL_ONE);
    glDepthMask(GL_FALSE);

    glUseProgram(m_programSprites);

    // Set modelview and projection matricies
    GLint h_ModelViewMatrix = glGetUniformLocation(m_programSprites, "modelview");
    GLint h_ProjectionMatrix = glGetUniformLocation(m_programSprites, "projection");
    matrix4 modelview;
    matrix4 projection;
    mat_identity(modelview);
    mat_identity(projection);
    mat_translate(modelview, m_camera);
    mat_perspective(projection, 60, (float)m_windowWidth / (float)m_windowHeight, 0.1, 1000.0);
    glUniformMatrix4fv(h_ModelViewMatrix, 1, GL_FALSE, (GLfloat*)modelview);
    glUniformMatrix4fv(h_ProjectionMatrix, 1, GL_FALSE, (GLfloat*)projection);

    // Set point size
    GLint h_PointSize = glGetUniformLocation(m_programSprites, "size");
    glUniform1f(h_PointSize, m_spriteSize);

    // Set base and secondary colors
    GLint h_BaseColor = glGetUniformLocation(m_programSprites, "baseColor");
    GLint h_SecondaryColor = glGetUniformLocation(m_programSprites, "secondaryColor");
    glUniform4f(h_BaseColor, 1.0, 1.0, 1.0, 1.0);
    glUniform4f(h_SecondaryColor, m_baseColor[0], m_baseColor[1], m_baseColor[2], m_baseColor[3]);

    // Set position coords
    GLint h_position = glGetAttribLocation(m_programSprites, "a_position");
    glBindBuffer(GL_ARRAY_BUFFER, m_pbo);
    glEnableVertexAttribArray(h_position);
    glVertexAttribPointer(h_position, 4, GL_FLOAT, GL_FALSE, 0, 0);

    GLuint texLoc = glGetUniformLocation(m_programSprites, "splatTexture");
    glUniform1i(texLoc, 0);
    glActiveTexture(GL_TEXTURE0);
    glBindTexture(GL_TEXTURE_2D, m_texture);

    glDrawArrays(GL_POINTS, 0, m_numParticles);

    glDisableVertexAttribArray(h_position);

    glUseProgram(0);

    glDisable(GL_BLEND);
    glDepthMask(GL_TRUE);
}
Beispiel #7
0
void AD_WindModifier::build_objectmatrix (float4 framepos)
{
   AD_Vect3D postmp, stmp;
   AD_Quaternion objrot;
   AD_Matrix posttrans, scaling, maux;

   accum_scale.x=accum_scale.y=accum_scale.z=1.0f;
   mat_identity(&currentmatrix_rot);

   // estrazione dei dati col keyframer: niente di piu' facile col c++ !!!
   if (rotationtrack.numkey>0)
   {
     rotationtrack.get_data(framepos, &objrot);
     quat_rotquat_to_matrix(&objrot, &currentmatrix_rot);
   }
   mat_copy(&currentmatrix_rot, &currentmatrix);

   if (scaletrack.numkey>0)
   {
     scaletrack.get_data(framepos, &stmp);
     mat_setmatrix_of_scaling(&scaling, stmp.x, stmp.y, stmp.z);
	 accum_scale.x*=stmp.x;
	 accum_scale.y*=stmp.y;
	 accum_scale.z*=stmp.z;
   }
   else mat_identity(&scaling);
   
   if (positiontrack.numkey>0) positiontrack.get_data(framepos, &currentpos);
   mat_setmatrix_of_pretraslation(&posttrans, &currentpos);

   mat_mul(&scaling, &currentmatrix_rot, &maux);
   mat_mul(&posttrans, &maux, &currentmatrix);
 
   if (father!=(AD_Object3D *)NULL)
   {
     mat_mulaffine(&father->currentmatrix_rot, &currentmatrix_rot, &currentmatrix_rot);
	 mat_mul(&father->currentmatrix, &currentmatrix, &currentmatrix);
     mat_mulvect(&father->currentmatrix, &currentpos, &postmp);
	 vect_copy(&postmp, &currentpos);
	 
	 accum_scale.x*=father->accum_scale.x;
	 accum_scale.y*=father->accum_scale.y;
	 accum_scale.z*=father->accum_scale.z;
   }

   mat_transpose(&currentmatrix_rot, &inverse_rotmatrix);
   mat_get_row(&currentmatrix, 1, &forza);
   vect_auto_normalize(&forza);
   vect_scale(&forza, strenght*0.00016f*forceScaleFactor, &forza);
}
Beispiel #8
0
void AD_PatchObject::build_objectmatrix (float4 framepos)
// costruisce la matrice di trasformazione, che servira' poi per trasformare
// i vertici dell'oggetto;
{
   AD_Vect3D postmp, stmp;
   AD_Quaternion objrot;
   AD_Matrix posttrans, scaling, maux;

   accum_scale.x=accum_scale.y=accum_scale.z=1.0f;
   mat_identity(&currentmatrix_rot);

   // estrazione dei dati col keyframer: niente di piu' facile col c++ !!!
   if (rotationtrack.numkey>0)
   {
     rotationtrack.get_data(framepos, &objrot);
     quat_rotquat_to_matrix(&objrot, &currentmatrix_rot);
   }
   mat_copy(&currentmatrix_rot, &currentmatrix);

   if (scaletrack.numkey>0)
   {
     scaletrack.get_data(framepos, &stmp);
     mat_setmatrix_of_scaling(&scaling, stmp.x, stmp.y, stmp.z);
	 accum_scale.x=accum_scale.x*stmp.x;
	 accum_scale.y=accum_scale.x*stmp.y;
	 accum_scale.z=accum_scale.x*stmp.z;
   }
   else mat_identity(&scaling);
   
   if (positiontrack.numkey>0) positiontrack.get_data(framepos, &currentpos);
   mat_setmatrix_of_pretraslation(&posttrans, &currentpos);

   mat_mul(&scaling, &currentmatrix_rot, &maux);
   mat_mul(&posttrans, &maux, &currentmatrix);
 
   if (father!=(AD_Object3D *)NULL)
   {
     mat_mulaffine(&father->currentmatrix_rot, &currentmatrix_rot, &currentmatrix_rot);
	 mat_mul(&father->currentmatrix, &currentmatrix, &currentmatrix);
     mat_mulvect(&father->currentmatrix, &currentpos, &postmp);
	 vect_copy(&postmp, &currentpos);
	 
	 accum_scale.x*=father->accum_scale.x;
	 accum_scale.y*=father->accum_scale.y;
	 accum_scale.z*=father->accum_scale.z;
   }

   mat_transpose(&currentmatrix_rot, &inverse_rotmatrix);
}
Beispiel #9
0
void make_player(
    float *data,
    float x, float y, float z, float rx, float ry)
{
    float ao[6][4] = {0};
    float light[6][4] = {
        {0.8, 0.8, 0.8, 0.8},
        {0.8, 0.8, 0.8, 0.8},
        {0.8, 0.8, 0.8, 0.8},
        {0.8, 0.8, 0.8, 0.8},
        {0.8, 0.8, 0.8, 0.8},
        {0.8, 0.8, 0.8, 0.8}
    };
    make_cube_faces(
        data, ao, light,
        1, 1, 1, 1, 1, 1,
        226, 224, 241, 209, 225, 227,
        0, 0, 0, 0.4);
    float ma[16];
    float mb[16];
    mat_identity(ma);
    mat_rotate(mb, 0, 1, 0, rx);
    mat_multiply(ma, mb, ma);
    mat_rotate(mb, cosf(rx), 0, sinf(rx), -ry);
    mat_multiply(ma, mb, ma);
    mat_apply(data, ma, 36, 3, 10);
    mat_translate(mb, x, y, z);
    mat_multiply(ma, mb, ma);
    mat_apply(data, ma, 36, 0, 10);
}
Beispiel #10
0
void make_rotated_cube(
    float *vertex, float *normal, float *texture,
    float x, float y, float z, float n, int w, float rx, float ry)
{
    make_cube(vertex, normal, texture, 1, 1, 1, 1, 1, 1, 0, 0, 0, n, w);
    float a[16];
    float b[16];
    float vec[4] = {0};
    vec[3] = 1;
    mat_identity(a);
    mat_rotate(b, 0, 1, 0, rx);
    mat_multiply(a, b, a);
    mat_rotate(b, cosf(rx), 0, sinf(rx), -ry);
    mat_multiply(a, b, a);
    mat_translate(b, x, y, z);
    mat_multiply(a, b, a);
    for (int i = 0; i < 36; i++) {
        // vertex
        float *v = vertex + i * 3;
        vec[0] = *(v++); vec[1] = *(v++); vec[2] = *(v++);
        mat_vec_multiply(vec, a, vec);
        v = vertex + i * 3;
        *(v++) = vec[0]; *(v++) = vec[1]; *(v++) = vec[2];
        // normal
        float *d = normal + i * 3;
        vec[0] = *(d++); vec[1] = *(d++); vec[2] = *(d++);
        mat_vec_multiply(vec, a, vec);
        d = normal + i * 3;
        *(d++) = vec[0]; *(d++) = vec[1]; *(d++) = vec[2];
    }
}
Beispiel #11
0
void Init(){
	/*
		Standard initialization
	*/
	vid_set_mode(DM_640x480,PM_RGB565);
	vid_border_color(0,255,0);

	//pvr_init_defaults();
	
	pvr_init_params_t pvr_params;
	pvr_params.vertex_buf_size= 1024*512;
	pvr_params.dma_enabled= 0;
	pvr_params.fsaa_enabled= 0;
	pvr_params.autosort_disabled = 0;
	pvr_params.opb_sizes[PVR_LIST_OP_POLY]= PVR_BINSIZE_32;
	pvr_params.opb_sizes[PVR_LIST_OP_MOD]= PVR_BINSIZE_0;
	pvr_params.opb_sizes[PVR_LIST_TR_POLY]= PVR_BINSIZE_16;
	pvr_params.opb_sizes[PVR_LIST_TR_MOD]= PVR_BINSIZE_0;
	pvr_params.opb_sizes[PVR_LIST_PT_POLY]= PVR_BINSIZE_0;
	
	pvr_init(&pvr_params);

	
	//Set palette to ARGB8888 format
	pvr_set_pal_format(PVR_PAL_ARGB8888);
	
	mat_identity();

	
	//Initialize ogg streamer
	//snd_stream_init();
	//sndoggvorbis_init();
	
}
Beispiel #12
0
/* Rotate a matrix about the X, Y or Z axis */
void mat_rotate (Matrix mat1, Matrix mat2, int axis, float angle)
{
    Matrix mat;
    float  cosa, sina;

    cosa = cos ((PI/180.0) * angle);
    sina = sin ((PI/180.0) * angle);

    mat_identity (mat);

    switch (axis) {
    case X:
        mat[1][1] = cosa;
        mat[1][2] = sina;
        mat[2][1] = -sina;
        mat[2][2] = cosa;
        break;

    case Y:
        mat[0][0] = cosa;
        mat[0][2] = -sina;
        mat[2][0] = sina;
        mat[2][2] = cosa;
        break;

    case Z:
        mat[0][0] = cosa;
        mat[0][1] = sina;
        mat[1][0] = -sina;
        mat[1][1] = cosa;
        break;
    }

    mat_mult (mat1, mat2, mat);
}
Beispiel #13
0
void render_cloud(Cloud *cloud, CloudAttrib *attrib){
    float matrix[16];

    float matrix_prev[16];
    glGetUniformfv(attrib->program, attrib->model, matrix_prev);
    glGetUniformfv(attrib->program, attrib->model, matrix);

    mat_identity(matrix);

    mat_translate(matrix, cloud->x - (cloud->hmWidth/2), CLOUD_Y_HEIGHT + cloud->y, cloud->z - (cloud->hmDepth/2));

    mat_scale(matrix, cloud->sx, cloud->sy, cloud->sz);

    glUniform3f(attrib->cloudColour, cloud->r, cloud->g, cloud->b);

    int i, j;
    for (i = 0; i < cloud->hmWidth; i++) {
        for (j=0; j < cloud->hmDepth; j++) {
            mat_translate_existing(matrix, 0, 0, 1);
            int heightval = cloud->heightmap[i*(cloud->hmDepth) + j];
            if(heightval > 0){
                float up = heightval/2.0f;
                mat_translate_existing(matrix, 0, up, 0);
                mat_scale(matrix, 1, heightval, 1);
                glUniformMatrix4fv(attrib->model, 1, GL_FALSE, matrix);
                glDrawArrays(GL_TRIANGLES, 0, 36);
                mat_translate_existing(matrix, 0, -up, 0);
                mat_scale(matrix, 1, 1.0f/heightval, 1);
            }
        }
        mat_translate_existing(matrix, 1, 0, -cloud->hmDepth);
    }
    glUniformMatrix4fv(attrib->model, 1, GL_FALSE, matrix_prev);
}
Beispiel #14
0
void make_plant(
    float *data, float ao, float light,
    float px, float py, float pz, float n, int w, float rotation)
{
    static const float positions[4][4][3] = {
        {{ 0, -1, -1}, { 0, -1, +1}, { 0, +1, -1}, { 0, +1, +1}},
        {{ 0, -1, -1}, { 0, -1, +1}, { 0, +1, -1}, { 0, +1, +1}},
        {{-1, -1,  0}, {-1, +1,  0}, {+1, -1,  0}, {+1, +1,  0}},
        {{-1, -1,  0}, {-1, +1,  0}, {+1, -1,  0}, {+1, +1,  0}}
    };
    static const float normals[4][3] = {
        {-1, 0, 0},
        {+1, 0, 0},
        {0, 0, -1},
        {0, 0, +1}
    };
    static const float uvs[4][4][2] = {
        {{0, 0}, {1, 0}, {0, 1}, {1, 1}},
        {{1, 0}, {0, 0}, {1, 1}, {0, 1}},
        {{0, 0}, {0, 1}, {1, 0}, {1, 1}},
        {{1, 0}, {1, 1}, {0, 0}, {0, 1}}
    };
    static const float indices[4][6] = {
        {0, 3, 2, 0, 1, 3},
        {0, 3, 1, 0, 2, 3},
        {0, 3, 2, 0, 1, 3},
        {0, 3, 1, 0, 2, 3}
    };
    float *d = data;
    float s = 0.0625;
    float a = 0;
    float b = s;
    struct item_list *plant = get_item_by_id(ABS(w));
    float du = (plant->tile->sprite % 16) * s;
    float dv = (plant->tile->sprite / 16) * s;
    for (int i = 0; i < 4; i++) {
        for (int v = 0; v < 6; v++) {
            int j = indices[i][v];
            *(d++) = n * positions[i][j][0];
            *(d++) = n * positions[i][j][1];
            *(d++) = n * positions[i][j][2];
            *(d++) = normals[i][0];
            *(d++) = normals[i][1];
            *(d++) = normals[i][2];
            *(d++) = du + (uvs[i][j][0] ? b : a);
            *(d++) = dv + (uvs[i][j][1] ? b : a);
            *(d++) = ao;
            *(d++) = light;
        }
    }
    float ma[16];
    float mb[16];
    mat_identity(ma);
    mat_rotate(mb, 0, 1, 0, RADIANS(rotation));
    mat_multiply(ma, mb, ma);
    mat_apply(data, ma, 24, 3, 10);
    mat_translate(mb, px, py, pz);
    mat_multiply(ma, mb, ma);
    mat_apply(data, ma, 24, 0, 10);
}
Beispiel #15
0
void update_matrix_3d(
    float *matrix, float x, float y, float z, float rx, float ry)
{
    float a[16];
    float b[16];
    int width, height;
    glfwGetWindowSize(&width, &height);
    glViewport(0, 0, width, height);
    float aspect = (float)width / height;
    mat_identity(a);
    mat_translate(b, -x, -y, -z);
    mat_multiply(a, b, a);
    mat_rotate(b, cosf(rx), 0, sinf(rx), ry);
    mat_multiply(a, b, a);
    mat_rotate(b, 0, 1, 0, -rx);
    mat_multiply(a, b, a);
    if (ortho) {
        int size = 32;
        mat_ortho(b, -size * aspect, size * aspect, -size, size, -256, 256);
    }
    else {
        mat_perspective(b, 65.0, aspect, 0.1, 1024.0);
    }
    mat_multiply(a, b, a);
    for (int i = 0; i < 16; i++) {
        matrix[i] = a[i];
    }
}
Beispiel #16
0
void make_rotated_cube(float *data, float ao[6][4], float light[6][4],
                       int left, int right, int top, int bottom, int front, int back,
                       float x, float y, float z, float n, float rx, float ry, float rz,
                       int w, const int blocks[256][6]) {
    int wleft = blocks[w][0];
    int wright = blocks[w][1];
    int wtop = blocks[w][2];
    int wbottom = blocks[w][3];
    int wfront = blocks[w][4];
    int wback = blocks[w][5];
    make_cube_faces(
        data, ao, light,
        left, right, top, bottom, front, back,
        wleft, wright, wtop, wbottom, wfront, wback,
        n);
    float ma[16];
    float mb[16];
    mat_identity(ma);
    /* Create rotation transformation */
    mat_rotate(mb, 0, 1, 0, ry);
    mat_multiply(ma, mb, ma);
    mat_rotate(mb, 1, 0, 0, rx);
    mat_multiply(ma, mb, ma);
    mat_rotate(mb, 0, 0, 1, rz);
    mat_multiply(ma, mb, ma);
    /* Apply to normals */
    mat_apply(data, ma, (left + right + top + bottom + front + back)*6, 3, 10);
    /* Create translation transformation */
    mat_translate(mb, x, y, z);
    /* Merge with rotation transformation */
    mat_multiply(ma, mb, ma);
    /* Apply to vertices */
    mat_apply(data, ma, (left + right + top + bottom + front + back)*6, 0, 10);
}
void palHydrofoil::Apply() {
			palMatrix4x4 m;
			palMatrix4x4 out;
			palVector3 V;
			m_pBody->GetLinearVelocity(V);
			palMatrix4x4 bodypos = m_pBody->GetLocationMatrix();

			mat_identity(&m);
			mat_translate(&m,m_fAxisX,m_fAxisY,m_fAxisZ);
			mat_multiply(&out,&bodypos,&m); //out is now the facing of the sub

			palVector3 uvw;
			uvw.x=out._41-bodypos._41;
			uvw.y=out._42-bodypos._42;
			uvw.z=out._43-bodypos._43;
			vec_norm(&uvw);
			vec_vec_mul(&uvw,&uvw,&V); //now have uvw for velocity fowards

			Float alpha;
			
			/*alpha = atan2(uvw.y,uvw.x);//arctan(w/u);
			alpha=Clamp(alpha);			
			printf("ca:%5.3f ",alpha);*/
			alpha=m_alpha;


			Float lift = Float(0.5) * m_row * (alpha*alpha*m_CL_a+alpha*m_CL_b+m_CL_c)* m_Af * uvw.x*uvw.x;
			//		printf("{%f,%f (%f %f %f)}",(alpha*alpha*m_CL_a+alpha*m_CL_b+m_CL_c),Float(0.5) * m_row * m_Af,m_CL_a,m_CL_b,m_CL_c);

//			if (alpha<0) lift = -lift;

//			printf("lift%5.3f :%f, %f\n",lift,uvw.x,alpha);
			SetImpulse(lift);
			palImpulseActuator::Apply();
	}
Beispiel #18
0
void CCamera::m_BuildWorldMatrix(void)
{
  float4 sinx, cosx, siny, cosy, sinz, cosz;
  AD_Matrix pretrans, irot, swapXY;
  AD_Vect3D ptmp;

  sinx = fast_sinf(p_CurrentAngX);
  cosx = fast_cosf(p_CurrentAngX);
  siny = fast_sinf(p_CurrentAngY);
  cosy = fast_cosf(p_CurrentAngY);
  sinz = fast_sinf(p_CurrentAngZ);
  cosz = fast_cosf(p_CurrentAngZ);

  vect_neg(&p_CurrentPosition, &ptmp);
  mat_setmatrix_of_pretraslation(&pretrans, &ptmp);

  mat_identity(&p_CurrentRotationMatrix);
  p_CurrentRotationMatrix.a[0][0] =  sinx * siny * sinz + cosx * cosz;
  p_CurrentRotationMatrix.a[0][1] =  cosy * sinz;
  p_CurrentRotationMatrix.a[0][2] =  sinx * cosz - cosx * siny * sinz;
  p_CurrentRotationMatrix.a[1][0] =  sinx * siny * cosz - cosx * sinz;
  p_CurrentRotationMatrix.a[1][1] =  cosy * cosz;
  p_CurrentRotationMatrix.a[1][2] = -cosx * siny * cosz - sinx * sinz;
  p_CurrentRotationMatrix.a[2][0] = -sinx * cosy;
  p_CurrentRotationMatrix.a[2][1] =  siny;
  p_CurrentRotationMatrix.a[2][2] =  cosx * cosy;
  
  mat_mul(&p_CurrentRotationMatrix, &pretrans, &p_ViewMatrix);

  // costruzione matrice inversa
  mat_transpose(&p_CurrentRotationMatrix, &irot);
  mat_setmatrix_of_pretraslation(&pretrans, &p_CurrentPosition);
  mat_mul(&pretrans, &irot, &p_InverseViewMatrix);


  // costruzione matrice per il linking con oggetti
  // 1) matrice di swap YZ
  mat_identity(&swapXY);
  swapXY.a[1][1]=0;
  swapXY.a[2][2]=0;
  swapXY.a[1][2]=1;
  swapXY.a[2][1]=-1;

  mat_mul(&p_InverseViewMatrix, &swapXY, &p_WorldMatrix);
  //mat_mul(&swapXY, &p_InverseViewMatrix, &p_WorldMatrix);
  //mat_copy(&p_InverseViewMatrix, &p_WorldMatrix);
}
static void
mat_translate(GLfloat mat[16], float tx, float ty, float tz)
{
   mat_identity(mat);
   mat[12] = tx;
   mat[13] = ty;
   mat[14] = tx;
}
CGeometricObject::CGeometricObject()
{
   strcpy(p_Name, "");
   strcpy(p_FatherName, "");
   p_Father=(CGeometricObject *)NULL;
   p_HasChildrens=0;

   p_BaseMaterial=(CMaterial *)NULL;
   for (int32 i=0; i<MAX_LODS; i++)
   {
	  p_Lods[i].Mesh=(CMesh *)NULL;
	  p_Lods[i].DistMin=0;
	  p_Lods[i].DistMax=10000.0f;
      p_Lods[i].VBStart=-1;
      p_Lods[i].VBLong=-1;
      p_Lods[i].IBStart=-1;
      p_Lods[i].IBLong=-1;
   }
   p_NumLods=0;
   p_VertexBuffer=(IDirect3DVertexBuffer8 *)NULL;
   p_StaticVertex=1;  // non sono soggetti a modificatori

   p_HideTrack=(CHideTrack *)NULL;
   p_PosTrack=(CPosTrack *)NULL;
   p_RotTrack=(CRotTrack *)NULL;
   p_ScaleTrack=(CPosTrack *)NULL;

   p_Visible=1;
   vect_set(&p_Pivot, 0, 0, 0);
   vect_set(&p_CurrentPosition, 0, 0, 0);
   quat_set(&p_CurrentRotationQuaternion, 0, 0, 0, 0);
   mat_identity(&p_CurrentRotationMatrix);
   vect_set(&p_CurrentScale, 1, 1, 1);
   vect_set(&p_TotalScale, 1, 1, 1);
   mat_identity(&p_WorldMatrix);
   mat_identity(&p_InverseWorldMatrix);

   p_SPHEREBoundVolume=(CBoundVolume *)NULL;
   p_AABBBoundVolume=(CBoundVolume *)NULL;
   p_OBBBoundVolume=(CBoundVolume *)NULL;

   for (i=0; i<MAX_OSM_MODIFIERS; i++)
      p_OSMs[i]=(CObjectSpaceModifier *)NULL;
   p_NumOSMs=0;
}
/* Make sure the proper matrices are in the matrix registers */
static void fix_matrices() {
	if (gl_matrix_dirty) {
		mat_identity();
		glKosMatrixApply(GL_KOS_SCREENVIEW);
		glKosMatrixApply(GL_PROJECTION);
		glKosMatrixApply(GL_MODELVIEW);

		gl_matrix_dirty = GL_FALSE;
	}
}
Beispiel #22
0
void AD_TaperModifier::update(float4 framepos)
{
   AD_Vect3D sub_center;
   AD_Matrix mrot, imrot, pret, ipret;

   if (center_track!=(postrack *)NULL)
      center_track->get_data(framepos, &center);

   if (amount_track!=(rolltrack *)NULL)
	   amount_track->get_data(framepos, &amount);

   if (curve_track!=(rolltrack *)NULL)
	   curve_track->get_data(framepos, &curve);

   if (uplim_track!=(rolltrack *)NULL)
	   uplim_track->get_data(framepos, &uplim);

   if (lowlim_track!=(rolltrack *)NULL)
	   lowlim_track->get_data(framepos, &lowlim);

   // costruzione matrice di trasformazione e la sua
   // inversa
   sub_center.x=-center.x;
   sub_center.y=-center.y;
   sub_center.z=-center.z;

   switch (axis)
   {
     case 0:  // asse X
             mat_setmatrix_of_eulerrotationZ(&mrot, (float)(-M_PI/2.0));
			 l=bbx2-bbx1;
		     break;
     case 1:  // asse Y
             mat_identity(&mrot);
			 l=bby2-bby1;
		     break;
     case 2:  // asse Z
             mat_setmatrix_of_eulerrotationX(&mrot, (float)(M_PI/2.0));
			 l=bbz2-bbz1;
		     break;
   }

   mat_transpose(&mrot, &imrot);
   mat_setmatrix_of_pretraslation(&pret, &sub_center);
   mat_setmatrix_of_pretraslation(&ipret, &center);
   mat_mul (&mrot, &pret, &tm);
   mat_mul (&ipret, &imrot, &invtm);

   switch (effectaxis)
   {
     case 0: doX = 1;  doY = 0; break;
     case 1: doX = 0;  doY = 1;  break;
     case 2: doX = 1;  doY = 1;  break;
   }
}
Beispiel #23
0
void AD_TwistModifier::update(float4 framepos)
{
   AD_Vect3D sub_center;
   AD_Matrix mrot, imrot, pret, ipret;

   if (center_track!=(postrack *)NULL)
      center_track->get_data(framepos, &center);

   if (angle_track!=(rolltrack *)NULL)
	   angle_track->get_data(framepos, &angle);

   if (bias_track!=(rolltrack *)NULL)
	   bias_track->get_data(framepos, &bias);

   if (uplim_track!=(rolltrack *)NULL)
	   uplim_track->get_data(framepos, &uplim);

   if (lowlim_track!=(rolltrack *)NULL)
	   lowlim_track->get_data(framepos, &lowlim);

   // costruzione matrice di trasformazione e la sua
   // inversa
   sub_center.x=-center.x;
   sub_center.y=-center.y;
   sub_center.z=-center.z;

   switch (axis)
   {
     case 0:  // asse X
             mat_setmatrix_of_eulerrotationZ(&mrot, (float)(-M_PI/2.0));
			 height=bbx2-bbx1;
		     break;
     case 1:  // asse Y
             mat_identity(&mrot);
			 height=bby2-bby1;
		     break;
     case 2:  // asse Z
             mat_setmatrix_of_eulerrotationX(&mrot, (float)(M_PI/2.0));
			 height=bbz2-bbz1;
		     break;
   }

   mat_transpose(&mrot, &imrot);
   mat_setmatrix_of_pretraslation(&pret, &sub_center);
   mat_setmatrix_of_pretraslation(&ipret, &center);
   mat_mul (&mrot, &pret, &tm);
   mat_mul (&ipret, &imrot, &invtm);
   if (height==0)
   {
	 angle = 0.0f;
	 angleOverHeight = 0.0f;
   }
   else angleOverHeight = angle / height;
}
Beispiel #24
0
void set_matrix_item(float *matrix, int width, int height) {
    float a[16];
    float b[16];
    float aspect = (float)width / height;
    float size = 64;
    float box = height / size / 2;
    float xoffset = 1 - size / width * 2;
    float yoffset = 1 - size / height * 2;
    mat_identity(a);
    mat_rotate(b, 0, 1, 0, -PI / 4);
    mat_multiply(a, b, a);
    mat_rotate(b, 1, 0, 0, -PI / 10);
    mat_multiply(a, b, a);
    mat_ortho(b, -box * aspect, box * aspect, -box, box, -1, 1);
    mat_multiply(a, b, a);
    mat_translate(b, -xoffset, -yoffset, 0);
    mat_multiply(a, b, a);
    mat_identity(matrix);
    mat_multiply(matrix, a, matrix);
}
Beispiel #25
0
void set_matrix_item_r(float *matrix, int width, int height, float scale,
        float xoffset, float yoffset, float rx, float ry, float rz) {
    float a[16];
    float b[16];
    float aspect = (float)width / height;
    float size = 64 * scale;
    float box = height / size / 2;
    mat_identity(a);
    mat_rotate(b, 0, 1, 0, rx);
    mat_multiply(a, b, a);
    mat_rotate(b, 1, 0, 0, ry);
    mat_multiply(a, b, a);
    mat_rotate(b, 0, 0, 1, rz);
    mat_multiply(a, b, a);
    mat_ortho(b, -box * aspect, box * aspect, -box, box, -3, 2);
    mat_multiply(a, b, a);
    mat_translate(b, -xoffset, -yoffset, 0);
    mat_multiply(a, b, a);
    mat_identity(matrix);
    mat_multiply(matrix, a, matrix);
}
Beispiel #26
0
// Render a cube with ID w at x, y. This function is used to render the inventory
// blocks, like the belt and the inventory screen.
void render_inventory_block(Attrib *attrib, int w, float s, float x, float y, int flag) {
    glUseProgram(attrib->program);
    glUniform3f(attrib->camera, 0, 0, 5);
    glUniform1i(attrib->sampler, 0); // GL_TEXTURE0
    glUniform1f(attrib->timer, PI*2);
    float identity[16];
    mat_identity(identity);
    glUniformMatrix4fv(attrib->extra5, 1, GL_FALSE, identity);
    float matrix[16];
    GLuint buffer;

    // Default block rotations
    float rx = -PI/4;
    float ry = -PI/10;
    float rz = 0;
    float dz = 0;

    switch (flag) {
        case 1:
            rx = -PI/8;
            break;
        case 2:
            rx = -PI/8;
            ry = -PI/10;
            rz = -PI/16;
            dz = -1.0;
            break;
        case 3:
            rx = -PI/8;
            ry = -PI/10;
            rz = -PI/16;
            dz = 2.0;
            break;
    }

    set_matrix_item_r(matrix, g->width, g->height, s, x, y, rx, ry, rz);

    if (is_plant(w)) {
        glDeleteBuffers(1, &buffer);
        buffer = gen_plant_buffer(0, 0, dz, 0.5, w);
    } else {
        buffer = gen_cube_buffer(0, 0, dz, 0.5, w);
    }
    glUniformMatrix4fv(attrib->matrix, 1, GL_FALSE, matrix);
    if (is_plant(w)) {
        draw_plant(attrib, buffer);
    } else {
        draw_cube(attrib, buffer);
    }
    del_buffer(buffer);
}
void palImpulseActuator::Apply()
{
	palMatrix4x4 m;
	mat_identity(&m);
	mat_translate(&m,m_fRelativePosX,m_fRelativePosY,m_fRelativePosZ);
	//printf("rel:%f %f %f  ",m._41,m._42,m._43);
	palMatrix4x4 bodypos = m_pBody->GetLocationMatrix();
	

	palMatrix4x4 out;

	mat_multiply(&out,&bodypos,&m);
	palVector3 newpos;
	newpos.x=out._41;
	newpos.y=out._42;
	newpos.z=out._43;
//	printf("output : %f %f %f ",out._41,out._42,out._43);

//	imp_pos=out;
	
	mat_identity(&m);
	mat_translate(&m,m_fAxisX,m_fAxisY,m_fAxisZ);
	mat_multiply(&out,&bodypos,&m);

//	printf("output : %f %f %f\n",out._41,out._42,out._43);

//	imp_axis=out;

	palVector3 newaxis;
	newaxis.x=out._41-bodypos._41;
	newaxis.y=out._42-bodypos._42;
	newaxis.z=out._43-bodypos._43;
	vec_norm(&newaxis);

	m_pBody->ApplyImpulseAtPosition(newpos.x,newpos.y,newpos.z,newaxis.x*m_fImpulse,newaxis.y*m_fImpulse,newaxis.z*m_fImpulse);


	}
Beispiel #28
0
void update_matrix_item(float *matrix) {
    float a[16];
    float b[16];
    int width, height;
    glfwGetFramebufferSize(window, &width, &height);
    glViewport(0, 0, width, height);
    float aspect = (float)width / height;
    float size = 64;
    float box = height / size / 2;
    float xoffset = 1 - size / width * 2;
    float yoffset = 1 - size / height * 2;
    mat_identity(a);
    mat_rotate(b, 0, 1, 0, PI / 4);
    mat_multiply(a, b, a);
    mat_rotate(b, 1, 0, 0, -PI / 10);
    mat_multiply(a, b, a);
    mat_ortho(b, -box * aspect, box * aspect, -box, box, -1, 1);
    mat_multiply(a, b, a);
    mat_translate(b, -xoffset, -yoffset, 0);
    mat_multiply(a, b, a);
    mat_identity(matrix);
    mat_multiply(matrix, a, matrix);
}
Beispiel #29
0
void lookat(vec3 eye, vec3 center, vec3 up, float* camera) {
	vec3 z = normal3(sub3(eye, center));
	vec3 x = normal3(cross3(up,z));
	vec3 y = normal3(cross3(z,x));
	float Minv[4][4];
	float Tr[4][4];
	mat_identity(&Minv[0][0]);
	mat_identity(&Tr[0][0]);

	Minv[0][0] = x.x;
	Minv[1][0] = y.x;
	Minv[2][0] = z.x;
	Tr[0][3] = -center.x;
	Minv[0][1] = x.y;
	Minv[1][1] = y.y;
	Minv[2][1] = z.y;
	Tr[1][3] = -center.y;
	Minv[0][2] = x.z;
	Minv[1][2] = y.z;
	Minv[2][2] = z.z;
	Tr[2][3] = -center.z;
	matmul(&Minv[0][0], &Tr[0][0], camera);
}
Beispiel #30
0
// ---------------------------------------------------------
AD_Object3D::AD_Object3D()   // costruttore
{
   num_vertex3D=num_vertexUV=num_vertex2D=num_normals=0;
   num_tria=num_tria_envRGB=num_tria_RGB=num_tria_envmap=0;

   vertex3D=(AD_Vertex3D *)NULL;
   vertex2D=(AD_Vertex2D *)NULL;
   vertexUV=(AD_VectUV *)NULL;

   tria_envRGB=tria_RGB=tria_envmap=tria=(AD_Tria3D *)NULL;
   flare=(texture *)NULL;
   latoX=latoY=0;
   flare_scale_x=flare_scale_y=160.0f;

   father_name=name=(char *)NULL;
   father=(AD_Object3D *)NULL;
   have_childrens=0;

   num_omni=num_spot=0;

   matbase=(material *)NULL;
   vect_set(&accum_scale, 1, 1, 1);
   radius=0;
   
   for (int i=0; i<MAX_OSM_MODIFIERS; i++)
     OSMmods[i]=(AD_OSMObject *)NULL;
   
   num_OSMmods=0;
   bones_matrix=(AD_Matrix **)NULL;
   bones_matrix_rot=(AD_Matrix **)NULL;
   skin_modifier=(Skin_Bone **)NULL;
   skinned_object=(AD_Object3D *)NULL;
   mat_identity(&currentmatrix);
   mat_identity(&currentmatrix_rot);
   mat_identity(&inverse_rotmatrix);
   mat_identity(&incremental_rotmatrix);
}