BoundingBox XMLElement::GetBoundingBox() const { BoundingBox ret; ret.min_ = GetVector3("min"); ret.max_ = GetVector3("max"); return ret; }
int NFCRecord::FindVector3(const int nCol, const NFVector3& value, NFDataList& varResult) { if (!ValidCol(nCol)) { return -1; } if (TDATA_VECTOR3 != mVarRecordType->Type(nCol)) { return -1; } { for (int i = 0; i < mnMaxRow; ++i) { if (!IsUsed(i)) { continue; } if (GetVector3(i, nCol) == value) { varResult << (int64_t)i; } } return varResult.GetCount(); } return -1; }
void ReplaceMaterialParam(const Palleon::MaterialPtr& material, const char* paramName, const CVector4& newParamValue) { auto param = material->GetEffectParameter(paramName); CVector4 paramValue(0, 0, 0, 0); if(param.IsVector3()) { paramValue = CVector4(param.GetVector3(), 0); } else { paramValue = param.GetVector4(); } paramValue.x = (newParamValue.x == 1000.f) ? paramValue.x : newParamValue.x; paramValue.y = (newParamValue.y == 1000.f) ? paramValue.y : newParamValue.y; paramValue.z = (newParamValue.z == 1000.f) ? paramValue.z : newParamValue.z; paramValue.w = (newParamValue.w == 1000.f) ? paramValue.w : newParamValue.w; if(param.IsVector3()) { param.SetVector3(paramValue.xyz()); } else { param.SetVector4(paramValue); } material->SetEffectParameter(paramName, param); }
Vector PickObjectTool::GetWorldCoordinates(BaseDraw* bd, const Matrix4d& m, Float x, Float y, Float z) { // pick object returns the view-projection matrix. This transforms a point in camera space into clip space. Int32 l, t, r, b, w, h; Vector4d pos; Vector posWorld; bd->GetFrame(&l, &t, &r, &b); if (l == r || b == t) return Vector(0.0); w = r - l; h = b - t; // first, transform the points into clip space pos.x = (x - Float(l)) / Float(w); pos.y = (y - Float(t)) / Float(h); pos.z = z; pos.w = 1.0; pos = pos * 2.0f - Vector4d(1.0f); pos.y = -pos.y; // apply the inverse view transform Matrix4d im = !m; pos = im * pos; pos.MakeVector3(); // convert it into a 3-tupel posWorld = bd->GetMg() * GetVector3(pos); return posWorld; }
const Urho3D::Vector3 ConfigManager::GetVector3(const Urho3D::String& section, const Urho3D::String& parameter, const Urho3D::Vector3& defaultValue) { auto value = Get(section, parameter); if (value.GetType() == Urho3D::VAR_VECTOR3) return value.GetVector3(); if (value.GetType() == Urho3D::VAR_STRING) return Urho3D::ToVector3(value.GetString()); // Parameter doesn't exist, or is a different type if (_saveDefaultParameters) { // Set back to default Set(section, parameter, defaultValue); } return defaultValue; }
cMainRoleData::cMainRoleData(TiXmlElement*e_pTiXmlElement):cCharacterBase(e_pTiXmlElement) { assert(this->Count() == eMTMRS_MAX&&"animation count is not match"); m_bBattleMode = false; m_eVirtualGamePadDirection = eVGPD_NONE; m_vRenderPos = Vector2(0,0); m_eBattleAttackType = eBT_ATTATK_MAX; m_eBattleDefenceType = eBT_DEFENCE_MAX; m_eBattleAttackType = eBT_ATTATK_MOVE_OBJECT; m_eBattleDefenceType = eBT_DEFENCE_1; //main character setup cPuzzleImage*l_pPuzzleImage = cGameApp::GetPuzzleImageByFileName(L"MagicTower/Image/MainCharacter.pi"); POINT l_MapPosIndex = {2,1}; m_pImage[eVGPD_LEFT] = l_pPuzzleImage->GetObject(L"Character_Main_L"); m_pImage[eVGPD_UP] = l_pPuzzleImage->GetObject(L"Character_Main_Bk"); m_pImage[eVGPD_RIGHT] = l_pPuzzleImage->GetObject(L"Character_Main_R"); m_pImage[eVGPD_DOWN] = l_pPuzzleImage->GetObject(L"Character_Main_F"); m_pImage[eVGPD_NONE] = l_pPuzzleImage->GetObject(L"Character_Main_Idle"); assert(m_pImage[eVGPD_NONE]); assert(m_pImage[eVGPD_UP]); assert(m_pImage[eVGPD_LEFT]); assert(m_pImage[eVGPD_RIGHT]); assert(m_pImage[eVGPD_DOWN]); //TiXmlElement*l_pElement = ISAXCallback::GetXmlElementByNameFromElement(L"Battle",e_pTiXmlElement); TiXmlElement*l_pElement = GetXmlElementByNameFromElement(L"Battle",e_pTiXmlElement); if( l_pElement ) { const WCHAR*l_strPos = l_pElement->Attribute(L"Pos"); if( l_strPos ) { this->SetWorldPosition(GetVector3(l_strPos)); } } }
template <> Vector3 Variant::Get<Vector3>() const { return GetVector3(); }
template <> const Vector3& Variant::Get<const Vector3&>() const { return GetVector3(); }
const NFVector3& NFCRecord::GetVector3(const int nRow, const std::string& strColTag) const { int nCol = GetCol(strColTag); return GetVector3(nRow, nCol); }
ProjectStructs::MESHLESS_OBJECT_STRUCT PointCloudHandler::ProcessPointCloud( std::string file, CSGTree *&volumeTree , Volume *&volume) { TiXmlDocument pointCloudXml; if(!pointCloudXml.LoadFile(file.c_str())) { std::string errorText = "Could not parse " + file; std::string errorHeader = "Point Cloud Error"; MessageBox(0, errorText.c_str(), errorHeader.c_str(), 0); } ProjectStructs::MESHLESS_OBJECT_STRUCT meshlessStruct; TiXmlNode *meshNode = pointCloudXml.FirstChild(XML_MESHLESS_ROOT); meshlessStruct.name = meshNode->FirstChild(XML_MESHLESS_NAME)->FirstChild()->Value(); meshlessStruct.materialProperties.deformable = meshNode->FirstChild(XML_MESHLESS_DEFORMABLE)->FirstChild()->Value() == XML_MESHLESS_TRUE; meshlessStruct.materialProperties.texture= meshNode->FirstChild(XML_MESHLESS_TEXTURE)->FirstChild()->Value(); D3DXVECTOR3 translation = GetVector3(meshNode->FirstChild(XML_MESHLESS_WORLDTRANSLATION)->ToElement()); D3DXVECTOR3 scale = GetVector3(meshNode->FirstChild(XML_MESHLESS_WORLDSCALE)->ToElement()); D3DXVECTOR3 yawpitchroll= GetVector3(meshNode->FirstChild(XML_MESHLESS_WORLDYAWPITCHROLL)->ToElement()); double d; meshNode->FirstChild(XML_MESHLESS_LIGHTING)->ToElement()->Attribute(XML_MESHLESS_MATERIAL_RHO.c_str(), &d); meshlessStruct.materialProperties.rho = (float)d; meshNode->FirstChild(XML_MESHLESS_LIGHTING)->ToElement()->Attribute(XML_MESHLESS_MATERIAL_SIGMA.c_str(), &d); meshlessStruct.materialProperties.sigma = (float)d; meshlessStruct.materialProperties.vertexGridSize= -1.0f; if(meshlessStruct.materialProperties.deformable) { meshlessStruct.materialProperties.density = (float)atof(meshNode->FirstChild(XML_MESHLESS_DENSITY)->FirstChild()->Value()); // meshlessStruct.materialProperties.mass = (float)atof(meshNode->FirstChild(XML_MESHLESS_MASS)->FirstChild()->Value()); meshlessStruct.materialProperties.toughness = (float)atof(meshNode->FirstChild(XML_MESHLESS_TOUGHNESS)->FirstChild()->Value()); meshlessStruct.materialProperties.youngsModulus = (float)atof(meshNode->FirstChild(XML_MESHLESS_YOUNGS_MODULUS)->FirstChild()->Value());// * pow(10.0f, 5.0f); meshlessStruct.materialProperties.poissonRatio = (float)atof(meshNode->FirstChild(XML_MESHLESS_POISSON_RATIO)->FirstChild()->Value()); meshlessStruct.materialProperties.phyxelGridSize= (float)atof(meshNode->FirstChild(XML_MESHLESS_PHYXEL_GRID_SIZE)->FirstChild()->Value()); meshlessStruct.materialProperties.minimunSurfelSize = (float)atof(meshNode->FirstChild(XML_MESHLESS_MINIMUM_SURFEL_SIZE)->FirstChild()->Value()); meshlessStruct.materialProperties.vertexGridSize= (float)atof(meshNode->FirstChild(XML_MESHLESS_VERTEX_GRID_SIZE)->FirstChild()->Value()); } meshlessStruct.transform = translation; D3DXMATRIX translationMatrix, scaleMatrix, yawpitchrollMatrix; D3DXMatrixTranslation(&translationMatrix, translation.x, translation.y, translation.z); D3DXMatrixScaling(&scaleMatrix, scale.x, scale.y, scale.z); D3DXMatrixRotationYawPitchRoll(&yawpitchrollMatrix, yawpitchroll.x, yawpitchroll.y, yawpitchroll.z); meshlessStruct.scale = scale; meshlessStruct.rotation= yawpitchroll; meshlessStruct.world = scaleMatrix * yawpitchrollMatrix * translationMatrix; TiXmlNode* volumeNode = meshNode->FirstChild(XML_MESHLESS_VOLUME); TiXmlNode* surfel; std::vector<Volume*> volumes; do { surfel = volumeNode->FirstChild(XML_MESHLESS_SURFACE); Volume *v = new Volume(meshlessStruct.materialProperties); v->SetWorld(meshlessStruct.world); do { D3DXVECTOR3 pos = GetVector3(surfel ->FirstChild(XML_MESHLESS_SURFACE_POSITION)->ToElement()); D3DXVECTOR3 majorAxis = GetVector3(surfel ->FirstChild(XML_MESHLESS_SURFACE_SURFEL_MAJOR_AXIS)->ToElement()); D3DXVECTOR3 minorAxis = GetVector3(surfel ->FirstChild(XML_MESHLESS_SURFACE_SURFEL_MINOR_AXIS)->ToElement()); D3DXVECTOR3 normal = GetVector3(surfel ->FirstChild(XML_MESHLESS_SURFACE_SURFEL_NORMAL)->ToElement()); D3DXVECTOR2 count = GetVector2(surfel ->FirstChild(XML_MESHLESS_SURFACE_SURFEL_COUNT)->ToElement()); CreateSurface(v, pos, majorAxis, minorAxis, normal, count.x, count.y, meshlessStruct.texture); surfel = surfel->NextSibling(XML_MESHLESS_SURFACE); } while(surfel); v->Init(); volumes.push_back(v); volumeNode = volumeNode->NextSibling(XML_MESHLESS_VOLUME); } while(volumeNode); if(volumes.size() == 1) { volume = volumes[0]; volumes.clear(); return meshlessStruct; } else if(volumes.size() == 2) { volumeTree = new CSGTree(); volumeTree->CreateTree(volumeTree->And(volumes[0], volumes[1])); volumes.clear(); return meshlessStruct; } volumeTree = new CSGTree(); std::vector<OPERATOR_NODE*> one, two; bool done = false; int size = volumes.size(); for(unsigned int i = 0; i<volumes.size()-1; i+=2) { one.push_back(volumeTree->And(volumes[i], volumes[i+1])); } if(volumes.size() % 2 == 1) { one[one.size()-1] = volumeTree->And(one[one.size()-1], volumes[volumes.size()-1]); } while(!done) { two.clear(); for(unsigned int i = 0; i<one.size()-1; i+=2) { two.push_back(volumeTree->And(one[i], one[i+1])); } if(one.size() % 2 == 1) { two[two.size()-1] = volumeTree->And(two[two.size()-1], one[one.size()-1]); } if(one.size() == 2) { volumeTree->CreateTree(volumeTree->And(one[0], one[1])); break; } if(two.size() == 2) { volumeTree->CreateTree(volumeTree->And(two[0], two[1])); break; } if(one.size() == 1) { volumeTree->CreateTree(one[0]); break; } if(two.size() == 1) { volumeTree->CreateTree(two[0]); break; } one.clear(); for(unsigned int i = 0; i<two.size()-1; i+=2) one.push_back(volumeTree->And(two[i], two[i+1])); if(two.size() % 2 == 1) { one[one.size()-1] = volumeTree->And(one[one.size()-1], two[two.size()-1]); } } volumes.clear(); return meshlessStruct; }
CValue* CVectorValue::CalcFinal(VALUE_DATA_TYPE dtype, VALUE_OPERATOR op, CValue *val) /* pre: the type of val is dtype ret: a new object containing the result of applying operator op to val and this object */ { CValue *ret = NULL; switch(op) { case VALUE_ADD_OPERATOR: { switch (dtype) { case VALUE_EMPTY_TYPE: case VALUE_VECTOR_TYPE: { ret = new CVectorValue( val->GetVector3()[KX_X] + GetVector3()[KX_X], val->GetVector3()[KX_Y] + GetVector3()[KX_Y], val->GetVector3()[KX_Z] + GetVector3()[KX_Z], CValue::HEAPVALUE); ret->SetName(GetName()); break; } default: ret = new CErrorValue(val->GetText() + op2str(op) + GetText()); } break; } case VALUE_MUL_OPERATOR: { switch (dtype) { case VALUE_EMPTY_TYPE: case VALUE_VECTOR_TYPE: { //MT_Vector3 supports 'scaling' by another vector, instead of using general transform, Gino? //ret = new CVectorValue(val->GetVector3().Scaled(GetVector3()),GetName()); break; } case VALUE_FLOAT_TYPE: { ret = new CVectorValue( val->GetVector3()[KX_X] * GetVector3()[KX_X], val->GetVector3()[KX_Y] * GetVector3()[KX_Y], val->GetVector3()[KX_Z] * GetVector3()[KX_Z], CValue::HEAPVALUE); ret->SetName(GetName()); break; } default: ret = new CErrorValue(val->GetText() + op2str(op) + GetText()); } break; } default: ret = new CErrorValue(val->GetText() + op2str(op) + GetText()); } return ret; }
void XmlMapFile::LoadMap() { TiXmlNode* node = m_File.RootElement(); if( node == NULL || node->ValueStr() != "map" ) { LOG_ERROR( m_File.ValueStr() + " is not a valid fields map file! No <map> in root." ); return; } node = node->FirstChild(); while( node != NULL ) { if( node->Type() == TiXmlNode::TINYXML_ELEMENT && node->ValueStr() == "walkmesh" ) { Ogre::String name( GetString( node, "file_name" ) ); if( !name.empty() ) { QGears::WalkmeshFileManager::getSingleton(); QGears::WalkmeshFilePtr walkmesh( QGears::WalkmeshFileManager::getSingleton().load( name, "Game" ) ); EntityManager::getSingleton().GetWalkmesh()->load( walkmesh ); } } else if( node->Type() == TiXmlNode::TINYXML_ELEMENT && node->ValueStr() == "movement_rotation" ) { Ogre::Degree rotation = Ogre::Degree( GetFloat( node, "degree", 0 ) ); EntityManager::getSingleton().SetPlayerMoveRotation( Ogre::Radian( rotation ) ); } else if( node->Type() == TiXmlNode::TINYXML_ELEMENT && node->ValueStr() == "background2d" ) { Ogre::String name = GetString( node, "file_name" ); if( name != "" ) { // TODO migrate this code to a Resource and use it's group to load background QGears::Background2DFilePtr background( QGears::Background2DFileManager::getSingleton().load( name, "Game" ) ); EntityManager::getSingleton().GetBackground2D()->load( background ); } } else if( node->Type() == TiXmlNode::TINYXML_ELEMENT && node->ValueStr() == "entity_model" ) { Ogre::String name = GetString( node, "name" ); if( name == "" ) { LOG_ERROR( "There is no name specified for <entity_model> tag." ); continue; } Ogre::String file_name = GetString( node, "file_name" ); if( file_name == "" ) { LOG_ERROR( "There is no file_name specified for <entity_model> tag." ); continue; } Ogre::Vector3 position( GetVector3( node, "position" ) ); Ogre::Degree direction( Ogre::Degree( GetFloat( node, "direction" ) ) ); Ogre::Vector3 scale( GetVector3( node, "scale", Ogre::Vector3::UNIT_SCALE ) ); Ogre::Quaternion orientation( GetQuaternion( node, "root_orientation" ) ); EntityManager::getSingleton().AddEntity( name, file_name, position, direction, scale, orientation ); } else if( node->Type() == TiXmlNode::TINYXML_ELEMENT && node->ValueStr() == "entity_trigger" ) { Ogre::String name = GetString( node, "name" ); if( name == "" ) { LOG_ERROR( "There is no name specified for <entity_trigger> tag." ); continue; } Ogre::Vector3 point1 = GetVector3( node, "point1", Ogre::Vector3::ZERO ); Ogre::Vector3 point2 = GetVector3( node, "point2", Ogre::Vector3::ZERO ); bool enabled = GetBool( node, "enabled", false ); EntityManager::getSingleton().AddEntityTrigger( name, point1, point2, enabled ); } else if( node->Type() == TiXmlNode::TINYXML_ELEMENT && node->ValueStr() == "entity_point" ) { Ogre::String name = GetString( node, "name" ); if( name == "" ) { LOG_ERROR( "There is no name specified for <entity_point> tag." ); continue; } Ogre::Vector3 position = GetVector3( node, "position" ); float rotation = GetFloat( node, "rotation" ); EntityManager::getSingleton().AddEntityPoint( name, position, rotation ); } else if( node->Type() == TiXmlNode::TINYXML_ELEMENT && node->ValueStr() == "entity_script" ) { Ogre::String name = GetString( node, "name" ); if( name == "" ) { LOG_ERROR( "There is no name specified for <entity_script> tag." ); continue; } EntityManager::getSingleton().AddEntityScript( name ); } else if( node->Type() == TiXmlNode::TINYXML_ELEMENT && node->ValueStr() == "script" ) { Ogre::String file_name = GetString( node, "file_name" ); if( file_name != "" ) { ScriptManager::getSingleton().RunFile( file_name ); } } node = node->NextSibling(); } }