]> de.git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - clvm_cmds.c
skel_build: normalize the per-bone matrices
[xonotic/darkplaces.git] / clvm_cmds.c
index e5cfe01102cbda3057bb72159c8fba63a3ca07b2..c7b24a4a9dc9bd5b924581473eff9f3d8524d7d8 100644 (file)
@@ -1705,14 +1705,14 @@ static void VM_CL_ReadPicture (prvm_prog_t *prog)
        const char *name;
        unsigned char *data;
        unsigned char *buf;
-       int size;
+       unsigned short size;
        int i;
        cachepic_t *pic;
 
        VM_SAFEPARMCOUNT(0, VM_CL_ReadPicture);
 
        name = MSG_ReadString(&cl_message, cl_readstring, sizeof(cl_readstring));
-       size = MSG_ReadShort(&cl_message);
+       size = (unsigned short) MSG_ReadShort(&cl_message);
 
        // check if a texture of that name exists
        // if yes, it is used and the data is discarded
@@ -1884,10 +1884,14 @@ static void VM_CL_copyentity (prvm_prog_t *prog)
 // #404 void(vector org, string modelname, float startframe, float endframe, float framerate) effect (DP_SV_EFFECT)
 static void VM_CL_effect (prvm_prog_t *prog)
 {
+#if 1
+       Con_Printf("WARNING: VM_CL_effect not implemented\n"); // FIXME: this needs to take modelname not modelindex, the csqc defs has it as string and so it shall be
+#else
        vec3_t org;
        VM_SAFEPARMCOUNT(5, VM_CL_effect);
        VectorCopy(PRVM_G_VECTOR(OFS_PARM0), org);
        CL_Effect(org, (int)PRVM_G_FLOAT(OFS_PARM1), (int)PRVM_G_FLOAT(OFS_PARM2), (int)PRVM_G_FLOAT(OFS_PARM3), PRVM_G_FLOAT(OFS_PARM4));
+#endif
 }
 
 // #405 void(vector org, vector velocity, float howmany) te_blood (DP_TE_BLOOD)
