void CTextureTransformProxy::OnBind( void *pC_BaseEntity ) { Vector2D center( 0.5, 0.5 ); Vector2D translation( 0, 0 ); VMatrix mat, temp; if (m_pCenterVar) { m_pCenterVar->GetVecValue( center.Base(), 2 ); } MatrixBuildTranslation( mat, -center.x, -center.y, 0.0f ); if (m_pScaleVar) { Vector2D scale; m_pScaleVar->GetVecValue( scale.Base(), 2 ); MatrixBuildScale( temp, scale.x, scale.y, 1.0f ); MatrixMultiply( temp, mat, mat ); } if (m_pRotateVar) { float angle = m_pRotateVar->GetFloatValue( ); MatrixBuildRotateZ( temp, angle ); MatrixMultiply( temp, mat, mat ); } MatrixBuildTranslation( temp, center.x, center.y, 0.0f ); MatrixMultiply( temp, mat, mat ); if (m_pTranslateVar) { m_pTranslateVar->GetVecValue( translation.Base(), 2 ); MatrixBuildTranslation( temp, translation.x, translation.y, 0.0f ); MatrixMultiply( temp, mat, mat ); } m_pResult->SetMatrixValue( mat ); if ( ToolsEnabled() ) { ToolFramework_RecordMaterialParams( GetMaterial() ); } }
/* ====================== UI_PositionRotatedEntityOnTag ====================== */ static void UI_PositionRotatedEntityOnTag( refEntity_t *entity, const refEntity_t *parent, clipHandle_t parentModel, char *tagName ) { int i; orientation_t lerped; vec3_t tempAxis[3]; // lerp the tag trap_CM_LerpTag( &lerped, parent, tagName, 0 ); // FIXME: allow origin offsets along tag? VectorCopy( parent->origin, entity->origin ); for ( i = 0 ; i < 3 ; i++ ) { VectorMA( entity->origin, lerped.origin[i], parent->axis[i], entity->origin ); } // cast away const because of compiler problems MatrixMultiply( entity->axis, ( (refEntity_t *)parent )->axis, tempAxis ); MatrixMultiply( lerped.axis, tempAxis, entity->axis ); }
//----------------------------------------------------------------------------------- void Matrix4x4::MatrixInvertOrthogonal(Matrix4x4* matrix) { Vector3 translation = MatrixGetOffset(matrix); MatrixTranspose(matrix); MatrixSetColumn(matrix, 3, Vector4(0.0f, 0.0f, 0.0f, 1.0f)); Matrix4x4 translationMatrix; MatrixMakeTranslation(&translationMatrix, translation); MatrixInvert(&translationMatrix); MatrixMultiply(matrix, &translationMatrix, matrix); }
main( ) { Matrix A = { { 1, 2 }, { 3, 4 } }; Matrix C; MatrixMultiply( A, A, C, 2 ); printf( "%6.2f %6.2f\n%6.2f %6.2f\n", C[ 0 ][ 0 ], C[ 0 ][ 1 ], C[ 1 ][ 0 ], C[ 1 ][ 1 ] ); return 0; }
//heading으로부터 side각도로 회전 행렬 생성 void ZeroMat::Rotate(const ZeroVec & _fwd, const ZeroVec & _side) { ZeroMat::Matrix mat; mat._11 = _fwd.x; mat._12 = _fwd.y; mat._13 = 0; mat._21 = _side.x; mat._22 = _side.y; mat._23 = 0; mat._31 = 0; mat._32 = 0; mat._33 = 1; //행렬을 곱한다. MatrixMultiply(mat); }
void Bone::calculatedMatrix() { //iterate through all sibling and set the matrices Bone *curBone = this; while(curBone && curBone->sibling) { MatrixMultiply(&curBone->sibling->combinedTranformation, &curBone->combinedTranformation, &curBone->sibling->localTransform); curBone = curBone->sibling; } //iterate through all children and set the matrices curBone = this; while(curBone && curBone->child) { MatrixMultiply(&curBone->child->combinedTranformation, &curBone->combinedTranformation, &curBone->sibling->localTransform); curBone = curBone->child; } }
//크기 행렬 생성 void ZeroMat::Scale(float _xScale, float _yScale) { ZeroMat::Matrix mat; mat._11 = _xScale; mat._12 = 0; mat._13 = 0; mat._21 = 0; mat._22 = _yScale; mat._23 = 0; mat._31 = 0; mat._32 = 0; mat._33 = 1; //행렬을 곱한다. MatrixMultiply(mat); }
//----------------------------------------------------------------------------- // Loads the model * view matrix into pixel shader constants //----------------------------------------------------------------------------- void CBaseVSShader::LoadModelViewMatrixIntoVertexShaderConstant( int vertexReg ) { VMatrix view, model, modelView, transpose; s_pShaderAPI->GetMatrix( MATERIAL_MODEL, model.m[0] ); MatrixTranspose( model, model ); s_pShaderAPI->GetMatrix( MATERIAL_VIEW, view.m[0] ); MatrixTranspose( view, view ); MatrixMultiply( view, model, modelView ); s_pShaderAPI->SetVertexShaderConstant( vertexReg, modelView.m[0], 3 ); }
// 描画後処理 void CPlayer::PostDraw(void) { if (!m_pMesh) { return; } // 後ろ向きモデルのため、Y軸180度回転 MATRIX world; MatrixRotationY(&world, RAD * 180); MatrixMultiply(&world, &m_world, &world); DrawMeshAlpha(&world, m_pMesh); }
//==================== // ボーンの行列を更新 //==================== void cPMDBone::updateMatrix( void ) { // クォータニオンと移動値からボーンのローカルマトリックスを作成 QuaternionToMatrix( m_matLocal, &m_vec4Rotation ); m_matLocal[3][0] = m_vec3Position.x + m_vec3Offset.x; m_matLocal[3][1] = m_vec3Position.y + m_vec3Offset.y; m_matLocal[3][2] = m_vec3Position.z + m_vec3Offset.z; // 親があるなら親の回転を受け継ぐ if( m_pParentBone ) MatrixMultiply( m_matLocal, m_matLocal, m_pParentBone->m_matLocal ); }
void SpinAdapted::MatrixRotate (const Matrix& a, const Matrix& b, const Matrix& c, Matrix& d) { try { assert (d.Nrows () == a.Ncols () && d.Ncols () == c.Ncols ()); #ifdef BLAS Matrix work (b.Nrows (), c.Ncols ()); Clear (work); MatrixMultiply (b, 'n', c, 'n', work, 1.); MatrixMultiply (a, 't', work, 'n', d, 1.); #else d = a.t () * b * c; #endif } catch (Exception) { pout << Exception::what () << endl; abort (); } }
void ParticleData::MatrixMap(float x, float y, float z, float theta, float size, bool init, float speed){ MATRIX mov; MATRIX rot; //シェーダーのコンスタントバッファーに各種データを渡す D3D11_MAPPED_SUBRESOURCE pData; CONSTANT_BUFFER_P cb; dx->pDeviceContext->Map(pConstantBuffer, 0, D3D11_MAP_WRITE_DISCARD, 0, &pData); MatrixRotationZ(&rot, theta); MatrixTranslation(&mov, x, y, z); MatrixMultiply(&dx->World, &rot, &mov); MatrixMultiply(&cb.WV, &dx->World, &dx->View); cb.Proj = dx->Proj; MatrixTranspose(&cb.WV); MatrixTranspose(&cb.Proj); cb.size.x = size; if (init)cb.size.y = 1.0f; else cb.size.y = 0.0f; cb.size.z = speed; memcpy_s(pData.pData, pData.RowPitch, (void*)(&cb), sizeof(cb)); dx->pDeviceContext->Unmap(pConstantBuffer, 0); }
void MyMatrix::RotateZ(float angle) { float sinAngle, cosAngle; sinAngle = sinf ( angle * PI / 180.0f ); cosAngle = cosf ( angle * PI / 180.0f ); MyMatrix temp; temp.LoadIndentity(); temp.m[0][0] = temp.m[1][1] = cosAngle; temp.m[0][1] = sinAngle; temp.m[1][0] = -sinAngle; MatrixMultiply(&temp,this); }
//========================== // ボーンを指定座標へ向ける //========================== void cPMDBone::lookAt( const Vector3 *pvecTargetPos, float fLimitXD, float fLimitXU, float fLimitY ) { // どうもおかしいので要調整 Matrix matTemp; MatrixIdentity( matTemp ); matTemp[3][0] = m_vec3Position.x + m_vec3Offset.x; matTemp[3][1] = m_vec3Position.y + m_vec3Offset.y; matTemp[3][2] = m_vec3Position.z + m_vec3Offset.z; if( m_pParentBone ) { Matrix matInvTemp; MatrixInverse( matInvTemp, m_pParentBone->m_matLocal ); matInvTemp[3][0] = m_pParentBone->m_matLocal[3][0]; matInvTemp[3][1] = m_pParentBone->m_matLocal[3][1]; matInvTemp[3][2] = -m_pParentBone->m_matLocal[3][2]; MatrixMultiply( matTemp, matTemp, matInvTemp ); } MatrixInverse( matTemp, matTemp ); Vector3 vec3LocalTgtPosZY; Vector3 vec3LocalTgtPosXZ; Vector3Transform( &vec3LocalTgtPosZY, pvecTargetPos, matTemp ); vec3LocalTgtPosXZ = vec3LocalTgtPosZY; vec3LocalTgtPosXZ.y = 0.0f; Vector3Normalize( &vec3LocalTgtPosXZ, &vec3LocalTgtPosXZ ); vec3LocalTgtPosZY.x = 0.0f; Vector3Normalize( &vec3LocalTgtPosZY, &vec3LocalTgtPosZY ); Vector3 vec3Angle = { 0.0f, 0.0f, 0.0f }; vec3Angle.x = asinf( vec3LocalTgtPosZY.y ); if( vec3LocalTgtPosXZ.x < 0.0f ) vec3Angle.y = acosf( vec3LocalTgtPosXZ.z ); else vec3Angle.y = -acosf( vec3LocalTgtPosXZ.z ); if( vec3Angle.x < RAD(fLimitXD) ) vec3Angle.x = RAD(fLimitXD); if( RAD(fLimitXU) < vec3Angle.x ) vec3Angle.x = RAD(fLimitXU); if( vec3Angle.y < RAD(-fLimitY) ) vec3Angle.y = RAD(-fLimitY); if( RAD(fLimitY) < vec3Angle.y ) vec3Angle.y = RAD( fLimitY); Vector4 vec4RotTemp; QuaternionCreateEuler( &vec4RotTemp, &vec3Angle ); QuaternionSlerp( &m_vec4LookRotation, &m_vec4LookRotation, &vec4RotTemp, 0.5f ); // 0.3f ); // 視線の動きを高速化 m_vec4Rotation = m_vec4LookRotation; }
/* ============= R_SetupMatrix ============= */ void R_SetupMatrix (void) { GL_Viewport(glx + r_refdef.vrect.x, gly + glheight - r_refdef.vrect.y - r_refdef.vrect.height, r_refdef.vrect.width, r_refdef.vrect.height); // Projection matrix GL_FrustumMatrix(vulkan_globals.projection_matrix, DEG2RAD(r_fovx), DEG2RAD(r_fovy)); // View matrix float rotation_matrix[16]; RotationMatrix(vulkan_globals.view_matrix, -M_PI / 2.0f, 1.0f, 0.0f, 0.0f); RotationMatrix(rotation_matrix, M_PI / 2.0f, 0.0f, 0.0f, 1.0f); MatrixMultiply(vulkan_globals.view_matrix, rotation_matrix); RotationMatrix(rotation_matrix, DEG2RAD(-r_refdef.viewangles[2]), 1.0f, 0.0f, 0.0f); MatrixMultiply(vulkan_globals.view_matrix, rotation_matrix); RotationMatrix(rotation_matrix, DEG2RAD(-r_refdef.viewangles[0]), 0.0f, 1.0f, 0.0f); MatrixMultiply(vulkan_globals.view_matrix, rotation_matrix); RotationMatrix(rotation_matrix, DEG2RAD(-r_refdef.viewangles[1]), 0.0f, 0.0f, 1.0f); MatrixMultiply(vulkan_globals.view_matrix, rotation_matrix); float translation_matrix[16]; TranslationMatrix(translation_matrix, -r_refdef.vieworg[0], -r_refdef.vieworg[1], -r_refdef.vieworg[2]); MatrixMultiply(vulkan_globals.view_matrix, translation_matrix); // View projection matrix memcpy(vulkan_globals.view_projection_matrix, vulkan_globals.projection_matrix, 16 * sizeof(float)); MatrixMultiply(vulkan_globals.view_projection_matrix, vulkan_globals.view_matrix); vkCmdPushConstants(vulkan_globals.command_buffer, vulkan_globals.basic_pipeline_layout, VK_SHADER_STAGE_ALL_GRAPHICS, 0, 16 * sizeof(float), vulkan_globals.view_projection_matrix); }
//----------------------------------------------------------------------------- // Creates a vector material var //----------------------------------------------------------------------------- static IMaterialVar* CreateMatrixMaterialVarFromKeyValue( IMaterial* pMaterial, KeyValues* pKeyValue ) { char const* pScan = pKeyValue->GetString(); // Matrices can be specified one of two ways: // [ # # # # # # # # # # # # # # # # ] // or // center # # scale # # rotate # translate # # VMatrix mat; int count = sscanf( pScan, " [ %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f ]", &mat.m[0][0], &mat.m[0][1], &mat.m[0][2], &mat.m[0][3], &mat.m[1][0], &mat.m[1][1], &mat.m[1][2], &mat.m[1][3], &mat.m[2][0], &mat.m[2][1], &mat.m[2][2], &mat.m[2][3], &mat.m[3][0], &mat.m[3][1], &mat.m[3][2], &mat.m[3][3] ); if (count == 16) { return IMaterialVar::Create( pMaterial, pKeyValue->GetName(), mat ); } Vector2D scale, center; float angle; Vector2D translation; count = sscanf( pScan, " center %f %f scale %f %f rotate %f translate %f %f", ¢er.x, ¢er.y, &scale.x, &scale.y, &angle, &translation.x, &translation.y ); if (count != 7) return NULL; VMatrix temp; MatrixBuildTranslation( mat, -center.x, -center.y, 0.0f ); MatrixBuildScale( temp, scale.x, scale.y, 1.0f ); MatrixMultiply( temp, mat, mat ); MatrixBuildRotateZ( temp, angle ); MatrixMultiply( temp, mat, mat ); MatrixBuildTranslation( temp, center.x + translation.x, center.y + translation.y, 0.0f ); MatrixMultiply( temp, mat, mat ); // Create the variable! return IMaterialVar::Create( pMaterial, pKeyValue->GetName(), mat ); }
/* * UI_PositionRotatedEntityOnTag */ static void UI_PositionRotatedEntityOnTag(Refent *entity, const Refent *parent, Cliphandle parentModel, char *tagName) { int i; Orient lerped; Vec3 tempAxis[3]; /* lerp the tag */ trap_CM_LerpTag(&lerped, parentModel, parent->oldframe, parent->frame, 1.0 - parent->backlerp, tagName); /* FIXME: allow origin offsets along tag? */ copyv3(parent->origin, entity->origin); for(i = 0; i < 3; i++) saddv3(entity->origin, lerped.origin[i], parent->axis[i], entity->origin); /* cast away const because of compiler problems */ MatrixMultiply(entity->axis, ((Refent*)parent)->axis, tempAxis); MatrixMultiply(lerped.axis, tempAxis, entity->axis); }
/*------------------------------------------------------------ ContrastVMF() - computes the variance multiplication factor ------------------------------------------------------------*/ static double ContrastVMF(MATRIX *X, MATRIX *C) { float vmf; MATRIX *Xt, *XtX, *iXtX, *CiXtX, *Ct, *CiXtXCt; Xt = MatrixTranspose(X,NULL); XtX = MatrixMultiply(Xt,X,NULL); iXtX = MatrixInverse(XtX,NULL); CiXtX = MatrixMultiply(C,iXtX,NULL); Ct = MatrixTranspose(C,NULL); CiXtXCt = MatrixMultiply(CiXtX,Ct,NULL); vmf = CiXtXCt->rptr[1][1]; MatrixFree(&Xt); MatrixFree(&XtX); MatrixFree(&iXtX); MatrixFree(&CiXtX); MatrixFree(&Ct); MatrixFree(&CiXtXCt); return(vmf); }
//----------------------------------------------------------------------------- // Read in worldcraft data... //----------------------------------------------------------------------------- bool CVGuiScreen::KeyValue( const char *szKeyName, const char *szValue ) { //!! temp hack, until worldcraft is fixed // strip the # tokens from (duplicate) key names char *s = (char *)strchr( szKeyName, '#' ); if ( s ) { *s = '\0'; } if ( FStrEq( szKeyName, "panelname" )) { SetPanelName( szValue ); return true; } // NOTE: Have to do these separate because they set two values instead of one if( FStrEq( szKeyName, "angles" ) ) { Assert( GetMoveParent() == NULL ); QAngle angles; UTIL_StringToVector( angles.Base(), szValue ); // Because the vgui screen basis is strange (z is front, y is up, x is right) // we need to rotate the typical basis before applying it VMatrix mat, rotation, tmp; MatrixFromAngles( angles, mat ); MatrixBuildRotationAboutAxis( rotation, Vector( 0, 1, 0 ), 90 ); MatrixMultiply( mat, rotation, tmp ); MatrixBuildRotateZ( rotation, 90 ); MatrixMultiply( tmp, rotation, mat ); MatrixToAngles( mat, angles ); SetAbsAngles( angles ); return true; } return BaseClass::KeyValue( szKeyName, szValue ); }
//회전 행렬 생성 void ZeroMat::Rotate(float _rotation) { ZeroMat::Matrix mat; float sin = ZeroMathMgr->Sin(_rotation); float cos = ZeroMathMgr->Cos(_rotation); mat._11 = cos; mat._12 = sin; mat._13 = 0; mat._21 = -sin; mat._22 = cos; mat._23 = 0; mat._31 = 0; mat._32 = 0; mat._33 = 1; //행렬을 곱한다. MatrixMultiply(mat); }
void MyMatrix::Rotate(float angle, float x, float y, float z) { float sinAngle, cosAngle; float mag = sqrtf(x * x + y * y + z * z); sinAngle = sinf ( angle * PI / 180.0f ); cosAngle = cosf ( angle * PI / 180.0f ); if ( mag > 0.0f ) { float xx, yy, zz, xy, yz, zx, xs, ys, zs; float oneMinusCos; MyMatrix rotMat; x /= mag; y /= mag; z /= mag; xx = x * x; yy = y * y; zz = z * z; xy = x * y; yz = y * z; zx = z * x; xs = x * sinAngle; ys = y * sinAngle; zs = z * sinAngle; oneMinusCos = 1.0f - cosAngle; rotMat.m[0][0] = (oneMinusCos * xx) + cosAngle; rotMat.m[0][1] = (oneMinusCos * xy) - zs; rotMat.m[0][2] = (oneMinusCos * zx) + ys; rotMat.m[0][3] = 0.0F; rotMat.m[1][0] = (oneMinusCos * xy) + zs; rotMat.m[1][1] = (oneMinusCos * yy) + cosAngle; rotMat.m[1][2] = (oneMinusCos * yz) - xs; rotMat.m[1][3] = 0.0F; rotMat.m[2][0] = (oneMinusCos * zx) - ys; rotMat.m[2][1] = (oneMinusCos * yz) + xs; rotMat.m[2][2] = (oneMinusCos * zz) + cosAngle; rotMat.m[2][3] = 0.0F; rotMat.m[3][0] = 0.0F; rotMat.m[3][1] = 0.0F; rotMat.m[3][2] = 0.0F; rotMat.m[3][3] = 1.0F; MatrixMultiply( &rotMat, this); } }
//----------------------------------------------------------------------------- // Sets up the camera //----------------------------------------------------------------------------- void CRenderManager::SetupCameraRenderState( ) { CCameraProperty *pCamera = g_pWorldManager->GetLocalPlayer()->m_pCameraProperty; matrix3x4_t cameraToWorld; AngleMatrix( pCamera->m_Angles, pCamera->m_Origin, cameraToWorld ); matrix3x4_t matRotate; matrix3x4_t matRotateZ; MatrixBuildRotationAboutAxis( Vector(0,0,1), -90, matRotateZ ); MatrixMultiply( cameraToWorld, matRotateZ, matRotate ); matrix3x4_t matRotateX; MatrixBuildRotationAboutAxis( Vector(1,0,0), 90, matRotateX ); MatrixMultiply( matRotate, matRotateX, matRotate ); matrix3x4_t view; MatrixInvert( matRotate, view ); CMatRenderContextPtr pRenderContext( g_pMaterialSystem ); pRenderContext->MatrixMode( MATERIAL_VIEW ); pRenderContext->LoadMatrix( view ); }
static void draw() { static int i = 0; i++; Matrix modelview; /* clear the color buffer */ glClearColor(0.5, 0.5, 0.5, 1.0); glClear(GL_COLOR_BUFFER_BIT); MatrixLoadIdentity(&modelview); Translate(&modelview, 0.0f, 0.0f, -8.0f); Rotate(&modelview, 45.0f + (0.25f * i), 1.0f, 0.0f, 0.0f); Rotate(&modelview, 45.0f - (0.5f * i), 0.0f, 1.0f, 0.0f); Rotate(&modelview, 10.0f + (0.15f * i), 0.0f, 0.0f, 1.0f); GLfloat aspect = 512/512; Matrix projection; MatrixLoadIdentity(&projection); Frustum(&projection, -2.8f, +2.8f, -2.8f * aspect, +2.8f * aspect, 6.0f, 10.0f); Matrix modelviewprojection; MatrixLoadIdentity(&modelviewprojection); MatrixMultiply(&modelviewprojection, &modelview, &projection); float normal[9]; normal[0] = modelview.m[0][0]; normal[1] = modelview.m[0][1]; normal[2] = modelview.m[0][2]; normal[3] = modelview.m[1][0]; normal[4] = modelview.m[1][1]; normal[5] = modelview.m[1][2]; normal[6] = modelview.m[2][0]; normal[7] = modelview.m[2][1]; normal[8] = modelview.m[2][2]; glUniformMatrix4fv(modelviewmatrix, 1, GL_FALSE, &modelview.m[0][0]); glUniformMatrix4fv(modelviewprojectionmatrix, 1, GL_FALSE, &modelviewprojection.m[0][0]); glUniformMatrix3fv(normalmatrix, 1, GL_FALSE, normal); glEnableVertexAttribArray(0); glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, cubePositions); GLint texCoordLoc = glGetAttribLocation(program, "a_texCoord"); glEnableVertexAttribArray(texCoordLoc); glVertexAttribPointer(texCoordLoc, 2, GL_FLOAT, GL_FALSE, 0, cubeTexels); glDrawArrays(GL_TRIANGLES, 0, cubeVertices); }
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 draw_twat(float x, float y, float angle) { int n; float ang, angs = 6.2831853071796 / 8, angs2 = 6.2831853071796 / 32; MATRIX matrix; // rotate and translate the sprite matrix = MatrixRotationZ(angle); matrix = MatrixMultiply(matrix, MatrixTranslation(x , y , 65535.0f)); // fix ModelView Matrix tiny3d_SetMatrixModelView(&matrix); tiny3d_SetPolygon(TINY3D_TRIANGLES); ang = 0.0f; for(n = 0; n <8; n++) { tiny3d_VertexPos(4.0f *sinf(ang), 4.0f *cosf(ang), 0); tiny3d_VertexColor(0xffffff30); tiny3d_VertexPos(7.0f *sinf(ang+angs/2), 7.0f *cosf(ang+angs/2), 0); tiny3d_VertexColor(0xff00ff40); tiny3d_VertexPos(4.0f *sinf(ang+angs), 4.0f *cosf(ang+angs), 0); tiny3d_VertexColor(0xffffff30); ang += angs; } tiny3d_End(); tiny3d_SetPolygon(TINY3D_POLYGON); ang = 0.0f; for(n = 0; n <32; n++) { tiny3d_VertexPos(3.0f * sinf(ang), 3.0f * cosf(ang), 0); if(n & 1) tiny3d_VertexColor(0x80ffff40); else tiny3d_VertexColor(0xffffff40); ang += angs2; } tiny3d_End(); tiny3d_SetMatrixModelView(NULL); // set matrix identity }
MATRIX * regio_read_surfacexform_from_register_dat(char *fname, MRI_SURFACE *mris, MRI *mri, char **subject) { MATRIX *Ta, *Sa, *invT, *A, *R, *S, *invSa, *T, *m1, *m2, *B ; float pres, bres, intensity ; int float2int ; MRI *mri_surf = MRIallocHeader(mris->vg.width, mris->vg.height, mris->vg.depth, MRI_UCHAR,1) ; if (regio_read_register(fname, subject, &pres, &bres, &intensity,&B,&float2int) != 0) ErrorReturn(NULL, (ERROR_NOFILE, "regio_read_surfacexform_from_register_dat(%s) failed", fname)) ; MRIcopyVolGeomToMRI(mri_surf, &mris->vg) ; T = MRIxfmCRS2XYZtkreg(mri) ; S = MRIgetVoxelToRasXform(mri) ; Ta = MRIxfmCRS2XYZtkreg(mri_surf); Sa = MRIgetVoxelToRasXform(mri_surf); invSa = MatrixInverse(Sa, NULL) ; invT = MatrixInverse(T,NULL); A = MatrixMultiply(S,invT, NULL); m1 = MatrixMultiply(A, B, NULL) ; m2 = MatrixMultiply(invSa, m1, NULL) ; R = MatrixMultiply(Ta, m2, NULL) ; MatrixFree(&A) ; MatrixFree(&Ta) ; MatrixFree(&Sa) ; MatrixFree(&invT) ; MatrixFree(&B) ; MatrixFree(&m1) ; MatrixFree(&m2) ; MatrixFree(&S) ; MatrixFree(&invSa); MatrixFree(&T) ; MRIfree(&mri_surf) ; return(R) ; }
void COGModelSkeleton::GetWorldMatrix(OGMatrix& _mOut, unsigned int _NodeId, unsigned int _Frame) const { OGModelNode* pNode = m_Nodes[_NodeId]; if (pNode->mTransformList.size() > _Frame) _mOut = pNode->mTransformList[_Frame]; else _mOut = pNode->mTransformList[0]; if(pNode->nIdxParent < 0) return; OGMatrix mTmp; GetWorldMatrix(mTmp, pNode->nIdxParent, _Frame); MatrixMultiply(_mOut, _mOut, mTmp); }
static void draw() { static int i = 0; i++; Matrix modelview; /* clear the color buffer */ glClearColor(0.5, 0.5, 0.5, 1.0); glClear(GL_COLOR_BUFFER_BIT); MatrixLoadIdentity(&modelview); Translate(&modelview, 0.0f, 0.0f, -8.0f); Rotate(&modelview, 45.0f + (0.25f * i), 1.0f, 0.0f, 0.0f); Rotate(&modelview, 45.0f - (0.5f * i), 0.0f, 1.0f, 0.0f); Rotate(&modelview, 10.0f + (0.15f * i), 0.0f, 0.0f, 1.0f); GLfloat aspect = 512/512; Matrix projection; MatrixLoadIdentity(&projection); Frustum(&projection, -2.8f, +2.8f, -2.8f * aspect, +2.8f * aspect, 6.0f, 10.0f); Matrix modelviewprojection; MatrixLoadIdentity(&modelviewprojection); MatrixMultiply(&modelviewprojection, &modelview, &projection); float normal[9]; normal[0] = modelview.m[0][0]; normal[1] = modelview.m[0][1]; normal[2] = modelview.m[0][2]; normal[3] = modelview.m[1][0]; normal[4] = modelview.m[1][1]; normal[5] = modelview.m[1][2]; normal[6] = modelview.m[2][0]; normal[7] = modelview.m[2][1]; normal[8] = modelview.m[2][2]; glUniformMatrix4fv(modelviewmatrix, 1, GL_FALSE, &modelview.m[0][0]); glUniformMatrix4fv(modelviewprojectionmatrix, 1, GL_FALSE, &modelviewprojection.m[0][0]); glUniformMatrix3fv(normalmatrix, 1, GL_FALSE, normal); glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); glDrawArrays(GL_TRIANGLE_STRIP, 4, 4); glDrawArrays(GL_TRIANGLE_STRIP, 8, 4); glDrawArrays(GL_TRIANGLE_STRIP, 12, 4); glDrawArrays(GL_TRIANGLE_STRIP, 16, 4); glDrawArrays(GL_TRIANGLE_STRIP, 20, 4); }
static MRI * apply_bias(MRI *mri_orig, MRI *mri_norm, MRI *mri_bias) { MATRIX *m_vox2vox; VECTOR *v1, *v2; int x, y, z ; double xd, yd, zd, bias, val_orig, val_norm ; if (mri_norm == NULL) mri_norm = MRIclone(mri_orig, NULL) ; m_vox2vox = MRIgetVoxelToVoxelXform(mri_orig, mri_bias) ; v1 = VectorAlloc(4, MATRIX_REAL); v2 = VectorAlloc(4, MATRIX_REAL); VECTOR_ELT(v1, 4) = 1.0 ; VECTOR_ELT(v2, 4) = 1.0 ; for (x = 0 ; x < mri_orig->width ; x++) { V3_X(v1) = x ; for (y = 0 ; y < mri_orig->height ; y++) { V3_Y(v1) = y ; for (z = 0 ; z < mri_orig->depth ; z++) { V3_Z(v1) = z ; if (x == Gx && y == Gy && z == Gz) DiagBreak() ; val_orig = MRIgetVoxVal(mri_orig, x, y, z, 0) ; MatrixMultiply(m_vox2vox, v1, v2) ; xd = V3_X(v2) ; yd = V3_Y(v2) ; zd = V3_Z(v2); MRIsampleVolume(mri_bias, xd, yd, zd, &bias) ; val_norm = val_orig * bias ; if (mri_norm->type == MRI_UCHAR) { if (val_norm > 255) val_norm = 255 ; else if (val_norm < 0) val_norm = 0 ; } MRIsetVoxVal(mri_norm, x, y, z, 0, val_norm) ; } } } MatrixFree(&m_vox2vox) ; VectorFree(&v1) ; VectorFree(&v2) ; return(mri_norm) ; }
/* * D3DParticleAddToRenderer: Adds a particle to be rendered. */ void D3DParticleAddToRenderer(d3d_render_pool_new *pPool, Draw3DParams *params, particle_system *pParticleSystem, particle *pParticle) { d3d_render_packet_new *pPacket; d3d_render_chunk_new *pChunk; pPacket = D3DRenderPacketFindMatch(pPool, pParticleSystem->pTexture, NULL, 0, 0, 0); assert(pPacket); pPacket->pMaterialFctn = &D3DMaterialParticlePacket; pChunk = D3DRenderChunkNew(pPacket); assert(pChunk); pChunk->numIndices = pParticleSystem->numIndices; pChunk->numVertices = pParticleSystem->numVertices; pChunk->numPrimitives = pParticleSystem->numPrimitives; pChunk->pMaterialFctn = &D3DMaterialParticleChunk; MatrixTranslate(&pChunk->xForm, pParticle->pos.x, pParticle->pos.z, pParticle->pos.y); if (pParticleSystem->pTexture) { MatrixMultiply(&pChunk->xForm, &mPlayerHeadingTrans, &pChunk->xForm); for (u_int i = 0; i < pChunk->numVertices; i++) { pChunk->indices[i] = pParticleSystem->pParticleIndices[i]; pChunk->xyz[i] = pParticleSystem->pParticleXYZ[i]; pChunk->st0[i] = pParticleSystem->pParticleST[i]; pChunk->bgra[i].b = pParticle->bgra.b; pChunk->bgra[i].g = pParticle->bgra.g; pChunk->bgra[i].r = pParticle->bgra.r; pChunk->bgra[i].a = pParticle->bgra.a; } } else { CHUNK_XYZ_SET(pChunk, 0, 0, 0, 0); CHUNK_XYZ_SET(pChunk, 1, -pParticle->velocity.x, -pParticle->velocity.y, -pParticle->velocity.z); CHUNK_BGRA_SET(pChunk, 0, (pParticle->bgra.b), pParticle->bgra.g, pParticle->bgra.r, pParticle->bgra.a); CHUNK_BGRA_SET(pChunk, 1, pParticle->bgra.b, pParticle->bgra.g, pParticle->bgra.r, 0); CHUNK_INDEX_SET(pChunk, 0, 0); CHUNK_INDEX_SET(pChunk, 1, 1); } }