int PhysicsIslandUpdate (const NewtonWorld* world, const void* islandHandle, int bodyCount) { if (showIslans) { dVector minAABB ( 1.0e10f, 1.0e10f, 1.0e10f, 0.0f); dVector maxAABB (-1.0e10f, -1.0e10f, -1.0e10f, 0.0f); for (int i = 0; i < bodyCount; i ++) { dVector p0; dVector p1; #if 0 // show the engine loose aabb NewtonIslandGetBodyAABB (islandHandle, i, &p0[0], &p1[0]); #else // calculate the shape aabb dMatrix matrix; NewtonBody* body; NewtonCollision *collision; body = NewtonIslandGetBody (islandHandle, i); collision = NewtonBodyGetCollision (body); NewtonBodyGetMatrix (body, &matrix[0][0]); CalculateAABB (collision, matrix, p0, p1); #endif for (int j = 0; j < 3; j ++ ) { minAABB[j] = p0[j] < minAABB[j] ? p0[j] : minAABB[j]; maxAABB[j] = p1[j] > maxAABB[j] ? p1[j] : maxAABB[j]; } } DebugDrawAABB (minAABB, maxAABB); } // g_activeBodies += bodyCount; return 1; }
BoundingBoxClass::BoundingBoxClass(String a_sInstanceName) { m_pMeshOBB = nullptr; m_v3CentroidOBB = vector3(0.0f, 0.0f, 0.0f); m_v3ColorOBB = MEBLUE; m_m4ModelToWorldOBB = matrix4(1.0f); m_bVisibleOBB = false; m_pMeshAABB = nullptr; m_v3CentroidAABB = vector3(0.0f,0.0f,0.0f); m_v3ColorAABB = MEWHITE; m_m4ModelToWorldAABB = matrix4(1.0f); m_bVisibleAABB = false; m_pModelMngr = ModelManagerClass::GetInstance(); m_sInstance = a_sInstanceName; int nInstance = m_pModelMngr->IdentifyInstance(m_sInstance); if (nInstance == -1) return; CalculateOBB(m_sInstance); m_m4ModelToWorldOBB = m_pModelMngr->GetModelMatrix(m_sInstance); m_pMeshOBB = new PrimitiveWireClass(); m_pMeshOBB->GenerateCube(1.0f, MEBLUE); SetModelMatrixOBB(m_m4ModelToWorldOBB); CalculateAABB(m_sInstance); m_m4ModelToWorldAABB = m_pModelMngr->GetModelMatrix(m_sInstance); m_pMeshAABB = new PrimitiveWireClass(); m_pMeshAABB->GenerateCube(1.0f, MEWHITE); SetModelMatrixAABB(m_m4ModelToWorldAABB); }
void Light_Point::IncSpreadAngle(float increment) { assert(AlwaysUpdate()); m_spreadAngle += increment; CalculateAABB(); TreeUpdate(); }
void Light_Point::SetSpreadAngle(float spreadAngle) { assert(AlwaysUpdate()); m_spreadAngle = spreadAngle; CalculateAABB(); TreeUpdate(); }
void Light_Point::IncDirectionAngle(float increment) { assert(AlwaysUpdate()); m_directionAngle += increment; CalculateAABB(); TreeUpdate(); }
void Light_Point::SetDirectionAngle(float directionAngle) { assert(AlwaysUpdate()); m_directionAngle = directionAngle; CalculateAABB(); TreeUpdate(); }
void Light::IncRadius(float increment) { assert(m_alwaysUpdate); m_radius += increment; CalculateAABB(); TreeUpdate(); }
void Light::SetRadius(float radius) { assert(m_alwaysUpdate); m_radius = radius; CalculateAABB(); TreeUpdate(); }
/** * Updates the collision detection deques */ void CCharacter::UpdateAABB (void) { switch (PhysicMode) { case CHAR_INVISIBLE: //No render, touchable: collidable case CHAR_PHYSICAL: //Renderable, touchable: collidable ///Recalculates the min and max values of the absolute coordinates of the bounding box CalculateAABB(); CollisionDetector.Update(this); } }
virtual void OnRender (dFloat timestep) const { dVector p0(0.0f); dVector p1(0.0f); DemoEntity* const entity = (DemoEntity*)NewtonBodyGetUserData(m_body); const dMatrix& matrix = entity->GetRenderMatrix(); NewtonCollision* const collision = NewtonBodyGetCollision(m_body); CalculateAABB (collision, matrix, p0, p1); NewtonWorld* const world = NewtonBodyGetWorld(m_body); NewtonWorldForEachBodyInAABBDo(world, &p0[0], &p1[0], CalculateContacts, (void*)this); }
static void BuildPyramid (DemoEntityManager* const scene, dFloat mass, const dVector& origin, const dVector& size, int count, PrimitiveType type, const dMatrix& shapeMatrix = dGetIdentityMatrix()) { dMatrix matrix (dGetIdentityMatrix()); matrix.m_posit = origin; matrix.m_posit.m_w = 1.0f; // create the shape and visual mesh as a common data to be re used NewtonWorld* const world = scene->GetNewton(); int defaultMaterialID; defaultMaterialID = NewtonMaterialGetDefaultGroupID (world); //dMatrix shapeMatrix (dRollMatrix(3.141692f * 0.5f)); NewtonCollision* const collision = CreateConvexCollision (world, shapeMatrix, size, type, defaultMaterialID); DemoMesh* const geometry = new DemoMesh("cylinder_1", collision, "wood_4.tga", "wood_4.tga", "wood_1.tga"); //DemoMesh____* const geometry = new DemoMesh____("cylinder_1", collision, "smilli.tga", "smilli.tga", "smilli.tga"); // matrix = dRollMatrix(3.141592f/2.0f); dFloat startElevation = 100.0f; dVector floor (FindFloor (world, dVector (matrix.m_posit.m_x, startElevation, matrix.m_posit.m_z, 0.0f), 2.0f * startElevation)); matrix.m_posit.m_y = floor.m_y + size.m_y / 2.0f; // get the dimension from shape itself dVector minP; dVector maxP; CalculateAABB (collision, dGetIdentityMatrix(), minP, maxP); //dFloat stepz = size.m_z + 0.01f; dFloat stepz = maxP.m_z - minP.m_z + 0.01f; dFloat stepy = maxP.m_y - minP.m_y; float y0 = matrix.m_posit.m_y + stepy / 2.0f; float z0 = matrix.m_posit.m_z - stepz * count / 2; matrix.m_posit.m_y = y0; for (int j = 0; j < count; j ++) { matrix.m_posit.m_z = z0; for (int i = 0; i < (count - j) ; i ++) { CreateSimpleSolid (scene, geometry, mass, matrix, collision, defaultMaterialID); matrix.m_posit.m_z += stepz; } z0 += stepz * 0.5f; matrix.m_posit.m_y += stepy; } // do not forget to release the assets geometry->Release(); NewtonDestroyCollision (collision); }
void BoundingBoxClass::SetModelMatrixAABB(matrix4 a_m4Matrix) { m_m4ModelToWorldAABB = a_m4Matrix; CalculateAABB(m_sInstance); matrix4 translate = glm::translate(m_v3CentroidAABB); vector3 v3Min = GetMinAABB(); vector3 v3Max = GetMaxAABB(); matrix4 scale = glm::scale(v3Max - v3Min); matrix4 m4MatrixAABB = translate * scale; m_pMeshAABB->SetModelMatrix(m4MatrixAABB); }
bool Light::Load(const void* wrapper, bool object) { if (Scene::Active == nullptr) { FURYE << "Active Pipeline is null!"; return false; } if (object && !IsObject(wrapper)) { FURYE << "Json node is not an object!"; return false; } // check type std::string str; if (!LoadMemberValue(wrapper, "type", str) || str != "Light") { FURYE << "Invalide type " << str << "!"; return false; } if (!LoadMemberValue(wrapper, "light_type", str)) { FURYE << "light_type not found!"; return false; } else { SetType(EnumUtil::LightTypeFromString(str)); } LoadMemberValue(wrapper, "color", m_Color); LoadMemberValue(wrapper, "intensity", m_Intensity); LoadMemberValue(wrapper, "inner_angle", m_InnerAngle); LoadMemberValue(wrapper, "outter_angle", m_OutterAngle); LoadMemberValue(wrapper, "falloff", m_Falloff); LoadMemberValue(wrapper, "radius", m_Radius); LoadMemberValue(wrapper, "cast_shadows", m_CastShadows); CalculateAABB(); return true; }
void dVehicleSingleBody::CalculateNodeAABB(const dMatrix& matrix, dVector& minP, dVector& maxP) const { NewtonCollision* const collision = NewtonBodyGetCollision(m_newtonBody); CalculateAABB(collision, matrix, minP, maxP); }
void dVehicleSingleBody::CalculateNodeAABB(const dMatrix& matrix, dVector& minP, dVector& maxP) const { NewtonBody* const newtonBody = m_chassis->GetBody(); NewtonCollision* const collision = NewtonBodyGetCollision(newtonBody); CalculateAABB(collision, matrix, minP, maxP); }
int MeshCompiler::Compile( const char* InFilename, const char* OutFilename, bool LongIndices ) { m_StrippedFilename = FileUtil::StripExtensions( FileUtil::StripLeadingFolders( InFilename ) ); TiXmlDocument XMLDoc; XMLDoc.LoadFile( InFilename ); TiXmlElement* RootElement = XMLDoc.FirstChildElement(); // "mesh" // Sanity check if( _stricmp( RootElement->Value(), "mesh" ) ) { PRINTF( "Input file is not a valid XML mesh file.\n" ); return -1; } STATICHASH( BakeAOForDynamicMeshes ); STATICHASH( BakeAOForAnimatedMeshes ); STATICHASH( TraceTriangleBacks ); STATICHASH( DynamicAORadius ); STATICHASH( DynamicAOPushOut ); MAKEHASH( m_StrippedFilename ); ConfigManager::Load( FileStream( "tools.cfg", FileStream::EFM_Read ) ); m_BakeAOForDynamicMeshes = ConfigManager::GetArchetypeBool( sBakeAOForDynamicMeshes, ConfigManager::EmptyContext, false, sm_StrippedFilename ); m_BakeAOForAnimatedMeshes = ConfigManager::GetArchetypeBool( sBakeAOForAnimatedMeshes, ConfigManager::EmptyContext, false, sm_StrippedFilename ); m_TraceTriangleBacks = ConfigManager::GetArchetypeBool( sTraceTriangleBacks, ConfigManager::EmptyContext, false, sm_StrippedFilename ); m_AORadius = ConfigManager::GetArchetypeFloat( sDynamicAORadius, ConfigManager::EmptyContext, 0.1f, sm_StrippedFilename ); m_AOPushOut = ConfigManager::GetArchetypeFloat( sDynamicAOPushOut, ConfigManager::EmptyContext, 0.01f, sm_StrippedFilename ); m_Header.m_LongIndices = LongIndices; // Get armature first, which will make it easier to handle bone references in verts TiXmlElement* Arm = RootElement->FirstChildElement( "armature" ); CompileArmature( Arm ); int NumFaces = 0; for( TiXmlElement* Face = RootElement->FirstChildElement( "face" ); Face; Face = Face->NextSiblingElement( "face" ) ) { CompileFace( Face ); NumFaces++; } for( TiXmlElement* Mat = RootElement->FirstChildElement( "material" ); Mat; Mat = Mat->NextSiblingElement( "material" ) ) { CompileMaterial( Mat ); } m_Header.m_NumVertices = m_Positions.Size(); m_Header.m_NumIndices = m_Indices.Size(); NormalizeWeights(); CalculateAABB(); if( m_Header.m_HasUVs && m_Header.m_HasNormals ) { m_Header.m_HasTangents = true; } PRINTF( "Calculating tangents...\n" ); CalculateTangents(); CalculateAmbientOcclusion(); PRINTF( "Compile successful!\n" ); PRINTF( "Imported %d faces.\n", NumFaces ); Write( FileStream( OutFilename, FileStream::EFM_Write ) ); PRINTF( "Exported %d vertices.\n", m_Header.m_NumVertices ); PRINTF( "Exported %d indices (%d triangles).\n", m_Header.m_NumIndices, m_Header.m_NumIndices / 3 ); if( m_Header.m_HasSkeleton ) { PRINTF( "Exported %d bones.\n", m_Header.m_NumBones ); PRINTF( "Exported %d frames.\n", m_Header.m_NumFrames ); PRINTF( "Exported %d animations.\n", m_Header.m_NumAnims ); } return 0; }