void Test5::SetupMeshes() { mesh1 = GetGreng().GetMeshManager().CreateMeshCube(); mesh2 = GetGreng().GetMeshManager().CreateMeshQuad(); mesh3 = GetGreng().GetMeshManager().CreateMeshFromObjFile( "assets/mt.obj"); mesh4 = GetGreng().GetMeshManager().CreateMeshFromObjFile( "assets/RB-BumbleBee.obj"); GetGreng().GetMeshManager().ComputeNormals(mesh3); GetGreng().GetMeshManager().ComputeTangentSpace(mesh3); GetGreng().GetMeshManager().ComputeNormals(mesh4); Matrix4f s; MatrixScale(s, Vec3f(0.1)); Matrix4f rx; MatrixRotationX(rx, -M_PI / 2.0); Matrix4f ry; MatrixRotationY(ry, -M_PI / 2.0); Matrix4f rxy; MatrixMultiply(ry, rx, rxy); MatrixMultiply(rxy, s, mesh3ConstMatrix); }
void MeshEntity::RenderBare(BOOL bUseTransform) { traceInFast(MeshEntity::RenderBare); if(!mesh) return; if(bUseTransform) { MatrixPush(); MatrixMultiply(invTransform); if(bHasScale) MatrixScale(scale); } LoadVertexBuffer(VertBuffer); LoadIndexBuffer(mesh->IdxBuffer); GS->DrawBare(GS_TRIANGLES, 0, 0, mesh->nFaces*3); LoadVertexBuffer(NULL); LoadIndexBuffer(NULL); if(bUseTransform) MatrixPop(); traceOutFast; }
void Scale(double d, SparseMatrix& a) { for (int lQ = 0; lQ < a.nrows(); ++lQ) for (int rQ = 0; rQ < a.ncols(); ++rQ) if (a.allowed(lQ, rQ)) MatrixScale(d, a.operator_element(lQ, rQ)); }
void MeshEntity::QuickRender() { traceInFast(MeshEntity::QuickRender); if(!mesh) return; if(GetActiveEffect()) LoadEffectData(); else { MatrixPush(); MatrixMultiply(invTransform); if(bHasScale) MatrixScale(scale); } LoadVertexBuffer(VertBuffer); LoadIndexBuffer(mesh->IdxBuffer); for(DWORD i=0;i<mesh->nSections;i++) { DrawSection §ion = mesh->SectionList[i]; Material *material = MaterialList[i]; if(!material) continue; if(material->effect == GetActiveEffect()) material->LoadParameters(); if(material->flags & MATERIAL_TWOSIDED) { GSCullMode cullMode; cullMode = GetCullMode(); SetCullMode(GS_NEITHER); GS->Draw(GS_TRIANGLES, 0, section.startFace*3, section.numFaces*3); SetCullMode(cullMode); } else GS->Draw(GS_TRIANGLES, 0, section.startFace*3, section.numFaces*3); } if(GetActiveEffect()) ResetEffectData(); else MatrixPop(); traceOutFast; }
void BoxBrowser::SetZoomMatrix() { MATRIX mtxScale = MatrixScale( zScale, zScale, zScale ); MATRIX matrixX = MatrixRotationX( FROM_ANGLE( zRotX ) ); MATRIX matrixZ = MatrixRotationZ( FROM_ANGLE( zRotZ ) ); // rotate and translate MATRIX mx = MatrixRotationY( FROM_ANGLE( zRotY ) ); //rotate mx = MatrixMultiply( mx, matrixX ); mx = MatrixMultiply( mx, matrixZ ); mx = MatrixMultiply( mx, mtxScale ); //scale this thing up mx = MatrixMultiply( mx, MatrixTranslation( zPosX, zPosY, zPosZ ) ); //translate into place //apply matrix tiny3d_SetMatrixModelView( &mx ); }
void BoxBrowser::CreateMatrix( float xpos, float ypos, float zpos, float xrot, float yrot, float zrot, float scale ) { MATRIX mtxScale = MatrixScale( scale, scale, scale ); MATRIX matrixX = MatrixRotationX( FROM_ANGLE( xrot ) ); MATRIX matrixZ = MatrixRotationZ( FROM_ANGLE( zrot ) ); // rotate and translate MATRIX mx = MatrixRotationY( FROM_ANGLE( yrot ) ); //rotate mx = MatrixMultiply( mx, matrixX ); mx = MatrixMultiply( mx, matrixZ ); mx = MatrixMultiply( mx, mtxScale ); //scale this thing up mx = MatrixMultiply( mx, MatrixTranslation( xpos, ypos, zpos ) ); //translate into place //put this matrix in the list mtxBox.push_back( mx ); }
void KGEDevice::transformVertexes() { _mat = MatrixScale(0.02, 0.02, 0.02)*MatrixTranslate(Vector4(0, -20, 0, 0))*MatrixRotation(Vector4(1, 0, 0, 0), -90 * M_PI / 180); int vertexCount = (int)_transformMesh->positionList.size(); for (int i = 0; i < vertexCount; ++i) { KGEVertex v = _transformMesh->GetVertex(i); KGEVertex tranformedV = VertexShaderProgram(_mat, _camera, _light, _transformMesh->materialList[v.materialID], v); _transformMesh->SetVertex(i, tranformedV); } vertexCount = _transformMesh->positionList.size(); for (int i = 0; i < vertexCount; ++i) { _transformMesh->positionList[i].persDiv(); _transformMesh->positionList[i] = _viewportMat * _transformMesh->positionList[i]; } }
void Model::ComputeLinearDeformation( KFbxMesh *mesh, KTime &time, KFbxVector4 *vertices, KFbxPose *pose ) { KFbxCluster::ELinkMode cluster_mode = ((KFbxSkin*)mesh->GetDeformer(0, KFbxDeformer::eSKIN))->GetCluster(0)->GetLinkMode(); int cp_count = mesh->GetControlPointsCount(); KFbxXMatrix *cluster_deformations = new KFbxXMatrix[cp_count]; memset( cluster_deformations, 0, cp_count * sizeof( KFbxXMatrix ) ); double *cluster_weights = new double[cp_count]; memset( cluster_weights, 0, cp_count * sizeof( double ) ); if( cluster_mode == KFbxCluster::eADDITIVE ) { for( int i = 0;i < cp_count; i++ ) { cluster_deformations[i].SetIdentity(); } } int skin_count = mesh->GetDeformerCount(KFbxDeformer::eSKIN); for( int skin_index = 0; skin_index < skin_count; skin_index++ ) { KFbxSkin *skin_deformer = (KFbxSkin*)mesh->GetDeformer(skin_index,KFbxDeformer::eSKIN); int cluster_count = skin_deformer->GetClusterCount(); for( int cluster_index = 0; cluster_index < cluster_count; cluster_index++ ) { KFbxCluster *cluster = skin_deformer->GetCluster(cluster_index); if( !cluster->GetLink() ) continue; KFbxXMatrix vertex_transform_matrix; ComputeClusterDeformation( mesh, cluster, vertex_transform_matrix, time, pose ); int vertex_index_count = cluster->GetControlPointIndicesCount(); for( int k = 0; k < vertex_index_count; k++ ) { int index = cluster->GetControlPointIndices()[k]; if( index >= cp_count ) continue; double weight = cluster->GetControlPointWeights()[k]; if( weight == 0.0 ) continue; KFbxXMatrix influence = vertex_transform_matrix; MatrixScale( influence, weight ); if( cluster_mode == KFbxCluster::eADDITIVE ) { MatrixAddToDiagonal( influence, 1.0 - weight ); cluster_deformations[index] = influence * cluster_deformations[index]; cluster_weights[index] = 1.0; } else { // linkmode == normalize or total1 MatrixAdd( cluster_deformations[index], influence ); cluster_weights[index] += weight; } } } } // actual deformation for( int i = 0; i < cp_count; i++ ) { KFbxVector4 source_vertex = vertices[i]; KFbxVector4 &dest_vertex = vertices[i]; double weight = cluster_weights[i]; if( weight != 0.0 ) { dest_vertex = cluster_deformations[i].MultT( source_vertex ); if( cluster_mode == KFbxCluster::eNORMALIZE ) { dest_vertex /= weight; } else if( cluster_mode == KFbxCluster::eTOTAL1 ) { source_vertex *= (1.0 - weight); dest_vertex += source_vertex; } } } delete[] cluster_deformations; delete[] cluster_weights; }
void Wiimote::GetIRData(u8* const data, bool use_accel) { u16 x[4], y[4]; memset(x, 0xFF, sizeof(x)); ControlState xx = 10000, yy = 0, zz = 0; double nsin, ncos; if (use_accel) { double ax, az, len; ax = m_accel.x; az = m_accel.z; len = sqrt(ax * ax + az * az); if (len) { ax /= len; az /= len; // normalizing the vector nsin = ax; ncos = az; } else { nsin = 0; ncos = 1; } } else { // TODO m_tilt stuff nsin = 0; ncos = 1; } LowPassFilter(ir_sin, nsin, 1.0 / 60); LowPassFilter(ir_cos, ncos, 1.0 / 60); m_ir->GetState(&xx, &yy, &zz, true); Vertex v[4]; static const int camWidth = 1024; static const int camHeight = 768; static const double bndup = -0.315447; static const double bnddown = 0.85; static const double bndleft = 0.443364; static const double bndright = -0.443364; static const double dist1 = 100.0 / camWidth; // this seems the optimal distance for zelda static const double dist2 = 1.2 * dist1; for (auto& vtx : v) { vtx.x = xx * (bndright - bndleft) / 2 + (bndleft + bndright) / 2; if (m_sensor_bar_on_top) vtx.y = yy * (bndup - bnddown) / 2 + (bndup + bnddown) / 2; else vtx.y = yy * (bndup - bnddown) / 2 - (bndup + bnddown) / 2; vtx.z = 0; } v[0].x -= (zz * 0.5 + 1) * dist1; v[1].x += (zz * 0.5 + 1) * dist1; v[2].x -= (zz * 0.5 + 1) * dist2; v[3].x += (zz * 0.5 + 1) * dist2; #define printmatrix(m) \ PanicAlert("%f %f %f %f\n%f %f %f %f\n%f %f %f %f\n%f %f %f %f\n", m[0][0], m[0][1], m[0][2], \ m[0][3], m[1][0], m[1][1], m[1][2], m[1][3], m[2][0], m[2][1], m[2][2], m[2][3], \ m[3][0], m[3][1], m[3][2], m[3][3]) Matrix rot, tot; static Matrix scale; MatrixScale(scale, 1, camWidth / camHeight, 1); MatrixRotationByZ(rot, ir_sin, ir_cos); MatrixMultiply(tot, scale, rot); for (int i = 0; i < 4; i++) { MatrixTransformVertex(tot, v[i]); if ((v[i].x < -1) || (v[i].x > 1) || (v[i].y < -1) || (v[i].y > 1)) continue; x[i] = (u16)lround((v[i].x + 1) / 2 * (camWidth - 1)); y[i] = (u16)lround((v[i].y + 1) / 2 * (camHeight - 1)); } // Fill report with valid data when full handshake was done if (m_reg_ir.data[0x30]) // ir mode switch (m_reg_ir.mode) { // basic case 1: { memset(data, 0xFF, 10); wm_ir_basic* const irdata = reinterpret_cast<wm_ir_basic*>(data); for (unsigned int i = 0; i < 2; ++i) { if (x[i * 2] < 1024 && y[i * 2] < 768) { irdata[i].x1 = static_cast<u8>(x[i * 2]); irdata[i].x1hi = x[i * 2] >> 8; irdata[i].y1 = static_cast<u8>(y[i * 2]); irdata[i].y1hi = y[i * 2] >> 8; } if (x[i * 2 + 1] < 1024 && y[i * 2 + 1] < 768) { irdata[i].x2 = static_cast<u8>(x[i * 2 + 1]); irdata[i].x2hi = x[i * 2 + 1] >> 8; irdata[i].y2 = static_cast<u8>(y[i * 2 + 1]); irdata[i].y2hi = y[i * 2 + 1] >> 8; } } }
void RotationManipulator::RenderScaled(const Vect &cameraDir, float scale) { traceInFast(RotationManipulator::RenderScaled); DWORD i; Shader *rotManipShader = GetVertexShader(TEXT("Editor:RotationManipulator.vShader")); LoadVertexShader(rotManipShader); LoadPixelShader(GetPixelShader(TEXT("Base:SolidColor.pShader"))); rotManipShader->SetVector(rotManipShader->GetParameter(2), cameraDir); MatrixPush(); MatrixTranslate(GetWorldPos()); MatrixScale(scale, scale, scale); for(i=0; i<3; i++) { Vect axisColor(0.0f, 0.0f, 0.0f); axisColor.ptr[i] = 1.0f; if(i == activeAxis) axisColor.Set(1.0f, 1.0f, 0.0f); else axisColor.ptr[i] = 1.0f; rotManipShader->SetVector(rotManipShader->GetParameter(1), axisColor); LoadVertexBuffer(axisBuffers[i]); LoadIndexBuffer(NULL); Draw(GS_LINESTRIP); } LoadVertexBuffer(NULL); //---------------------------------------------------- Shader *solidShader = GetVertexShader(TEXT("Base:SolidColor.vShader")); LoadVertexShader(solidShader); MatrixPush(); MatrixRotate(Quat().SetLookDirection(cameraDir)); LoadVertexBuffer(axisBuffers[2]); LoadIndexBuffer(NULL); solidShader->SetColor(solidShader->GetParameter(1), 0.5, 0.5, 0.5, 0.5); Draw(GS_LINESTRIP); MatrixScale(1.25f, 1.25f, 1.25f); //--------------- if(activeAxis == 4) solidShader->SetColor(solidShader->GetParameter(1), 1.0f, 1.0f, 0.0, 1.0f); else solidShader->SetColor(solidShader->GetParameter(1), 0.8, 0.8, 0.8, 0.8); Draw(GS_LINESTRIP); MatrixPop(); MatrixPop(); LoadVertexShader(NULL); LoadPixelShader(NULL); traceOutFast; }
void Wiimote::GetIRData(u8* const data, bool use_accel) { const bool has_focus = HAS_FOCUS; u16 x[4], y[4]; memset(x, 0xFF, sizeof(x)); if (has_focus) { float xx = 10000, yy = 0, zz = 0; double nsin,ncos; if (use_accel) { double ax,az,len; ax=m_accel.x; az=m_accel.z; len=sqrt(ax*ax+az*az); if (len) { ax/=len; az/=len; //normalizing the vector nsin=ax; ncos=az; } else { nsin=0; ncos=1; } // PanicAlert("%d %d %d\nx:%f\nz:%f\nsin:%f\ncos:%f",accel->x,accel->y,accel->z,ax,az,sin,cos); //PanicAlert("%d %d %d\n%d %d %d\n%d %d %d",accel->x,accel->y,accel->z,calib->zero_g.x,calib->zero_g.y,calib->zero_g.z, // calib->one_g.x,calib->one_g.y,calib->one_g.z); } else { nsin=0; //m_tilt stuff here (can't figure it out yet....) ncos=1; } LowPassFilter(ir_sin,nsin,1.0f/60); LowPassFilter(ir_cos,ncos,1.0f/60); m_ir->GetState(&xx, &yy, &zz, true); UDPTLayer::GetIR(m_udp, &xx, &yy, &zz); Vertex v[4]; static const int camWidth=1024; static const int camHeight=768; static const double bndup=-0.315447; static const double bnddown=0.85; static const double bndleft=0.443364; static const double bndright=-0.443364; static const double dist1=100.f/camWidth; //this seems the optimal distance for zelda static const double dist2=1.2f*dist1; for (auto& vtx : v) { vtx.x=xx*(bndright-bndleft)/2+(bndleft+bndright)/2; if (m_sensor_bar_on_top) vtx.y=yy*(bndup-bnddown)/2+(bndup+bnddown)/2; else vtx.y=yy*(bndup-bnddown)/2-(bndup+bnddown)/2; vtx.z=0; } v[0].x-=(zz*0.5+1)*dist1; v[1].x+=(zz*0.5+1)*dist1; v[2].x-=(zz*0.5+1)*dist2; v[3].x+=(zz*0.5+1)*dist2; #define printmatrix(m) PanicAlert("%f %f %f %f\n%f %f %f %f\n%f %f %f %f\n%f %f %f %f\n",m[0][0],m[0][1],m[0][2],m[0][3],m[1][0],m[1][1],m[1][2],m[1][3],m[2][0],m[2][1],m[2][2],m[2][3],m[3][0],m[3][1],m[3][2],m[3][3]) Matrix rot,tot; static Matrix scale; static bool isscale=false; if (!isscale) { MatrixScale(scale,1,camWidth/camHeight,1); //MatrixIdentity(scale); } MatrixRotationByZ(rot,ir_sin,ir_cos); //MatrixIdentity(rot); MatrixMultiply(tot,scale,rot); for (int i=0; i<4; i++) { MatrixTransformVertex(tot,v[i]); if ((v[i].x<-1)||(v[i].x>1)||(v[i].y<-1)||(v[i].y>1)) continue; x[i]=(u16)round((v[i].x+1)/2*(camWidth-1)); y[i]=(u16)round((v[i].y+1)/2*(camHeight-1)); } // PanicAlert("%f %f\n%f %f\n%f %f\n%f %f\n%d %d\n%d %d\n%d %d\n%d %d", // v[0].x,v[0].y,v[1].x,v[1].y,v[2].x,v[2].y,v[3].x,v[3].y, // x[0],y[0],x[1],y[1],x[2],y[2],x[3],y[38]); } // Fill report with valid data when full handshake was done if (m_reg_ir.data[0x30]) // ir mode switch (m_reg_ir.mode) { // basic case 1 : { memset(data, 0xFF, 10); wm_ir_basic* const irdata = (wm_ir_basic*)data; for (unsigned int i=0; i<2; ++i) { if (x[i*2] < 1024 && y[i*2] < 768) { irdata[i].x1 = u8(x[i*2]); irdata[i].x1hi = x[i*2] >> 8; irdata[i].y1 = u8(y[i*2]); irdata[i].y1hi = y[i*2] >> 8; } if (x[i*2+1] < 1024 && y[i*2+1] < 768) { irdata[i].x2 = u8(x[i*2+1]); irdata[i].x2hi = x[i*2+1] >> 8; irdata[i].y2 = u8(y[i*2+1]); irdata[i].y2hi = y[i*2+1] >> 8; } } }
int main(int argc, char *argv[]) { ModularContext mctx; Module *master; Module *output; int timer; srand(0); mctx.rate = SAMPLE_RATE; ModularInitialize(&mctx); master = ModularMaster(&mctx); output = ModularOutput(&mctx); Module *osc = NewModule(&mctx, &ModOscillator); Module *env = NewModule(&mctx, &ModADSR); OscillatorGet(osc)->waveform = OscBandlimitedSaw; *ADSRGet(env)->A = 0.006; *ADSRGet(env)->D = 0.700; *ADSRGet(env)->S = 0.000; *ADSRGet(env)->R = 0.100; *ADSRGet(env)->trig = 0.0; OscillatorGet(osc)->gain = env->out; AddDependency(&mctx, osc, env); Module *filt = NewModule(&mctx, &ModFilter); FilterSetInput(&mctx, filt, osc); Module *env2filt = NewModule(&mctx, &ModMatrix); MatrixSetInput(&mctx, env2filt, env); MatrixScale(env2filt, 0.0, 1.0, 10.0, 10000.0); FilterGet(filt)->cutoff = env2filt->out; AddDependency(&mctx, filt, env2filt); Module *env2reso = NewModule(&mctx, &ModMatrix); MatrixSetInput(&mctx, env2reso, env); MatrixScale(env2reso, 0.0, 1.0, 0.1, 2.0); FilterGet(filt)->reso = env2reso->out; AddDependency(&mctx, filt, env2reso); MixerSlot *slot = MixerAddSlot(&mctx, master, filt, 0.3, 0.0); KeyController *kc = NewMonoSynth(); OscillatorGet(osc)->freq = MonoSynthGet(kc)->freq; ADSRGet(env)->trig = MonoSynthGet(kc)->trig; Module *bassosc = NewModule(&mctx, &ModOscillator); Module *bassenv = NewModule(&mctx, &ModADSR); OscillatorGet(bassosc)->waveform = OscBandlimitedSaw; *ADSRGet(bassenv)->A = 0.006; *ADSRGet(bassenv)->D = 0.200; *ADSRGet(bassenv)->S = 0.000; *ADSRGet(bassenv)->R = 0.100; *ADSRGet(bassenv)->trig = 0.0; //OscillatorGet(bassosc)->gain = bassenv->out; AddDependency(&mctx, bassosc, bassenv); Module *bassfilt = NewModule(&mctx, &ModFilter); FilterSetInput(&mctx, bassfilt, bassosc); Module *bassenv2filt = NewModule(&mctx, &ModMatrix); MatrixSetInput(&mctx, bassenv2filt, bassenv); MatrixScale(bassenv2filt, 0.0, 1.0, 50.0, 5000.0); FilterGet(bassfilt)->cutoff = bassenv2filt->out; AddDependency(&mctx, bassfilt, bassenv2filt); *FilterGet(bassfilt)->reso = 0.4; MixerSlot *bassslot = MixerAddSlot(&mctx, master, bassfilt, 0.3, 0.0); KeyController *bkc = NewMonoSynth(); OscillatorGet(bassosc)->freq = MonoSynthGet(bkc)->freq; ADSRGet(bassenv)->trig = MonoSynthGet(bkc)->trig; for (timer=0; ; timer++) { ModularStep(&mctx); if (timer % 96000 == 84000) seq = seqs[((timer / 96000) % 2)]; if (timer % 12000 == 0) KeyControllerKeyDown(kc, seq[(timer / 12000) % 4] - 12, 64); if (timer % 24000 == 22000) KeyControllerKeyUp(kc, seq[(timer / 12000) % 4] - 12); KeyControllerUpdate(kc); if (timer % 12000 == 0) KeyControllerKeyDown(bkc, bass[(timer / 12000) % 16], 64); if (timer % 12000 == 11000) KeyControllerKeyUp(bkc, bass[(timer / 12000) % 16]); KeyControllerUpdate(bkc); put_frame(output->out[0] * OUTPUT_SCALE, output->out[1] * OUTPUT_SCALE); } return 0; }
void SpinAdapted::MatrixNormalise(Matrix& a) { double norm = MatrixDotProduct(a, a); MatrixScale(1./sqrt(norm), a); }
// Deform the vertex array in classic linear way. void ofxFBXMesh::computeLinearDeformation(FbxAMatrix& pGlobalPosition, FbxMesh* pMesh, FbxTime& pTime, FbxVector4* pVertexArray, FbxPose* pPose ) { // All the links must have the same link mode. FbxCluster::ELinkMode lClusterMode = ((FbxSkin*)fbxMesh->GetDeformer(0, FbxDeformer::eSkin))->GetCluster(0)->GetLinkMode(); int lVertexCount = pMesh->GetControlPointsCount(); // cout << "control points count = " << lVertexCount << " mesh verts = " << mesh.getNumVertices() << endl; FbxAMatrix* lClusterDeformation = new FbxAMatrix[lVertexCount]; memset(lClusterDeformation, 0, lVertexCount * sizeof(FbxAMatrix)); double* lClusterWeight = new double[lVertexCount]; memset(lClusterWeight, 0, lVertexCount * sizeof(double)); if (lClusterMode == FbxCluster::eAdditive) { for (int i = 0; i < lVertexCount; ++i) { lClusterDeformation[i].SetIdentity(); } } // For all skins and all clusters, accumulate their deformation and weight // on each vertices and store them in lClusterDeformation and lClusterWeight. int lSkinCount = pMesh->GetDeformerCount(FbxDeformer::eSkin); // cout << "computeLinearDeformation :: number of skins = " << lSkinCount << endl; for ( int lSkinIndex=0; lSkinIndex<lSkinCount; ++lSkinIndex) { FbxSkin * lSkinDeformer = (FbxSkin *)pMesh->GetDeformer(lSkinIndex, FbxDeformer::eSkin); int lClusterCount = lSkinDeformer->GetClusterCount(); for ( int lClusterIndex=0; lClusterIndex<lClusterCount; ++lClusterIndex) { FbxCluster* lCluster = lSkinDeformer->GetCluster(lClusterIndex); if (!lCluster->GetLink()) continue; FbxAMatrix lVertexTransformMatrix; computeClusterDeformation(pGlobalPosition, pMesh, lCluster, lVertexTransformMatrix, pTime, pPose); int lVertexIndexCount = lCluster->GetControlPointIndicesCount(); for (int k = 0; k < lVertexIndexCount; ++k) { int lIndex = lCluster->GetControlPointIndices()[k]; // Sometimes, the mesh can have less points than at the time of the skinning // because a smooth operator was active when skinning but has been deactivated during export. if (lIndex >= lVertexCount) continue; double lWeight = lCluster->GetControlPointWeights()[k]; if (lWeight == 0.0) { continue; } // Compute the influence of the link on the vertex. FbxAMatrix lInfluence = lVertexTransformMatrix; MatrixScale(lInfluence, lWeight); if (lClusterMode == FbxCluster::eAdditive) { // cout << "computeLinearDeformation :: clustermode = eAdditive" << endl; // Multiply with the product of the deformations on the vertex. MatrixAddToDiagonal(lInfluence, 1.0 - lWeight); lClusterDeformation[lIndex] = lInfluence * lClusterDeformation[lIndex]; // Set the link to 1.0 just to know this vertex is influenced by a link. lClusterWeight[lIndex] = 1.0; } else // lLinkMode == FbxCluster::eNormalize || lLinkMode == FbxCluster::eTotalOne { // if(k == 0) cout << "computeLinearDeformation :: clustermode != eAdditive" << endl; // Add to the sum of the deformations on the vertex. MatrixAdd(lClusterDeformation[lIndex], lInfluence); // Add to the sum of weights to either normalize or complete the vertex. lClusterWeight[lIndex] += lWeight; } }//For each vertex }//lClusterCount } //Actually deform each vertices here by information stored in lClusterDeformation and lClusterWeight for (int i = 0; i < lVertexCount; i++) { FbxVector4 lSrcVertex = pVertexArray[i]; FbxVector4& lDstVertex = pVertexArray[i]; double lWeight = lClusterWeight[i]; // Deform the vertex if there was at least a link with an influence on the vertex, if (lWeight != 0.0) { lDstVertex = lClusterDeformation[i].MultT(lSrcVertex); if (lClusterMode == FbxCluster::eNormalize) { // In the normalized link mode, a vertex is always totally influenced by the links. lDstVertex /= lWeight; } else if (lClusterMode == FbxCluster::eTotalOne) { // In the total 1 link mode, a vertex can be partially influenced by the links. lSrcVertex *= (1.0 - lWeight); lDstVertex += lSrcVertex; } } } delete [] lClusterDeformation; delete [] lClusterWeight; }
void Test5::Render() { Test3::Render(); if (mesh1 != nullptr) { Matrix4f r; MatrixRotationZ(r, angle); Matrix4f s; MatrixScale(s, Vec3f(10)); Matrix4f rot; MatrixMultiply(r, s, rot); Matrix4f transl; MatrixTranslation(transl, Vec3f(-100, 30, 0)); Matrix4f model; MatrixMultiply(transl, rot, model); Matrix4f model_view; MatrixMultiply(GetCamera().GetViewMatrix(), model, model_view); auto program = shaderProgram ? shaderProgram : shaderProgram2; GetGreng().GetRenderer().RenderMesh( mesh1, 0, &tex6, 1, program, &model, nullptr, &model_view, &GetCamera().GetProjectionMatrix().getValue(), &light1, {}, {}, frameBuffer); } if (mesh2 != nullptr) { Matrix4f r; MatrixRotationZ(r, -angle); Matrix4f s; MatrixScale(s, Vec3f(10)); Matrix4f rot; MatrixMultiply(r, s, rot); Matrix4f transl; MatrixTranslation(transl, Vec3f(100, 30, 0)); Matrix4f model; MatrixMultiply(transl, rot, model); Matrix4f model_view; MatrixMultiply(GetCamera().GetViewMatrix(), model, model_view); auto program = shaderProgram ? shaderProgram : shaderProgram2; GetGreng().GetRenderer().RenderMesh( mesh2, 0, &tex2, 1, program, &model, nullptr, &model_view, &GetCamera().GetProjectionMatrix().getValue(), &light1, {}, {}, frameBuffer); } if (mesh3 != nullptr) { Matrix4f rangle; MatrixRotationY(rangle, 0); Matrix4f model; MatrixMultiply(rangle, mesh3ConstMatrix, model); Matrix4f model_view; MatrixMultiply(GetCamera().GetViewMatrix(), model, model_view); greng::Texture* texts[6] = { tex4, tex4normal, tex3, tex3normal, tex5, tex5normal }; auto program = shaderProgram ? shaderProgram : shaderProgram4; for (unsigned int i = 0; i < 3; i++) { GetGreng().GetRenderer().RenderMesh( mesh3, i, &texts[i * 2], 2, program, &model, nullptr, &model_view, &GetCamera().GetProjectionMatrix().getValue(), &light1, nullptr, &GetCamera().GetPos().Get(), frameBuffer); } } if (mesh4 != nullptr) { Matrix4f rangle; MatrixRotationY(rangle, 0); Matrix4f model_1; MatrixMultiply(rangle, mesh3ConstMatrix, model_1); Matrix4f trans; MatrixTranslation(trans, Vec3f(-150, 0, 0)); Matrix4f model; MatrixMultiply(trans, model_1, model); Matrix4f model_view; MatrixMultiply(GetCamera().GetViewMatrix(), model, model_view); greng::Texture* texts[6] = { tex7, tex7normal, tex7, tex7normal, tex7, tex7normal, }; auto program = shaderProgram ? shaderProgram : shaderProgram4; for (unsigned int i = 0; i < 3; i++) { GetGreng().GetRenderer().RenderMesh( mesh4, i, &texts[i * 2], 2, program, &model, nullptr, &model_view, &GetCamera().GetProjectionMatrix().getValue(), &light1, nullptr, &GetCamera().GetPos().Get(), frameBuffer); } } GetGreng().GetRenderer().DrawPoint(GetCamera(), light1.position, 10, Color4f(1, 1, 1, 1), false); }