void FunctionSimple::SetMinZ(float f)
{
  // Offset is avg of min and max.
  m_offsetZ = (f + GetMaxZ()) / 2.0f;
  // Multiplier is max - offset, or offset - min
  m_multiplierZ = fabs(f - m_offsetZ);
}
Exemple #2
0
void FChart3d::Update()
{
    double MaxX = DataMap3d->AddressZ.GetSizeX();
    double MaxY = DataMap3d->AddressZ.GetSizeY();

    if(DataMap3d->Data->IsEmply() || DataMap3d->AddressZ.IsEmpty())
    {
        Surface3d->setMesh(3, 3);
        Surface3d->setDomain(0, 1, 0 , 1);
        Surface3d->create();
        updateData();
        updateGL();
        return;
    }

    double MaxZ = GetMaxZ();

    setTitle(DataMap3d->TitleGraf.isEmpty() ? "3D Map" : DataMap3d->TitleGraf);

    setRotation(30,0,15);
    setScale(MaxZ / MaxX, MaxZ / MaxY, 1);
    setShift(0,0,0); // Deslocamento
    setZoom(0.5);

    Surface3d->setMesh(MaxX+1, MaxY+1);
    Surface3d->setDomain(0, MaxX-1, 0 ,MaxY-1);
    Surface3d->create();


    for (unsigned i=0; i!=coordinates()->axes.size(); ++i)
    {
      coordinates()->axes[i].setMajors(4);
      coordinates()->axes[i].setMinors(2);
    }

    coordinates()->setAutoScale(true);


    double Tic = (coordinates()->second() - coordinates()->first()).length() / MaxZ;
            Tic = Tic * 0.5;
            coordinates()->setTicLength(Tic,0.6*Tic);


    coordinates()->axes[X1].setLabelString("x-axis");
    coordinates()->axes[Y1].setLabelString("y-axis");
    //coordinates()->axes[Z1].setLabelString(QChar(0x38f)); // Omega - see http://www.unicode.org/charts/


    //setCoordinateStyle(BOX);

    updateData();
    updateGL();
}
/// internal method for setting up geometry, called by OverlayElement::update
void cCompassOverlay::updatePositionGeometry(void) {
	/*
	// init clip to fullscreen
	if (!mbClipInitialized) {
		mbClipInitialized = true;
		mClip.left = 0;
		mClip.top = 0;
		if (mMetricsMode != GMM_RELATIVE) {
			mClip.right = mClip.left+cOgreWrapper::GetSingleton().GetViewportWidth();
			mClip.bottom = mClip.top+cOgreWrapper::GetSingleton().GetViewportHeight();
		} else {
			mClip.right = mClip.left+1.0;
			mClip.bottom = mClip.top+1.0;
		}
	}
	*/
	
	//mForm.SetLTWH(_getDerivedLeft(),_getDerivedTop(),mWidth,mHeight);
	
		
	// clear z buffer under overlay
	Real maxz 	= GetMaxZ();
	
	// construct geometry
	int iSteps = 21;
	Begin(2+iSteps,3*iSteps,true,false,Ogre::RenderOperation::OT_TRIANGLE_LIST);
	float radx = (mWidth / 2.0) * 2.0;
	float rady = (mHeight / 2.0) * 2.0;
	float midx = (_getDerivedLeft()) * 2.0 - 1.0 + radx;
	float midy = - (_getDerivedTop() * 2.0 - 1.0 + rady);
	float ang;
	float partang = 2.0 * 3.1415 / float(iSteps);

	Vertex(Vector3(midx,midy,maxz),mfMidU,mfMidV);
	for (int i=0;i<=iSteps;++i) {
		ang = float((i==iSteps)?0:i) * partang;
		Vertex(Vector3(midx-radx*sin(ang),midy+rady*cos(ang),maxz),mfMidU+mfRadU*sin(ang+mfAngBias),mfMidV+mfRadV*cos(ang+mfAngBias));
		if (i>0) {
			Index(0);
			Index(i+1);
			Index(i);
		}
	}
	//clipped.DrawStrip(this,maxz);
	End();
	//pRobRenderOp->Vertex(Vector3(x * 2.0 - 1.0,-(y * 2.0 - 1.0),z),u,v,col);
}
void CUmbralActor::RebuildActorRenderables()
{
	uint32 modelFolder = m_baseModelId % 10000;
	uint32 modelClass = m_baseModelId / 10000;
	const char* charaFolder = "";
	const char* charaPrefix = "";
	switch(modelClass)
	{
	case 1:
		charaFolder = "mon";
		charaPrefix = "m";
		break;
	case 2:
		charaFolder = "bgobj";
		charaPrefix = "b";
		break;
	case 4:
		charaFolder = "wep";
		charaPrefix = "w";
		break;
	default:
		assert(0);
		break;
	}

	uint32 subModelId = m_topModelId >> 10;
	uint32 variation = m_topModelId & 0x3FF;

	auto gamePath = CFileManager::GetGamePath();
	auto modelPath = string_format("%s/client/chara/%s/%s%0.3d/equ/e%0.3d/top_mdl/0001",
		gamePath.string().c_str(), charaFolder, charaPrefix, modelFolder, subModelId);

	Framework::CStdStream inputStream(modelPath.c_str(), "rb");

	auto modelResource = CSectionLoader::ReadSection(ResourceNodePtr(), inputStream);

	auto modelChunk = modelResource->SelectNode<CModelChunk>();
	assert(modelChunk);
	if(!modelChunk) return;

	auto boundingBox = modelChunk->SelectNode<CCompChunk>();

	CVector3 boxMin(boundingBox->GetMinX(), boundingBox->GetMinY(), boundingBox->GetMinZ());
	CVector3 boxMax(boundingBox->GetMaxX(), boundingBox->GetMaxY(), boundingBox->GetMaxZ());

	CVector3 modelSize = (boxMax - boxMin) / 2;
	CVector3 modelPos = (boxMax + boxMin) / 2;

	auto model = std::make_shared<CUmbralModel>(modelChunk);
	model->SetPosition(modelPos);
	model->SetScale(modelSize);
	AppendChild(model);

	auto modelBoundingSphere = model->GetBoundingSphere();
	modelBoundingSphere.radius *= std::max(std::max(modelSize.x, modelSize.y), modelSize.z);
	modelBoundingSphere.position += modelPos;
	m_boundingSphere = modelBoundingSphere;

	uint32 textureId = 0;
	if(modelClass == 4)
	{
		uint32 varWepId = 1000000000 + (modelFolder * 1000000) + (subModelId * 1000) + variation;
		auto var = CWeaponVars::GetInstance().GetVarForId(varWepId);
		textureId = var.textureId;

		for(const auto& meshNode : model->GetChildren())
		{
			if(auto mesh = std::dynamic_pointer_cast<CUmbralMesh>(meshNode))
			{
				auto meshName = mesh->GetName();
				int materialId = 0;
				if(meshName.find("_a") != std::string::npos)
				{
					materialId = 0;
				}
				if(meshName.find("_b") != std::string::npos)
				{
					materialId = 1;
				}
				if(meshName.find("_c") != std::string::npos)
				{
					materialId = 2;
				}
				if(meshName.find("_d") != std::string::npos)
				{
					assert(0);
				}
				const auto& varWepMaterial = var.materials[materialId];
				auto material = mesh->GetMaterial();
				ReplaceMaterialParam(material, "ps_diffuseColor", varWepMaterial.diffuseColor);
				ReplaceMaterialParam(material, "ps_multiDiffuseColor", varWepMaterial.multiDiffuseColor);
				ReplaceMaterialParam(material, "ps_specularColor", varWepMaterial.specularColor);
				ReplaceMaterialParam(material, "ps_multiSpecularColor", varWepMaterial.multiSpecularColor);
				ReplaceMaterialParam(material, "ps_reflectivity", varWepMaterial.specularColor);
				ReplaceMaterialParam(material, "ps_multiReflectivity", varWepMaterial.multiSpecularColor);
				ReplaceMaterialParam(material, "ps_shininess", varWepMaterial.shininess);
				ReplaceMaterialParam(material, "ps_multiShininess", varWepMaterial.multiShininess);
				mesh->SetActivePolyGroups(var.polyGroupState);
			}
		}
	}

	{
		auto texturePath = string_format("%s/client/chara/%s/%s%0.3d/equ/e%0.3d/top_tex2/%0.4d",
			gamePath.string().c_str(), charaFolder, charaPrefix, modelFolder, subModelId, textureId);

		Framework::CStdStream inputStream(texturePath.c_str(), "rb");
		auto textureResource = CSectionLoader::ReadSection(ResourceNodePtr(), inputStream);
		model->SetLocalTexture(textureResource);
	}

	m_renderableDirty = false;
}