@@ -2732,7 +2736,7 @@ static void VM_CL_ParticleThemeToGlobals(vmparticletheme_t *theme, prvm_prog_t *
        // VorteX: int only can store 0-255, not 0-256 which means 0 - 0,99609375...
        VectorSet(PRVM_clientglobalvector(particle_color1), (theme->color1 >> 16) & 0xFF, (theme->color1 >> 8) & 0xFF, (theme->color1 >> 0) & 0xFF);
        VectorSet(PRVM_clientglobalvector(particle_color2), (theme->color2 >> 16) & 0xFF, (theme->color2 >> 8) & 0xFF, (theme->color2 >> 0) & 0xFF);
-       PRVM_clientglobalfloat(particle_tex) = (float)theme->tex;
+       PRVM_clientglobalfloat(particle_tex) = (prvm_vec_t)theme->tex;
        PRVM_clientglobalfloat(particle_size) = theme->size;
        PRVM_clientglobalfloat(particle_sizeincrease) = theme->sizeincrease;
        PRVM_clientglobalfloat(particle_alpha) = theme->alpha/256;
@@ -2748,9 +2752,9 @@ static void VM_CL_ParticleThemeToGlobals(vmparticletheme_t *theme, prvm_prog_t *
        PRVM_clientglobalfloat(particle_stretch) = theme->stretch;
        VectorSet(PRVM_clientglobalvector(particle_staincolor1), ((int)theme->staincolor1 >> 16) & 0xFF, ((int)theme->staincolor1 >> 8) & 0xFF, ((int)theme->staincolor1 >> 0) & 0xFF);
        VectorSet(PRVM_clientglobalvector(particle_staincolor2), ((int)theme->staincolor2 >> 16) & 0xFF, ((int)theme->staincolor2 >> 8) & 0xFF, ((int)theme->staincolor2 >> 0) & 0xFF);
-       PRVM_clientglobalfloat(particle_staintex) = (float)theme->staintex;
-       PRVM_clientglobalfloat(particle_stainalpha) = (float)theme->stainalpha/256;
-       PRVM_clientglobalfloat(particle_stainsize) = (float)theme->stainsize;
+       PRVM_clientglobalfloat(particle_staintex) = (prvm_vec_t)theme->staintex;
+       PRVM_clientglobalfloat(particle_stainalpha) = (prvm_vec_t)theme->stainalpha/256;
+       PRVM_clientglobalfloat(particle_stainsize) = (prvm_vec_t)theme->stainsize;
        PRVM_clientglobalfloat(particle_delayspawn) = theme->delayspawn;
        PRVM_clientglobalfloat(particle_delaycollision) = theme->delaycollision;
        PRVM_clientglobalfloat(particle_angle) = theme->angle;
@@ -3425,7 +3429,7 @@ void VM_CL_AddPolygonsToMeshQueue (prvm_prog_t *prog)
        for (i = 0;i < polys->num_triangles;i++)
        {
                VectorMAMAM(1.0f / 3.0f, polys->data_vertex3f + 3*polys->data_triangles[i].elements[0], 1.0f / 3.0f, polys->data_vertex3f + 3*polys->data_triangles[i].elements[1], 1.0f / 3.0f, polys->data_vertex3f + 3*polys->data_triangles[i].elements[2], center);
-               R_MeshQueue_AddTransparent(MESHQUEUE_SORT_DISTANCE, center, VM_DrawPolygonCallback, (entity_render_t *)polys, i, NULL);
+               R_MeshQueue_AddTransparent(TRANSPARENTSORT_DISTANCE, center, VM_DrawPolygonCallback, (entity_render_t *)polys, i, NULL);
        }
 
        /*polys->num_triangles = 0; // now done after rendering the scene,
@@ -3966,7 +3970,7 @@ static void VM_CL_skel_build(prvm_prog_t *prog)
        int blendindex;
        framegroupblend_t framegroupblend[MAX_FRAMEGROUPBLENDS];
        frameblend_t frameblend[MAX_FRAMEBLENDS];
-       matrix4x4_t blendedmatrix;
+       matrix4x4_t bonematrix;
        matrix4x4_t matrix;
        PRVM_G_FLOAT(OFS_RETURN) = 0;
        if (skeletonindex < 0 || skeletonindex >= MAX_EDICTS || !(skeleton = prog->skeletons[skeletonindex]))
@@ -3978,17 +3982,18 @@ static void VM_CL_skel_build(prvm_prog_t *prog)
        VM_FrameBlendFromFrameGroupBlend(frameblend, framegroupblend, model, cl.time);
        blendfrac = 1.0f - retainfrac;
        for (numblends = 0;numblends < MAX_FRAMEBLENDS && frameblend[numblends].lerp;numblends++)
-               frameblend[numblends].lerp *= blendfrac;
+               ;
        for (bonenum = firstbone;bonenum <= lastbone;bonenum++)
        {
-               memset(&blendedmatrix, 0, sizeof(blendedmatrix));
-               Matrix4x4_Accumulate(&blendedmatrix, &skeleton->relativetransforms[bonenum], retainfrac);
+               memset(&bonematrix, 0, sizeof(bonematrix));
                for (blendindex = 0;blendindex < numblends;blendindex++)
                {
                        Matrix4x4_FromBonePose7s(&matrix, model->num_posescale, model->data_poses7s + 7 * (frameblend[blendindex].subframe * model->num_bones + bonenum));
-                       Matrix4x4_Accumulate(&blendedmatrix, &matrix, frameblend[blendindex].lerp);
+                       Matrix4x4_Accumulate(&bonematrix, &matrix, frameblend[blendindex].lerp);
                }
-               skeleton->relativetransforms[bonenum] = blendedmatrix;
+               Matrix4x4_Normalize3(&bonematrix, &bonematrix);
+               Matrix4x4_Scale(&skeleton->relativetransforms[bonenum], retainfrac, retainfrac);
+               Matrix4x4_Accumulate(&skeleton->relativetransforms[bonenum], &bonematrix, blendfrac);
        }
        PRVM_G_FLOAT(OFS_RETURN) = skeletonindex + 1;
 }