예제 #1
0
파일: camera.cpp 프로젝트: tweakoz/orkid
void CCameraData::GetPixelLengthVectors( const CVector3& Pos, const CVector2& vp, CVector3& OutX, CVector3& OutY ) const
{
	/////////////////////////////////////////////////////////////////
	int ivpw = int(vp.GetX());
	int ivph = int(vp.GetY());
	/////////////////////////////////////////////////////////////////
	CVector4 va = Pos;
	CVector4 va_xf = va.Transform(mVPMatrix);
	va_xf.PerspectiveDivide();
	va_xf = va_xf*CVector4(vp.GetX(),vp.GetY(),0.0f);
	/////////////////////////////////////////////////////////////////
	CVector4 vdx = Pos+mCamXNormal;
	CVector4 vdx_xf = vdx.Transform(mVPMatrix);
	vdx_xf.PerspectiveDivide();
	vdx_xf = vdx_xf*CVector4(vp.GetX(),vp.GetY(),0.0f);
	float MagX = (vdx_xf-va_xf).Mag(); // magnitude in pixels of mBillboardRight
	/////////////////////////////////////////////////////////////////
	CVector4 vdy = Pos+mCamYNormal;
	CVector4 vdy_xf = vdy.Transform(mVPMatrix);
	vdy_xf.PerspectiveDivide();
	vdy_xf = vdy_xf*CVector4(vp.GetX(),vp.GetY(),0.0f);
	float MagY = (vdy_xf-va_xf).Mag(); // magnitude in pixels of mBillboardUp
	/////////////////////////////////////////////////////////////////
	OutX = mCamXNormal*(2.0f/MagX);
	OutY = mCamYNormal*(2.0f/MagY);
	/////////////////////////////////////////////////////////////////
}
예제 #2
0
/*!
* @brief	開始
*/
bool EnemyTest::Start()
{
	if (orgSkinModelData == NULL) {
		orgSkinModelData = new CSkinModelData;
		orgAnimation = new CAnimation;
		//orgSkinModelData->LoadModelData("Assets/modelData/Unity.X", orgAnimation);
		orgSkinModelData->LoadModelData("Assets/modelData/player.X", orgAnimation);
	}
	//オリジナルのモデルデータからクローンモデルを作成。
	skinModelData.CloneModelData(*orgSkinModelData, &animation);
	
	skinModel.Init(&skinModelData);
	skinModel.SetLight(&light);
	skinModel.SetShadowCasterFlag(true);
	skinModel.SetShadowReceiverFlag(true);
	skinModel.SetFresnelFlag(true);
	skinModel.SetReflectionCasterFlag(true);

	light.SetDiffuseLightDirection(0, CVector3(0.707f, 0.0f, -0.707f));
	light.SetDiffuseLightDirection(1, CVector3(-0.707f, 0.0f, -0.707f));
	light.SetDiffuseLightDirection(2, CVector3(0.0f, 0.707f, -0.707f));
	light.SetDiffuseLightDirection(3, CVector3(0.0f, -0.707f, -0.707f));


	light.SetDiffuseLightColor(0, CVector4(0.2f, 0.2f, 0.2f, 1.0f));
	light.SetDiffuseLightColor(1, CVector4(0.2f, 0.2f, 0.2f, 1.0f));
	light.SetDiffuseLightColor(2, CVector4(0.2f, 0.2f, 0.2f, 1.0f));
	light.SetDiffuseLightColor(3, CVector4(0.2f, 0.2f, 0.2f, 1.0f));
	light.SetAmbinetLight(CVector3(0.4f, 0.4f, 0.4f));

	light.SetLimLightColor(CVector4(0.6f, 0.6f, 0.6f, 1.0f));
	light.SetLimLightDirection(CVector3(0.0f, 0.0f, -1.0f));

	isPointLightOn = false;
	UpdatePointLightPosition();

	currentAnimSetNo = AnimationInvalid;
	PlayAnimation(currentAnimSetNo);
	rotation = CQuaternion::Identity;

	CVector3 lightPos = CVector3(0.0f, 25.5f, 24.5f);
	ShadowMap().SetLightPosition(lightPos);
	ShadowMap().SetLightTarget(position);
	toLightPos.Subtract(lightPos, position);
	ShadowMap().SetCalcLightViewFunc(CShadowMap::enCalcLightViewFunc_PositionTarget);
	state = enStateStand;
	isJump = false;

	radius = 0.4f;

	collider.Create(radius);
	RigidBodyInfo rbInfo;
	rbInfo.pos = position;
	rbInfo.rot = rotation;
	rbInfo.collider = &collider;
	rigidBody.Create(rbInfo);
	toLampLocalPos.Set( 0.0f, 0.5f, 0.2f);
	//g_physicsWorld->AddRigidBody(&rigidBody);
	return true;
}
예제 #3
0
void CWorldEditor::CreateWorld()
{
	auto screenSize = Palleon::CGraphicDevice::GetInstance().GetScreenSize();

	{
		auto camera = CTouchFreeCamera::Create();
		camera->SetPerspectiveProjection(MAIN_CAMERA_FOV, screenSize.x / screenSize.y, MAIN_CAMERA_NEAR_Z, MAIN_CAMERA_FAR_Z, Palleon::HANDEDNESS_RIGHTHANDED);
		camera->SetPosition(CVector3(0, 2, 0));
		m_mainCamera = camera;
	}

	{
		auto viewport = Palleon::CViewport::Create();
		viewport->SetCamera(m_mainCamera);
		m_mainViewport = viewport;
	}

	{
		auto lightDir0 = CVector3(1, -1, 0).Normalize();
		auto lightDir1 = CVector3(-1, -1, 0).Normalize();

		m_mainViewport->SetEffectParameter("ps_ambientLightColor", Palleon::CEffectParameter(CVector4(0, 0, 0, 0)));
		m_mainViewport->SetEffectParameter("ps_dirLightDirection0", Palleon::CEffectParameter(lightDir0));
		m_mainViewport->SetEffectParameter("ps_dirLightDirection1", Palleon::CEffectParameter(lightDir1));
		m_mainViewport->SetEffectParameter("ps_dirLightColor0", Palleon::CEffectParameter(CVector4(1.0f, 1.0f, 1.0f, 0)));
		m_mainViewport->SetEffectParameter("ps_dirLightColor1", Palleon::CEffectParameter(CVector4(1.0f, 1.0f, 1.0f, 0)));
	}

	{
		auto viewport = Palleon::CViewport::Create();
		viewport->SetCamera(m_mainCamera);
		m_overlayViewport = viewport;
	}
}
bool CFXMotionBlurTexture::DoFrame(CDemo* pDemo, float fEffectTime, float fDemoTime)
{
	assert(pDemo);

	// Evaluate vars

	CVarFloat::CValueFloat valueTrail;
	EvaluateVar("Trail (0-1)", fEffectTime, &valueTrail);
	float fAlpha = valueTrail.GetValue();

	// Draw previous

	UtilGL::Rendering::DrawCenteredQuad(m_pTexture,
										0.5f, 0.5f, 1.0f, 1.0f,
										0.0f, CVector4(1.0f, 1.0f, 1.0f, fAlpha),
										UtilGL::States::BLEND_SRCALPHA, UtilGL::States::BLEND_INVSRCALPHA);
	// Accumulate

	m_pTexture->SetActive();
	m_pTexture->CopyFromFramebuffer(0, 0, 0, 0, m_pTexture->GetWidth(), m_pTexture->GetHeight());

	// Restore demo viewport
	pDemo->SetDemoViewport();

	// Clear framebuffer
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);

	return 	UtilGL::Rendering::DrawCenteredQuad(m_pTexture,
										0.5f, 0.5f, 1.0f, 1.0f,
										0.0f, CVector4(1.0f, 1.0f, 1.0f, 1.0f),
										UtilGL::States::BLEND_ONE, UtilGL::States::BLEND_ZERO);
}
예제 #5
0
//--------------------------------------------------------------------------------------------------------------------
void RDX11RenderHelper::RenderScaler(XMMATRIX& tm)
{
	SetWorldTM(tm);

	IShaderMgr* pShaderMgr = GLOBAL::ShaderMgr();
	IRenderStrategy* pRenderer = GLOBAL::RDevice()->GetRenderStrategy();

	pShaderMgr->Begin(SHADER_POS_VS, SHADER_COLOR_PS);

	CVector4 color = CVector4(0,0,0,1);
	pShaderMgr->SetShaderConstant( &color, sizeof(color), 9, VERTEX_SHADER);
	pRenderer->RenderGeometry(&m_BoxX);

	color = CVector4(0,0,1,0);
	pShaderMgr->SetShaderConstant( &color, sizeof(color), 9, VERTEX_SHADER);	
	pRenderer->RenderGeometry(&m_BoxY);

	color = CVector4(0,1,0,0);
	pShaderMgr->SetShaderConstant( &color, sizeof(color), 9, VERTEX_SHADER);
	pRenderer->RenderGeometry(&m_BoxZ);
	
	color = CVector4(0,0.5f, 0.5f, 0.5f);
	pShaderMgr->SetShaderConstant( &color, sizeof(color), 9, VERTEX_SHADER);
	pRenderer->RenderGeometry(&m_BoxCenter);

	RenderAxis(tm);
}
예제 #6
0
void CActorViewer::UpdateLights()
{
//	auto lightDir0 = CVector3(cos(m_elapsed), -1, sin(m_elapsed)).Normalize();
//	auto lightDir1 = CVector3(-sin(m_elapsed), -1, cos(m_elapsed)).Normalize();
	auto lightDir0 = CVector3(1, -1, 0).Normalize();
	auto lightDir1 = CVector3(0, 0, 0);

	m_mainViewport->SetEffectParameter("ps_ambientLightColor", Palleon::CEffectParameter(CVector4(0, 0, 0, 0)));
	m_mainViewport->SetEffectParameter("ps_dirLightDirection0", Palleon::CEffectParameter(lightDir0));
	m_mainViewport->SetEffectParameter("ps_dirLightDirection1", Palleon::CEffectParameter(lightDir1));
	m_mainViewport->SetEffectParameter("ps_dirLightColor0", Palleon::CEffectParameter(CVector4(1.0f, 1.0f, 1.0f, 0)));
	m_mainViewport->SetEffectParameter("ps_dirLightColor1", Palleon::CEffectParameter(CVector4(1.0f, 1.0f, 1.0f, 0)));
}
예제 #7
0
CVector4 Matrix4x4::GetRow(int position) const
{
	if(position==0)
		return CVector4(entries[0], entries[4], entries[8], entries[12]);

	if(position==1)
		return CVector4(entries[1], entries[5], entries[9], entries[13]);

	if(position==2)
		return CVector4(entries[2], entries[6], entries[10], entries[14]);

	if(position==3)
		return CVector4(entries[3], entries[7], entries[11], entries[15]);

	return CVector4(0.0f, 0.0f, 0.0f, 0.0f);
}
예제 #8
0
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);
}
예제 #9
0
bool CFXBoxBlur::LoadData(CResourceList* pResourceList)
{
	// Force width and height to be powers of two. log2(x) = log10(x) / log10(2)

	CVarInt::CValueInt valueInt;

	EvaluateVar("BlurTexture Width",  0.0f, &valueInt);
	if(valueInt.GetValue() < 1) valueInt.SetValue(1);
	int nWidthPwr = MYROUND(log10f(valueInt.GetValue()) / log10f(2));

	EvaluateVar("BlurTexture Height", 0.0f, &valueInt);
	if(valueInt.GetValue() < 1) valueInt.SetValue(1);
	int nHeightPwr = MYROUND(log10f(valueInt.GetValue()) / log10f(2));

	int nWidth  = pow(2, nWidthPwr);
	int nHeight = pow(2, nHeightPwr);

	// Create texture

	UtilGL::Texturing::STexLoadOptions texOptions;
	texOptions.SetDefaults();
	texOptions.eFilter = UtilGL::Texturing::FILTER_LINEAR;

	m_texture.LoadFlat(nWidth, nHeight, CVector4(0.0f, 0.0f, 0.0f, 1.0f), false, false, &texOptions);

	return true;
}
예제 #10
0
bool CFXBoxBlur::DoFrame(CDemo* pDemo, float fEffectTime, float fDemoTime)
{
	assert(pDemo);

	// Evaluate vars

	CVarInt::CValueInt valueRadius;

	EvaluateVar("Blur Radius (Pw2)", fEffectTime, &valueRadius);

	// Blur

	UtilGL::Rendering::ComputeBoxBlur(valueRadius.GetValue(), &m_texture);

	// Restore demo viewport

	pDemo->SetDemoViewport();

	// Clear framebuffer

	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);

	// Draw final blur

	UtilGL::Rendering::DrawCenteredQuad(&m_texture, 0.5f, 0.5f, 1.0f, 1.0f, 0.0f,
										CVector4(1.0f, 1.0f, 1.0f, 1.0f),
										UtilGL::States::BLEND_ONE, UtilGL::States::BLEND_ZERO);
	
	return true;
}
예제 #11
0
void ObserverCamControllerInst::DoUpdate( SceneInst* psi )
{
	CVector3 cam_UP = CVector3(0.0f,1.0f,0.0f);
	CVector3 cam_EYE = CVector3(0.0f,0.0f,0.0f);

	if( mpEye )
	{
		DagNode& dnodeEYE = mpEye->GetDagNode();
		TransformNode3D& t3dEYE = dnodeEYE.GetTransformNode();
		CMatrix4 mtxEYE = t3dEYE.GetTransform()->GetMatrix();
		cam_EYE = CVector4(mCD.GetEyeOffset()).Transform(mtxEYE).GetXYZ();
		cam_UP = mtxEYE.GetYNormal();
	}
	else
	{
		DagNode& dnodeEYE = GetEntity()->GetDagNode();
		TransformNode3D& t3dEYE = dnodeEYE.GetTransformNode();
		CMatrix4 mtxEYE = t3dEYE.GetTransform()->GetMatrix();
		cam_EYE = CVector4(mCD.GetEyeOffset()).Transform(mtxEYE).GetXYZ();
	}

	if( mpTarget )
	{
		DagNode& dnodeTGT = mpTarget->GetDagNode();
		TransformNode3D& t3dTGT = dnodeTGT.GetTransformNode();
		CMatrix4 mtxTGT = t3dTGT.GetTransform()->GetMatrix();
		CVector3 cam_TGT = CVector4(mCD.GetTgtOffset()).Transform(mtxTGT).GetXYZ();

		float fnear = mCD.GetNear();
		float ffar = mCD.GetFar();
		float faper = mCD.GetAperature();
		
		CVector3 N = (cam_TGT-cam_EYE).Normal();
		
		mCameraData.Persp( fnear, ffar, faper );
		mCameraData.Lookat( cam_EYE, cam_TGT, cam_UP );
		
		//orkprintf( "ocam eye<%f %f %f>\n", cam_EYE.GetX(), cam_EYE.GetY(), cam_EYE.GetZ() );
		//orkprintf( "ocam tgt<%f %f %f>\n", cam_TGT.GetX(), cam_TGT.GetY(), cam_TGT.GetZ() );
		//orkprintf( "ocam dir<%f %f %f>\n", N.GetX(), N.GetY(), N.GetZ() );
		
		//psi->SetCameraData( AddPooledLiteral("game1"), & mCameraData );
	}
}
bool CFXRecursiveBlurTexture::DoFrame(CDemo* pDemo, float fEffectTime, float fDemoTime)
{
	assert(pDemo);

	if(!m_pTexture) return false;

	// Evaluate vars

	CVarFloat::CValueFloat valueIntensity;
	CVarFloat::CValueFloat valueWidth;
	CVarFloat::CValueFloat valueHeight;
	CVarFloat::CValueFloat valueOriginX;
	CVarFloat::CValueFloat valueOriginY;

	EvaluateVar("Intensity",  fEffectTime, &valueIntensity);
	EvaluateVar("Width",      fEffectTime, &valueWidth);
	EvaluateVar("Height",     fEffectTime, &valueHeight);
	EvaluateVar("X Origin",   fEffectTime, &valueOriginX);
	EvaluateVar("Y Origin",   fEffectTime, &valueOriginY);

	// Compute blur direction

	CVector3 v3Vector;
	v3Vector.Build(CVector3(valueOriginX.GetValue(), valueOriginY.GetValue(), 0.0f), CVector3(0.5f, 0.5f, 0.0f));

	if(!IS_ZERO(v3Vector.X()) || !IS_ZERO(v3Vector.Y()))
	{
		v3Vector.Normalize();
	}

	// Accumulate previous blur

	float fWidth  = valueWidth.GetValue();
	float fHeight = valueHeight.GetValue();

	UtilGL::Rendering::DrawCenteredQuad(m_pTexture,
										0.5f + v3Vector.X() * ((fWidth  * 0.5f) - 0.5f),
										0.5f + v3Vector.Y() * ((fHeight * 0.5f) - 0.5f),
										fWidth, fHeight,
										0.0f, CVector4(1.0f, 1.0f, 1.0f, valueIntensity.GetValue()),
										UtilGL::States::BLEND_SRCALPHA, UtilGL::States::BLEND_INVSRCALPHA);

	// Store accumulation

	m_pTexture->CopyFromFramebuffer(0, 0, 0, 0, m_pTexture->GetWidth(), m_pTexture->GetHeight());

	// Restore demo viewport

	pDemo->SetDemoViewport();

	// Clear framebuffer

	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);

	return true;
}
예제 #13
0
// Draw-функция
int DrawCallback(void* Params)
{
    if ( k_MouseClick /*& !look_in_mouse*/ ) {
        k_MouseClick=false;
        myCam->View();
        //FindMousePointer(DEVICER->mouse_x,DEVICER->mouse_y);
    }
myCam->View();
   myWorld->Draw();
    ShowCamInfo(CVector4(0,0,0,1));
    return true;
};
예제 #14
0
	void OnLoading(float fPercentage)
	{
		glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
		glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
		glViewport(0, 90, 800, 420);

		UtilGL::Rendering::DrawCenteredQuad(m_pTexLoading,
									0.5f, 0.5f, 1.28f, 1.219f,
									0.0f, CVector4(1.0f, 1.0f, 1.0f, 1.0f),
									UtilGL::States::BLEND_ONE, UtilGL::States::BLEND_ZERO);

		float fWidth = 0.19875f;

		UtilGL::Rendering::DrawRect(NULL,
									0.4f, 0.75, fWidth * fPercentage * 0.01f, 0.007142857f,
									0.0f, CVector4(0.0f, 0.0f, 0.0f, 1.0f),
									UtilGL::States::BLEND_ONE, UtilGL::States::BLEND_ZERO);

		glFinish();
		SwapBuffers(this->GetHDC());
	}
예제 #15
0
/*!
* @brief	ポイントライトの位置を更新。
*/
void EnemyTest::UpdatePointLightPosition()
{
	if (isPointLightOn) {
		pointLightColor.Set(0.9f, 0.75f, 0.6f, 1.0f);
	}
	else {
		pointLightColor = CVector4(0.0f, 0.0f, 0.0f, 0.0f);
	}
	light.SetPointLightColor(pointLightColor);
	pointLightPosition = toLampLocalPos;
	CMatrix mWorld = skinModel.GetWorldMatrix();
	mWorld.Mul(pointLightPosition);
	light.SetPointLightPosition(pointLightPosition);
}
예제 #16
0
    // 平面を設定.
    void CPlane::Set(const SVector4& normal, IZ_FLOAT _d)
    {
        SVector4::Copy(nml, normal);

        nml.w = 0.0f;
        SVector4::Normalize(nml, nml);

        d = _d;

        // 平面の基準位置を計算する
        // => 原点からの法線方向へのレイとの交点を計算する
        CRay ray(
            CVector4(0.0f, 0.0f, 0.0f),
            nml);
        GetIntersectPoint(ray, this->pt);
    }
	// Basic Constructor.
	CSceneManager::CSceneManager()
	{
		m_pRender = NULL;
		m_pRenderDevice = new CRenderDevice();

		m_NumTemplates = 0;
		m_NumModels = 0;

		m_ClearColour = CVector4( 0.0f, 0.0f, 0.0f, 0.0f );

		// Insert Placeholders for the future implementation of the model + template creation.
		CTemplate* baseTemplate = new CTemplate( m_NumTemplates++ );
		CModel* baseModel = new CModel( m_NumModels, baseTemplate->GetUID() );
		m_TemplateList.push_back( baseTemplate );
		m_ModelList.insert( pair< TUInt32, TUInt32 >( m_NumModels++, baseTemplate->GetUID() ) );
	}
예제 #18
0
//--------------------------------------------------------------------------------------------------------------------
void RDX11RenderHelper::RenderLine( CVertexPC* pVetex, int count)
{
	SetWorldTM( XMMatrixIdentity() );

	CVertexPC v1;
	v1.color = COLOR_RED;

	for( int i=0; i < count; ++i)
		m_LineVertices.Add( pVetex[i]);

	// Set Line Shader
	GLOBAL::ShaderMgr()->Begin(SHADER_POS_VS, SHADER_COLOR_PS);
	CVector4 color = CVector4(0,1,1,1);
	GLOBAL::ShaderMgr()->SetShaderConstant( &color, sizeof(color), 9, VERTEX_SHADER);
	GLOBAL::RenderStateMgr()->SetDepthStancil(DEPTH_OFF_STENCIL_OFF);
	
	DrawLine();
}
예제 #19
0
    // 線分と交差する点を取得.
    IZ_BOOL CPlane::GetIntersectPoint(
        const SVector4& from,
        const SVector4& to,
        SVector4& refPtr,
        IZ_FLOAT* retRayCoefficient/*= IZ_NULL*/) const
    {
        if ((IsPositive(from) && !IsPositive(to))
            || (!IsPositive(from) && IsPositive(to)))
        {
            // 二つの点は面の正負のそれぞれにないといけない
            CRay ray(
                from,
                CVector4(to, from, CVector4::INIT_SUB));

            IZ_BOOL ret = GetIntersectPoint(ray, refPtr, retRayCoefficient);
            return ret;
        }

        return IZ_FALSE;
    }
예제 #20
0
void CSurface::Init(char* filename)
{
	Gdiplus::GdiplusStartupInput startupInput;
	ULONG_PTR token;
	GdiplusStartup(&token, &startupInput, NULL);

	int len = strlen(filename);
	wchar_t* temp = new wchar_t[len + 1];
	for (int i = 0; i < len; i++)
	{
		temp[i] = filename[i];
	}
	temp[len] = '\0';
	Gdiplus::Bitmap bitmap(temp);
	Gdiplus::Color pixel;

	if (bitmap.GetWidth() <= 0)
		return;
	if (bitmap.GetHeight() <= 0)
		return;

	m_width = bitmap.GetWidth();
	m_height = bitmap.GetHeight();

	m_pPixels = new CVector4[m_width * m_height];

	for (int x = 0; x < m_width; x++)
	{
		for (int y = 0; y < m_height; y++)
		{
			bitmap.GetPixel(x, y, &pixel);
			m_pPixels[x + y * m_width] = CVector4(pixel.GetR(), pixel.GetG(), pixel.GetB(), pixel.GetA());
		}
	}

	if (!m_pPixels)
		return;

	STRING::Copy(m_pFilename, filename);
}
예제 #21
0
파일: vector4.hpp 프로젝트: kfazi/Engine
		/**
		 * Vector division by a scalar.
		 */
		template<typename TType> friend CVector4 operator / (const CVector4 &cVector, TType tScalar)
		{
			return CVector4(cVector) / tScalar;
		}
예제 #22
0
cOneParameter cMorph::Akima(int const key, double const factor, bool const angular)
{
	int k1, k2, k3, k4, k5, k6;

	if (key >= 2) k1 = key - 2;
	else k1 = 0;

	if (key >= 1) k2 = key - 1;
	else k2 = 0;

	k3 = key;

	if (key < dataSets.size() - 1) k4 = key + 1;
	else k4 = dataSets.size() - 1;

	if (key < dataSets.size() - 2) k5 = key + 2;
	else k5 = dataSets.size() - 1;

	if (key < dataSets.size() - 3) k6 = key + 3;
	else k6 = dataSets.size() - 1;

	cOneParameter interpolated = dataSets[key].parameter;
	cMultiVal val;

	switch (dataSets[key].parameter.GetValueType())
	{
		case typeNull:
		case typeString:
		case typeBool:
			return None(key);

		case typeDouble:
		case typeInt:
		{
			double v1, v2, v3, v4, v5, v6;
			dataSets[k1].parameter.GetMultival(valueActual).Get(v1);
			dataSets[k2].parameter.GetMultival(valueActual).Get(v2);
			dataSets[k3].parameter.GetMultival(valueActual).Get(v3);
			dataSets[k4].parameter.GetMultival(valueActual).Get(v4);
			dataSets[k5].parameter.GetMultival(valueActual).Get(v5);
			dataSets[k6].parameter.GetMultival(valueActual).Get(v6);
			val.Store(AkimaInterpolate(factor, v1, v2, v3, v4, v5, v6, angular));
			break;
		}
		case typeRgb:
		{
			sRGB v1, v2, v3, v4, v5, v6;
			dataSets[k1].parameter.GetMultival(valueActual).Get(v1);
			dataSets[k2].parameter.GetMultival(valueActual).Get(v2);
			dataSets[k3].parameter.GetMultival(valueActual).Get(v3);
			dataSets[k4].parameter.GetMultival(valueActual).Get(v4);
			dataSets[k5].parameter.GetMultival(valueActual).Get(v5);
			dataSets[k6].parameter.GetMultival(valueActual).Get(v6);
			val.Store(sRGB(AkimaInterpolate(factor, v1.R, v2.R, v3.R, v4.R, v5.R, v6.R, angular),
										 AkimaInterpolate(factor, v1.G, v2.G, v3.G, v4.G, v5.G, v6.G, angular),
										 AkimaInterpolate(factor, v1.B, v2.B, v3.B, v4.B, v5.B, v6.B, angular)));
			break;
		}
		case typeVector3:
		{
			CVector3 v1, v2, v3, v4, v5, v6;
			dataSets[k1].parameter.GetMultival(valueActual).Get(v1);
			dataSets[k2].parameter.GetMultival(valueActual).Get(v2);
			dataSets[k3].parameter.GetMultival(valueActual).Get(v3);
			dataSets[k4].parameter.GetMultival(valueActual).Get(v4);
			dataSets[k5].parameter.GetMultival(valueActual).Get(v5);
			dataSets[k6].parameter.GetMultival(valueActual).Get(v6);
			val.Store(CVector3(AkimaInterpolate(factor, v1.x, v2.x, v3.x, v4.x, v5.x, v6.x, angular),
												 AkimaInterpolate(factor, v1.y, v2.y, v3.y, v4.y, v5.y, v6.y, angular),
												 AkimaInterpolate(factor, v1.z, v2.z, v3.z, v4.z, v5.z, v6.z, angular)));
			break;
		}
		case typeVector4:
		{
			CVector4 v1, v2, v3, v4, v5, v6;
			dataSets[k1].parameter.GetMultival(valueActual).Get(v1);
			dataSets[k2].parameter.GetMultival(valueActual).Get(v2);
			dataSets[k3].parameter.GetMultival(valueActual).Get(v3);
			dataSets[k4].parameter.GetMultival(valueActual).Get(v4);
			dataSets[k5].parameter.GetMultival(valueActual).Get(v5);
			dataSets[k6].parameter.GetMultival(valueActual).Get(v6);
			val.Store(CVector4(AkimaInterpolate(factor, v1.x, v2.x, v3.x, v4.x, v5.x, v6.x, angular),
												 AkimaInterpolate(factor, v1.y, v2.y, v3.y, v4.y, v5.y, v6.y, angular),
												 AkimaInterpolate(factor, v1.z, v2.z, v3.z, v4.z, v5.z, v6.z, angular),
												 AkimaInterpolate(factor, v1.w, v2.w, v3.w, v4.w, v5.w, v6.w, angular)));
			break;
		}
		case typeColorPalette:
		{
			cColorPalette v1, v2, v3, v4, v5, v6;
			cColorPalette out;
			dataSets[k1].parameter.GetMultival(valueActual).Get(v1);
			dataSets[k2].parameter.GetMultival(valueActual).Get(v2);
			dataSets[k3].parameter.GetMultival(valueActual).Get(v3);
			dataSets[k4].parameter.GetMultival(valueActual).Get(v4);
			dataSets[k5].parameter.GetMultival(valueActual).Get(v5);
			dataSets[k6].parameter.GetMultival(valueActual).Get(v6);
			for (int i = 0; i < v1.GetSize(); i++)
			{
				out.AppendColor(sRGB(AkimaInterpolate(factor,
																							v1.GetColor(i).R,
																							v2.GetColor(i).R,
																							v3.GetColor(i).R,
																							v4.GetColor(i).R,
																							v5.GetColor(i).R,
																							v6.GetColor(i).R,
																							angular),
														 AkimaInterpolate(factor,
																							v1.GetColor(i).G,
																							v2.GetColor(i).G,
																							v3.GetColor(i).G,
																							v4.GetColor(i).G,
																							v5.GetColor(i).G,
																							v6.GetColor(i).G,
																							angular),
														 AkimaInterpolate(factor,
																							v1.GetColor(i).B,
																							v2.GetColor(i).B,
																							v3.GetColor(i).B,
																							v4.GetColor(i).B,
																							v5.GetColor(i).B,
																							v6.GetColor(i).B,
																							angular)));
			}
			val.Store(out);
			break;
		}
	}

	interpolated.SetMultival(val, valueActual);
	return interpolated;
}
예제 #23
0
// --[  Method  ]---------------------------------------------------------------
//
//  - Class     : CStravaganzaMaxTools
//
//  - prototype : CVector4 ColorToVector4(Color& col, float fAlpha = 1.0f)
//
//  - Purpose   : Transforms a Color from MAX into our own CVector4 type.
//
// -----------------------------------------------------------------------------
CVector4 CStravaganzaMaxTools::ColorToVector4(Color& col, float fAlpha)
{
	return CVector4(col.r, col.g, col.b, fAlpha);
}
예제 #24
0
파일: vector4.hpp 프로젝트: kfazi/Engine
		/**
		 * A multiplication of two vectors.
		 */
		inline friend const CVector4 operator * (const CVector4 &cVector1, const CVector4 &cVector2)
		{
			return CVector4(cVector1) *= cVector2;
		}
예제 #25
0
cOneParameter cMorph::Linear(const int key, const double factor, const bool angular)
{
	int k1, k2;
	if (key == dataSets.size() - 1) return dataSets[key].parameter;

	cOneParameter interpolated = dataSets[key].parameter;
	cMultiVal val;

	k1 = key;
	k2 = key + 1;

	switch (dataSets[key].parameter.GetValueType())
	{
		case typeNull:
		case typeString:
		case typeBool:
			return None(key);

		case typeDouble:
		case typeInt:
		{
			double v1, v2;
			dataSets[k1].parameter.GetMultival(valueActual).Get(v1);
			dataSets[k2].parameter.GetMultival(valueActual).Get(v2);
			val.Store(LinearInterpolate(factor, v1, v2, angular));
			break;
		}
		case typeRgb:
		{
			sRGB v1, v2;
			dataSets[k1].parameter.GetMultival(valueActual).Get(v1);
			dataSets[k2].parameter.GetMultival(valueActual).Get(v2);
			val.Store(sRGB(LinearInterpolate(factor, v1.R, v2.R, angular),
										 LinearInterpolate(factor, v1.G, v2.G, angular),
										 LinearInterpolate(factor, v1.B, v2.B, angular)));
			break;
		}
		case typeVector3:
		{
			CVector3 v1, v2;
			dataSets[k1].parameter.GetMultival(valueActual).Get(v1);
			dataSets[k2].parameter.GetMultival(valueActual).Get(v2);
			val.Store(CVector3(LinearInterpolate(factor, v1.x, v2.x, angular),
												 LinearInterpolate(factor, v1.y, v2.y, angular),
												 LinearInterpolate(factor, v1.z, v2.z, angular)));
			break;
		}
		case typeVector4:
		{
			CVector4 v1, v2;
			dataSets[k1].parameter.GetMultival(valueActual).Get(v1);
			dataSets[k2].parameter.GetMultival(valueActual).Get(v2);
			val.Store(CVector4(LinearInterpolate(factor, v1.x, v2.x, angular),
												 LinearInterpolate(factor, v1.y, v2.y, angular),
												 LinearInterpolate(factor, v1.z, v2.z, angular),
												 LinearInterpolate(factor, v1.w, v2.w, angular)));
			break;
		}
		case typeColorPalette:
		{
			cColorPalette v1, v2;
			cColorPalette out;
			dataSets[k1].parameter.GetMultival(valueActual).Get(v1);
			dataSets[k2].parameter.GetMultival(valueActual).Get(v2);
			for (int i = 0; i < v1.GetSize(); i++)
			{
				out.AppendColor(sRGB(LinearInterpolate(factor, v1.GetColor(i).R, v2.GetColor(i).R, angular),
														 LinearInterpolate(factor, v1.GetColor(i).G, v2.GetColor(i).G, angular),
														 LinearInterpolate(factor,
																							 v1.GetColor(i).B,
																							 v2.GetColor(i).B,
																							 angular)));
			}
			val.Store(out);
			break;
		}
	}

	interpolated.SetMultival(val, valueActual);
	return interpolated;
}
예제 #26
0
void MapChip::Init(const std::vector<SMapChipLocInfo*>& mapChipLocInfoList)
{
	//まずはスキンモデルをロード。
	char modelPath[1024];
	sprintf(modelPath, "Assets/modelData/%s.X", mapChipLocInfoList[0]->modelName);
	SkinModelDataResources().Load(skinModelData, modelPath, NULL, true, (int)mapChipLocInfoList.size());
	skinModel.Init(skinModelData.GetBody());
	skinModel.SetLight(&light);
	skinModel.SetShadowCasterFlag(true);
	skinModel.SetShadowReceiverFlag(true);
	char filePath[256];
	const std::vector<CSkinModelMaterial*> materials = skinModelData.GetBody()->GetSkinModelMaterials();
	specMapList.resize(materials.size());
	normalMapList.resize(materials.size());
	int i = 0;
	for (CSkinModelMaterial* mat : materials) {
		char work[256];
		strcpy(work, mat->GetMaterialName());
		strtok(work, ".");
		sprintf(filePath, "Assets/modelData/%s_n.png", work);
		if (normalMapList[i].Load(filePath)) {
			mat->SetTexture("g_normalTexture", &normalMapList[i]);
			skinModel.SetHasNormalMap(true);
		}
		sprintf(filePath, "Assets/modelData/%s_s.png", work);
		if (specMapList[i].Load(filePath)) {
			mat->SetTexture("g_speculerMap", &specMapList[i]);
			skinModel.SetHasSpeculerMap(true);
		}

		i++;
	}

	//ワールド行列のバッファを作成。
	worldMatrixBuffer.reset(new CMatrix[mapChipLocInfoList.size()]);
	meshCollider.reset(new CMeshCollider[mapChipLocInfoList.size()]);
	rigidBody.reset(new CRigidBody[mapChipLocInfoList.size()]);
	i = 0;
	for (auto& mapChiplLocInfo : mapChipLocInfoList) {
		CMatrix mTrans;
		CVector3 pos = mapChiplLocInfo->pos;

		mTrans.MakeTranslation(pos);
		CMatrix mRot;
		mRot.MakeRotationFromQuaternion(mapChiplLocInfo->rotation);
		worldMatrixBuffer[i].Mul(mRot, mTrans);
		
		i++;
	}
	//行列を更新。
	Update();
	rootBoneMatrix = skinModelData.GetBody()->GetRootBoneWorldMatrix();
	i = 0;
	for (auto& mapChiplLocInfo : mapChipLocInfoList) {
		CMatrix mWorld;
		mWorld.Mul(*rootBoneMatrix, worldMatrixBuffer[i]);
		meshCollider[i].CreateFromSkinModel(&skinModel, &mWorld);
		RigidBodyInfo rbInfo;
		rbInfo.collider = &meshCollider[i];
		rbInfo.mass = 0.0f;
		rigidBody[i].Create(rbInfo);
		PhysicsWorld().AddRigidBody(&rigidBody[i]);
		i++;
	}
	

	light.SetDiffuseLightDirection(0, CVector3(0.707f, 0.0f, -0.707f));
	light.SetDiffuseLightDirection(1, CVector3(-0.707f, 0.0f, -0.707f));
	light.SetDiffuseLightDirection(2, CVector3(0.0f, 0.707f, -0.707f));
	light.SetDiffuseLightDirection(3, CVector3(0.0f, -0.707f, -0.707f));

	light.SetDiffuseLightColor(0, CVector4(0.2f, 0.2f, 0.2f, 1.0f));
	light.SetDiffuseLightColor(1, CVector4(0.2f, 0.2f, 0.2f, 1.0f));
	light.SetDiffuseLightColor(2, CVector4(0.2f, 0.2f, 0.2f, 1.0f));
	light.SetDiffuseLightColor(3, CVector4(0.2f, 0.2f, 0.2f, 1.0f));
	light.SetAmbinetLight(CVector3(0.4f, 0.4f, 0.4f));
	skinModel.SetFogParam(enFogFuncDist, 70.0f, 100.0f);

}
예제 #27
0
void CGameEngine::RenderFrame(int nMilliseconds)
{
	int i;
	// Determine the FPS
	static char szFrameCount[20] = {0};
	static int nTime = 0;
	static int nFrames = 0;
	nTime += nMilliseconds;
	if(nTime >= 1000)
	{
		m_fFPS = (float)(nFrames * 1000) / (float)nTime;
		sprintf(szFrameCount, "%2.2f FPS", m_fFPS);
		nTime = nFrames = 0;
	}
	nFrames++;

	// Move the camera
	HandleInput(nMilliseconds * 0.001f);

	glClearColor(0, 0, 0, 0);
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
	glPushMatrix();
	glLoadMatrixf(m_3DCamera.GetViewMatrix());
	glLightfv(GL_LIGHT0, GL_POSITION, CVector4(m_vLight.x, m_vLight.y, m_vLight.z, 1));
	glDisable(GL_LIGHTING);

	C3DObject obj;
	glMultMatrixf(obj.GetModelMatrix(&m_3DCamera));

	if(m_bShowTexture)
	{
		CTexture t(&m_pbOpticalDepth);
		t.Enable();
		glBegin(GL_QUADS);
		glTexCoord2f(0, 0);
		glVertex3f(-3.0f, 3.0f, 0.0f);
		glTexCoord2f(0, 1);
		glVertex3f(-3.0f, -3.0f, 0.0f);
		glTexCoord2f(1, 1);
		glVertex3f(3.0f, -3.0f, 0.0f);
		glTexCoord2f(1, 0);
		glVertex3f(3.0f, 3.0f, 0.0f);
		glEnd();
		t.Disable();
	}
	else
	{
		// Update the color for the vertices of each sphere
		CVector vCamera = m_3DCamera.GetPosition();
		SVertex *pBuffer = m_sphereInner.GetVertexBuffer();
		for(int i=0; i<m_sphereInner.GetVertexCount(); i++)
		{
			if((vCamera | pBuffer[i].vPos) > 0)		// Cheap optimization: Don't update vertices on the back half of the sphere
				SetColor(&pBuffer[i]);
		}
		pBuffer = m_sphereOuter.GetVertexBuffer();
		for(i=0; i<m_sphereOuter.GetVertexCount(); i++)
		{
			if((vCamera | pBuffer[i].vPos) > 0)		// Cheap optimization: Don't update vertices on the back half of the sphere
				SetColor(&pBuffer[i]);
		}

		// Then draw the two spheres
		m_sphereInner.Draw();
		glFrontFace(GL_CW);
		m_sphereOuter.Draw();
		glFrontFace(GL_CCW);
	}

	glPopMatrix();
	glEnable(GL_LIGHTING);

	// Draw info in the top-left corner
	char szBuffer[256];
	m_fFont.Begin();
	glColor3d(1.0, 1.0, 1.0);
	m_fFont.SetPosition(0, 0);
	m_fFont.Print(szFrameCount);
	m_fFont.SetPosition(0, 15);
/*
	sprintf(szBuffer, "Samples (+/-): %d", m_nSamples);
	m_fFont.Print(szBuffer);
	m_fFont.SetPosition(0, 30);
	sprintf(szBuffer, "Kr (F5/Sh+F5): %-4.4f", m_Kr);
	m_fFont.Print(szBuffer);
	m_fFont.SetPosition(0, 45);
	sprintf(szBuffer, "Km (F6/Sh+F6): %-4.4f", m_Km);
	m_fFont.Print(szBuffer);
	m_fFont.SetPosition(0, 60);
	sprintf(szBuffer, "g (F7/Sh+F7): %-2.2f", m_g);
	m_fFont.Print(szBuffer);
	m_fFont.SetPosition(0, 75);
	sprintf(szBuffer, "ESun (F8/Sh+F8): %-1.1f", m_ESun);
	m_fFont.Print(szBuffer);
	m_fFont.SetPosition(0, 90);
	sprintf(szBuffer, "Red (F9/Sh+F9): %-3.3f", m_fWavelength[0]);
	m_fFont.Print(szBuffer);
	m_fFont.SetPosition(0, 105);
	sprintf(szBuffer, "Green (F10/Sh+F10): %-3.3f", m_fWavelength[1]);
	m_fFont.Print(szBuffer);
	m_fFont.SetPosition(0, 120);
	sprintf(szBuffer, "Blue (F11/Sh+F11): %-3.3f", m_fWavelength[2]);
	m_fFont.Print(szBuffer);
*/
	/*
	for (int i = 0; i < users.getSize(); ++i)
	{
		const nite::UserData& user = users[i];

		sampleViewer->updateUserState(user, userTrackerFrame.getTimestamp());
		if (user.isNew())
		{
			sampleViewer->m_pUserTracker->startSkeletonTracking(user.getId());
			sampleViewer->m_pUserTracker->startPoseDetection(user.getId(), nite::POSE_CROSSED_HANDS);
		}
		else if (!user.isLost())
		{
				sampleViewer->SetRes(depthFrame);
				sampleViewer->DrawStatusLabel(sampleViewer->m_pUserTracker, user); // div by 0
				sampleViewer->DrawCenterOfMass(sampleViewer->m_pUserTracker, user);
				sampleViewer->DrawBoundingBox(user);
				sampleViewer->DrawSkeleton(sampleViewer->m_pUserTracker, user);
		}


	}
	*/


	//m_fFont.Print(sampleViewer->m_error);

	//sampleViewer->Display();
	nite::UserTrackerFrameRef userTrackerFrame;
	openni::VideoFrameRef depthFrame;
	nite::Status rc = sampleViewer->m_pUserTracker->readFrame(&userTrackerFrame);

	
	int skipAmount = int(m_fFPS)*4;		// variable skip depending on the frameRate - constant in human time
	//int skipAmount = 300;

if (rc != nite::STATUS_OK)
	{
		printf("GetNextData failed\n");
		return;
	}

	depthFrame = userTrackerFrame.getDepthFrame();
	const nite::UserMap& userLabels = userTrackerFrame.getUserMap();

	const nite::Array<nite::UserData>& users = userTrackerFrame.getUsers();
	
	
	float x,y,z;
	x = y = z = 0;

	skip++;
	if (skip > 60000)
		skip = 1;


	if (users.getSize() > 0 && skipAmount > 0)
{
		if (jointIdx < 500) {
			jointIdx++;
		}
		else
			jointIdx = 0;

		//user 0 
		const nite::UserData& user = users[0];
		sampleViewer->updateUserState(user, userTrackerFrame.getTimestamp());
		if (user.isNew())
		{
			sampleViewer->m_pUserTracker->startSkeletonTracking(user.getId());
			sampleViewer->m_pUserTracker->startPoseDetection(user.getId(), nite::POSE_CROSSED_HANDS);
		}
		else if (!user.isLost())
		{


		nite::SkeletonJoint jh = users[0].getSkeleton().getJoint(nite::JOINT_HEAD);
		nite::SkeletonJoint jrh = users[0].getSkeleton().getJoint(nite::JOINT_RIGHT_HAND);
			 
		// HEAD
		if (jh.getPositionConfidence() > 0.5f)  {
			x = jh.getPosition().x;	y = jh.getPosition().y;	z = jh.getPosition().z;
			jointHistoryH[jointIdx] = jh;

			if (initial || 	skip%skipAmount ==0) {
				initialH_x = x;
				initialH_z = z;
				initial = false;
				headFront = headBack = headLeft = headRight = false;
			}
		}


		#define RESISTANCE	0.1f	// Damping effect on velocity
		float fThrust = 0.7f;		// Acceleration rate due to thrusters (units/s*s)
		float fSeconds = 1.0f;
		float fSecondsRot = 0.002f;

		int distance = 200;

		if (startFly) {
			m_3DCamera.m_vVelocity;
			if (goingIn)
				m_3DCamera.Rotate(m_3DCamera.GetRightAxis(), fSecondsRot * 1);
			else
				m_3DCamera.Rotate(m_3DCamera.GetRightAxis(), fSecondsRot * -1);
		}

		CVector vAccel(0.0f);
		if (abs(z - initialH_z) > distance) {
			startFly = true;
			if (initialH_z > z) {
				headFront = true;
				goingIn = true;
				vAccel += m_3DCamera.GetViewAxis() * fThrust;
		
			}
			else {
				headBack = true;
				goingIn = false;
				vAccel += m_3DCamera.GetViewAxis() * -fThrust;				
			}

			initialH_z = z;

			m_3DCamera.Accelerate(vAccel, fSeconds, RESISTANCE);

			CVector vPos = m_3DCamera.GetPosition();
			float fMagnitude = vPos.Magnitude();
			if(fMagnitude < m_fInnerRadius)
			{
				vPos *= (m_fInnerRadius * (1 + DELTA)) / fMagnitude;
				m_3DCamera.SetPosition(CDoubleVector(vPos.x, vPos.y, vPos.z));
				m_3DCamera.SetVelocity(-m_3DCamera.GetVelocity());
			}

			t *arg1;
			arg1 = (t *)malloc(sizeof(t));	
			sprintf(arg1->wavFile, "media/space_chord_1.wav");
			_beginthread(	PlayWav, 0, (void*) arg1);
			
		}

		if (abs(x - initialH_x) > 100)
			if (initialH_x > x)
				headRight = true;
			else
				headLeft = true;

		sprintf(szBuffer, "initialH_x: %.1f  x:%.1f ", initialH_x, x);
		m_fFont.Print(szBuffer);


		// RIGHT HAND
		if (jrh.getPositionConfidence() > 0.5f)  {
			x = jrh.getPosition().x;	y = jrh.getPosition().y;	z = jrh.getPosition().z;
			jointHistoryRH[jointIdx] = jrh;

			if (initial || 	skip%skipAmount ==0)  {
				initialRH_x = x;
				initialRH_z = z;
				initial = false;
				handLeft = handRight = false;
			}
		}	

		if (abs(x - initialRH_x) < 100)
			if (initialRH_x > x)
				handRight = true;
			else
				handLeft  = true;
	}

	}
	

	//PlayWav(WHITE_WAVE_FILE);

	m_fFont.SetPosition(0, 30);
	sprintf(szBuffer, "initialH_z: %.1f  z:%.1f   ", initialH_z, z);
	m_fFont.Print(szBuffer);

	m_fFont.SetPosition(0, 45);	
	//sprintf(szBuffer, "Users: %d  hf:%d hb:%d hl:%d hr:%d hal:%d har:%d skAmount: %d    v: %.3f ", users.getSize(), headFront, headBack, headLeft, headRight, handLeft, handRight, skipAmount, m_3DCamera.m_vVelocity.Magnitude());
	sprintf(szBuffer, "Users: %d  hf:%d hb:%d   v: %.3f ", users.getSize(), headFront, headBack, m_3DCamera.m_vVelocity.Magnitude());
	m_fFont.Print(szBuffer);

	m_fFont.SetPosition(0, 60);	
//	m_fFont.Print(g_ALError);


	m_fFont.End();
	glFlush();



}
bool CFXTransExplodingCubes::LoadData(CResourceList* pResourceList)
{
	// Create RTT Texture

	CVarInt::CValueInt valueInt;

	EvaluateVar("RenderTex Width",  0.0f, &valueInt);
	if(valueInt.GetValue() < 1) valueInt.SetValue(1);
	int nWidthPwr = MYROUND(log10f(valueInt.GetValue()) / log10f(2));

	EvaluateVar("RenderTex Height", 0.0f, &valueInt);
	if(valueInt.GetValue() < 1) valueInt.SetValue(1);
	int nHeightPwr = MYROUND(log10f(valueInt.GetValue()) / log10f(2));

	int nWidth  = pow(2, nWidthPwr);
	int nHeight = pow(2, nHeightPwr);

	UtilGL::Texturing::STexLoadOptions texOptions;
	texOptions.SetDefaults();
	texOptions.eFilter = UtilGL::Texturing::FILTER_LINEAR;

	m_textureRTT.LoadFlat(nWidth, nHeight, CVector4(0.0f, 0.0f, 0.0f, 1.0f), false, false, &texOptions);

	// Create cubes

	CVarInt::CValueInt     valueXCubes;
	CVarInt::CValueInt     valueYCubes;
	CVarInt::CValueInt     valueSeed;
	CVarFloat::CValueFloat valueAngleMultiple;
	CVarFloat::CValueFloat valueDepth;
	CVarFloat::CValueFloat valueAngleStep;

	CVarFloat::CValueFloat valueAccelX;
	CVarFloat::CValueFloat valueAccelY;
	CVarFloat::CValueFloat valueAccelZ;
	CVarFloat::CValueFloat valueSpeedX;
	CVarFloat::CValueFloat valueSpeedY;
	CVarFloat::CValueFloat valueSpeedZ;
	CVarFloat::CValueFloat valueAssimetry;
	CVarFloat::CValueFloat valueMaxRotation;
	CVarFloat::CValueFloat valueVariation;

	EvaluateVar("X Cubes",        0.0f, &valueXCubes);
	EvaluateVar("Y Cubes",        0.0f, &valueYCubes);
	EvaluateVar("Seed",		      0.0f, &valueSeed);
	EvaluateVar("Z Depth",        0.0f, &valueDepth);
	EvaluateVar("Angle Step",     0.0f, &valueAngleStep);
	EvaluateVar("Accel X",        0.0f, &valueAccelX);
	EvaluateVar("Accel Y",        0.0f, &valueAccelY);
	EvaluateVar("Accel Z",        0.0f, &valueAccelZ);
	EvaluateVar("Start Speed X",  0.0f, &valueSpeedX);
	EvaluateVar("Start Speed Y",  0.0f, &valueSpeedY);
	EvaluateVar("Start Speed Z",  0.0f, &valueSpeedZ);
	EvaluateVar("Assimetry",      0.0f, &valueAssimetry);
	EvaluateVar("Max Rotation",   0.0f, &valueMaxRotation);
	EvaluateVar("Variation",      0.0f, &valueVariation);

	CVector3 v3Accel(valueAccelX.GetValue(), valueAccelY.GetValue(), valueAccelZ.GetValue());
	CVector3 v3Speed(valueSpeedX.GetValue(), valueSpeedY.GetValue(), valueSpeedZ.GetValue());

	int xRes = valueXCubes.GetValue() > 1 ? valueXCubes.GetValue() : 1;
	int yRes = valueYCubes.GetValue() > 1 ? valueYCubes.GetValue() : 1;

	float fSizeX = 1.0f / xRes;
	float fSizeY = 1.0f / yRes;

	srand(valueSeed.GetValue());

	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
	gluPerspective(60.0f, 1.33f, 1.0f, 100.0f);

	UtilGL::Transforming::ClearMatrix(UtilGL::Transforming::MATRIX_WORLD);
	UtilGL::Transforming::ClearMatrix(UtilGL::Transforming::MATRIX_VIEW);

	for(int y = 0; y < yRes; y++)
	{
		for(int x = 0; x < xRes; x++)
		{
			SCube cube;

			cube.fU  = x * fSizeX;
			cube.fV  = 1.0f - (y * fSizeY);
			cube.fU2 = x * fSizeX + fSizeX;
			cube.fV2 = 1.0f - (y * fSizeY + fSizeY);

			CVector3 upLeft  (x * fSizeX,          y * fSizeY,          0.5f);
			CVector3 botRight(x * fSizeX + fSizeX, y * fSizeY + fSizeY, 0.5f);

			UtilGL::Transforming::NormViewportToLocal(&upLeft);
			UtilGL::Transforming::NormViewportToLocal(&botRight);

			float fHalfX = (botRight.X() - upLeft.X()) * 0.5f;
			float fHalfY = (botRight.Y() - upLeft.Y()) * 0.5f;
			float fHalfZ = valueDepth.GetValue() * 0.5f;

			cube.v1.Set(-fHalfX, -fHalfY, +fHalfZ);
			cube.v2.Set(-fHalfX, +fHalfY, +fHalfZ);
			cube.v3.Set(+fHalfX, +fHalfY, +fHalfZ);
			cube.v4.Set(+fHalfX, -fHalfY, +fHalfZ);
			cube.v5.Set(-fHalfX, -fHalfY, -fHalfZ);
			cube.v6.Set(-fHalfX, +fHalfY, -fHalfZ);
			cube.v7.Set(+fHalfX, +fHalfY, -fHalfZ);
			cube.v8.Set(+fHalfX, -fHalfY, -fHalfZ);

			cube.v3Center.Set(	(x * fSizeX) + (fSizeX * 0.5f),
								(y * fSizeY) + (fSizeY * 0.5f),
								0.5f);

			cube.v3Accel    = v3Accel * ComputeRandWithVariation(1.0f, valueVariation.GetValue()) * ((botRight.Y() - upLeft.Y()) * xRes);
			cube.v3Speed    = v3Speed * ComputeRandWithVariation(1.0f, valueVariation.GetValue()) * ((botRight.Y() - upLeft.Y()) * xRes);

			cube.fStartTime = (MYFABSF(x - (xRes / 2.0f)) / (float)(xRes / 2.0f)) * valueAssimetry.GetValue();
			cube.fRotation  = ComputeRand(0.0f, valueMaxRotation.GetValue());

			UtilGL::Transforming::NormViewportToLocal(&cube.v3Center);

			cube.fTStart = 0.0f;
			cube.fTEnd   = 1.0f;

			m_vecCubes.push_back(cube);
		}
	}

	return true;
}
예제 #29
0
// --[  Method  ]---------------------------------------------------------------
//
//  - Class     : CStravaganzaMaxTools
//
//  - prototype : bool BuildShaders()
//
//  - Purpose   : Builds the shader list from MAX's materials.
//                Preview mode requires texture files to be stored with full
//                path in order to load them. When we export, we only store the
//                filename. Another thing is that in the export mode, we copy
//                all textures into the path specified by the user if that
//                option is checked.
//
// -----------------------------------------------------------------------------
bool CStravaganzaMaxTools::BuildShaders()
{
	std::vector<Mtl*>::iterator it;

	assert(m_vecShaders.empty());

	if(!m_bPreview && m_bCopyTextures && m_strTexturePath == "")
	{
		CLogger::NotifyWindow("Textures won't be copied\nSpecify a valid output texture path first");
	}

	LOG.Write("\n\n-Building shaders: ");

	for(it = m_vecMaterials.begin(); it != m_vecMaterials.end(); ++it)
	{
		Mtl* pMaxMaterial = *it;
		assert(pMaxMaterial);

		LOG.Write("\n    %s", pMaxMaterial->GetName().data());
		CShaderStandard* pShaderStd = new CShaderStandard;
		pShaderStd->SetName(pMaxMaterial->GetName().data());

		// Properties

		StdMat2 *pMaxStandardMtl = NULL;
		StdMat2 *pMaxBakedMtl    = NULL;

		float fAlpha;

		if(pMaxMaterial->ClassID() == Class_ID(DMTL_CLASS_ID, 0))
		{
			pMaxStandardMtl = (StdMat2 *)pMaxMaterial;
		}
		else if(pMaxMaterial->ClassID() == Class_ID(BAKE_SHELL_CLASS_ID, 0))
		{
			pMaxStandardMtl = (StdMat2 *)pMaxMaterial->GetSubMtl(0);
			pMaxBakedMtl    = (StdMat2 *)pMaxMaterial->GetSubMtl(1);
		}

		if(pMaxStandardMtl)
		{
			// Standard material

			fAlpha = pMaxStandardMtl->GetOpacity(0);

			Shader* pMaxShader = pMaxStandardMtl->GetShader();

			CVector4 v4Specular = ColorToVector4(pMaxStandardMtl->GetSpecular(0), 0.0f) * pMaxShader->GetSpecularLevel(0, 0);

			pShaderStd->SetAmbient  (ColorToVector4(pMaxStandardMtl->GetAmbient(0),  0.0f));
			pShaderStd->SetDiffuse  (ColorToVector4(pMaxStandardMtl->GetDiffuse(0),  fAlpha));
			pShaderStd->SetSpecular (v4Specular);
			pShaderStd->SetShininess(pMaxShader->GetGlossiness(0, 0) * 128.0f);

			if(pMaxStandardMtl->GetTwoSided() == TRUE)
			{
				pShaderStd->SetTwoSided(true);
			}

			// Need to cast to StdMat2 in order to get access to IsFaceted().
			// ¿Is StdMat2 always the interface for standard materials?
			if(((StdMat2*)pMaxStandardMtl)->IsFaceted())
			{
				pShaderStd->SetFaceted(true);
			}

			if(pMaxStandardMtl->GetWire() == TRUE)
			{
				pShaderStd->SetPostWire(true);
				pShaderStd->SetWireLineThickness(pMaxStandardMtl->GetWireSize(0));
			}
		}
		else
		{
			// Material != Standard

			fAlpha = 1.0f; // pMaxMaterial->GetXParency();

			pShaderStd->SetAmbient  (ColorToVector4(pMaxMaterial->GetAmbient(),  0.0f));
			pShaderStd->SetDiffuse  (ColorToVector4(pMaxMaterial->GetDiffuse(),  fAlpha));
			pShaderStd->SetSpecular (CVector4(0.0f, 0.0f, 0.0f, 0.0f));
			pShaderStd->SetShininess(0.0f);
		}

		// Layers

		if(!pMaxStandardMtl)
		{
			m_vecShaders.push_back(pShaderStd);
			continue;
		}

		bool bDiffuseMap32Bits = false;
		StdMat2 *pStandardMtl;

		for(int i = 0; i < 3; i++)
		{
			int nMap;

			pStandardMtl = pMaxStandardMtl;

			// 0 = diffuse, 1 == bump, 2 = lightmap (self illumination slot) or envmap (reflection slot)

			if(i == 0)
			{
				nMap = ID_DI;
			}
			else if(i == 1)
			{
				nMap = ID_BU;

				// If its a baked material, get the bump map from there

				if(pMaxBakedMtl)
				{
					pStandardMtl = pMaxBakedMtl;
				}
			}
			else if(i == 2)
			{
				bool bBaked = false;

				// If its a baked material, get the map2 (lightmap) from there

				if(pMaxBakedMtl)
				{
					if(pMaxBakedMtl->GetMapState(ID_SI) == MAXMAPSTATE_ENABLED)
					{
						bBaked       = true;
						nMap         = ID_SI;
						pStandardMtl = pMaxBakedMtl;
					}
				}

				if(!bBaked)
				{
					if(pStandardMtl->GetMapState(ID_SI) == MAXMAPSTATE_ENABLED)
					{
						nMap = ID_SI;
					}
					else
					{
						nMap = ID_RL;
					}
				}
			}

			// Check validity

			if(pStandardMtl->GetMapState(nMap) != MAXMAPSTATE_ENABLED)
			{
				if(i == 0)
				{
					LOG.Write("\n        No diffuse. Skipping.");
					break;
				}

				continue;
			}

			Texmap* pMaxTexmap = pStandardMtl->GetSubTexmap(nMap);

			if(!pMaxTexmap)
			{
				if(i == 0)
				{
					LOG.Write("\n        No diffuse. Skipping.");
					break;
				}

				continue;
			}

			// Get texmaps

			std::vector<std::string> vecTextures, vecPaths;

			CShaderStandard::SLayerInfo  layerInfo;
			CShaderStandard::SBitmapInfo bitmapInfo;

			if(pMaxTexmap->ClassID() == Class_ID(BMTEX_CLASS_ID, 0))
			{
				BitmapTex* pMaxBitmapTex = (BitmapTex*)pMaxTexmap;
				Bitmap*    pMaxBitmap    = pMaxBitmapTex->GetBitmap(SECONDS_TO_TICKS(m_fStartTime));
				StdUVGen*  pMaxUVGen     = pMaxBitmapTex->GetUVGen();

				if(!pMaxBitmap)
				{
					if(i == 0)
					{
						LOG.Write("\n        Invalid diffuse. Skipping.");
						break;
					}
					continue;
				}

				assert(pMaxUVGen);

				BitmapInfo bi = pMaxBitmap->Storage()->bi;

				// bi.Name() returns the full path
				// bi.Filename() returns just the filename

				vecTextures.push_back(bi.Filename());
				vecPaths.   push_back(bi.Name());

				LOG.Write("\n        Bitmap %s", vecTextures[0].data());

				// Check if diffuse texture has alpha channel

				if(i == 0)
				{
					CBitmap    bitmap;
					CInputFile bitmapFile;

					if(!bitmapFile.Open(bi.Name(), false))
					{
						CLogger::NotifyWindow("WARNING - CStravaganzaMaxTools::BuildShaders():\nUnable to load file %s", bi.Name());
					}
					else
					{
						if(!bitmap.Load(&bitmapFile, GetFileExt(bi.Name())))
						{
							CLogger::NotifyWindow("WARNING - CStravaganzaMaxTools::BuildShaders():\nUnable to load bitmap %s", bi.Name());
						}
						else
						{
							if(bitmap.GetBpp() == 32)
							{
								bDiffuseMap32Bits = true;
								LOG.Write(" (with alpha channel)");
							}
							bitmap.Free();
						}
						bitmapFile.Close();
					}
				}

				// Ok, copy properties

				layerInfo.texInfo.bLoop        = false;
				layerInfo.texInfo.eTextureType = UtilGL::Texturing::CTexture::TEXTURE2D;

				bitmapInfo.strFile         = m_bPreview ? bi.Name() : bi.Filename();
				bitmapInfo.bTile           = ((pMaxUVGen->GetTextureTiling() & (U_WRAP | V_WRAP)) == (U_WRAP | V_WRAP)) ? true : false;
				bitmapInfo.fSeconds        = 0.0f;
				bitmapInfo.bForceFiltering = false;
				bitmapInfo.eFilter         = UtilGL::Texturing::FILTER_TRILINEAR; // won't be used (forcefiltering = false)
				
				layerInfo.texInfo.m_vecBitmaps.push_back(bitmapInfo);

				layerInfo.eTexEnv          = nMap == ID_RL ? CShaderStandard::TEXENV_ADD : CShaderStandard::TEXENV_MODULATE;
				layerInfo.eUVGen           = pMaxUVGen->GetCoordMapping(0) == UVMAP_SPHERE_ENV ? CShaderStandard::UVGEN_ENVMAPPING : CShaderStandard::UVGEN_EXPLICITMAPPING;
				layerInfo.uMapChannel      = pMaxUVGen->GetMapChannel();
				layerInfo.v3ScrollSpeed    = CVector3(0.0f, 0.0f, 0.0f);
				layerInfo.v3RotationSpeed  = CVector3(0.0f, 0.0f, 0.0f);
				layerInfo.v3ScrollOffset   = CVector3(pMaxUVGen->GetUOffs(0), pMaxUVGen->GetVOffs(0), 0.0f);
				layerInfo.v3RotationOffset = CVector3(pMaxUVGen->GetUAng(0),  pMaxUVGen->GetVAng(0),  pMaxUVGen->GetWAng(0));
			}
			else if(pMaxTexmap->ClassID() == Class_ID(ACUBIC_CLASS_ID, 0))
			{
				ACubic*       pMaxCubic  = (ACubic*)pMaxTexmap;
				IParamBlock2* pBlock     = pMaxCubic->pblock;
				Interval      validRange = m_pMaxInterface->GetAnimRange();

				for(int nFace = 0; nFace < 6; nFace++)
				{
					int nMaxFace;

					switch(nFace)
					{
					case 0: nMaxFace = 3; break;
					case 1: nMaxFace = 2; break;
					case 2: nMaxFace = 1; break;
					case 3: nMaxFace = 0; break;
					case 4: nMaxFace = 5; break;
					case 5: nMaxFace = 4; break;
					}

					TCHAR *name;
					pBlock->GetValue(acubic_bitmap_names, TICKS_TO_SECONDS(m_fStartTime), name, validRange, nMaxFace);

					vecPaths.push_back(name);

					CStr path, file, ext;
					SplitFilename(CStr(name), &path, &file, &ext);

					std::string strFile = std::string(file.data()) + ext.data();

					vecTextures.push_back(strFile);

					bitmapInfo.strFile         = m_bPreview ? name : strFile;
					bitmapInfo.bTile           = false;
					bitmapInfo.fSeconds        = 0.0f;
					bitmapInfo.bForceFiltering = false;
					bitmapInfo.eFilter         = UtilGL::Texturing::FILTER_TRILINEAR;
					
					layerInfo.texInfo.m_vecBitmaps.push_back(bitmapInfo);
				}

				layerInfo.texInfo.bLoop        = false;
				layerInfo.texInfo.eTextureType = UtilGL::Texturing::CTexture::TEXTURECUBEMAP;

				layerInfo.eTexEnv          = nMap == ID_RL ? CShaderStandard::TEXENV_ADD : CShaderStandard::TEXENV_MODULATE;
				layerInfo.eUVGen           = CShaderStandard::UVGEN_ENVMAPPING;
				layerInfo.uMapChannel      = 0;
				layerInfo.v3ScrollSpeed    = CVector3(0.0f, 0.0f, 0.0f);
				layerInfo.v3RotationSpeed  = CVector3(0.0f, 0.0f, 0.0f);
				layerInfo.v3ScrollOffset   = CVector3(0.0f, 0.0f, 0.0f);
				layerInfo.v3RotationOffset = CVector3(0.0f, 0.0f, 0.0f);
			}
			else
			{
				if(i == 0)
				{
					LOG.Write("\n        No diffuse. Skipping.");
					break;
				}
				continue;
			}

			if(!m_bPreview && m_bCopyTextures && m_strTexturePath != "")
			{
				for(int nTex = 0; nTex != vecTextures.size(); nTex++)
				{
					// Copy textures into the specified folder

					std::string strDestPath = m_strTexturePath;

					if(strDestPath[strDestPath.length() - 1] != '\\')
					{
						strDestPath.append("\\", 1);
					}

					strDestPath.append(vecTextures[nTex]);

					if(!CopyFile(vecPaths[nTex].data(), strDestPath.data(), FALSE))
					{
						CLogger::NotifyWindow("Unable to copy %s to\n%s", vecPaths[i], strDestPath.data());
					}
				}
			}

			if(layerInfo.eUVGen == CShaderStandard::UVGEN_ENVMAPPING && i == 1)
			{
				CLogger::NotifyWindow("%s : Bump with spheremapping not supported", pShaderStd->GetName().data());
			}
			else
			{
				// Add layer

				switch(i)
				{
				case 0: pShaderStd->SetLayer(CShaderStandard::LAYER_DIFF, layerInfo); break;
				case 1: pShaderStd->SetLayer(CShaderStandard::LAYER_BUMP, layerInfo); break;
				case 2: pShaderStd->SetLayer(CShaderStandard::LAYER_MAP2, layerInfo); break;
				}
			}
		}

		// ¿Do we need blending?

		if(ARE_EQUAL(fAlpha, 1.0f) && !bDiffuseMap32Bits)
		{
			pShaderStd->SetBlendSrcFactor(UtilGL::States::BLEND_ONE);
			pShaderStd->SetBlendDstFactor(UtilGL::States::BLEND_ZERO);
		}
		else
		{
			pShaderStd->SetBlendSrcFactor(UtilGL::States::BLEND_SRCALPHA);
			pShaderStd->SetBlendDstFactor(UtilGL::States::BLEND_INVSRCALPHA);
		}

		// Add shader

		m_vecShaders.push_back(pShaderStd);
	}

	return true;
}
bool CFXTransExplodingCubes::DrawCube(const SCube& cube, float fT)
{
	float fAngle = cube.fRotation * fT;
	
	CVector3 v3Axis(1.0f, 0.0f, 0.0f);
	CVector3 v3Center = cube.v3Center + (cube.v3Speed * fT) + (cube.v3Accel * fT * fT * 0.5f);

	CMatrix mtxRot;
	mtxRot.BuildRotationZ(fAngle);
	mtxRot.Transform(&v3Axis, true);

	CVector2 mapping[4] = { CVector2(cube.fU,  cube.fV),
							CVector2(cube.fU,  cube.fV2),
							CVector2(cube.fU2, cube.fV2),
							CVector2(cube.fU2, cube.fV) };

	CMatrix worldMtx;
	worldMtx.BuildRotation(fAngle, 1.0f, 0.0f, 0.0f);
	worldMtx.Translate    (v3Center.X(), v3Center.Y(), v3Center.Z());

	UtilGL::Transforming::SetMatrix(UtilGL::Transforming::MATRIX_WORLD, worldMtx);

	// front  back
	// 1   4  5  8
	// 2   3  6  7

	m_textureRTT.SetActive();

	UtilGL::States::Set(UtilGL::States::TEXTURE2D, UtilGL::States::ENABLED);
	UtilGL::States::SetColor(CVector4(1.0f, 1.0f, 1.0f, 1.0f));

	glBegin(GL_QUADS);

	glTexCoord2fv(mapping[0].Data()); glVertex3fv(cube.v1.Data());
	glTexCoord2fv(mapping[1].Data()); glVertex3fv(cube.v2.Data());
	glTexCoord2fv(mapping[2].Data()); glVertex3fv(cube.v3.Data());
	glTexCoord2fv(mapping[3].Data()); glVertex3fv(cube.v4.Data());

	glTexCoord2fv(mapping[0].Data()); glVertex3fv(cube.v8.Data());
	glTexCoord2fv(mapping[1].Data()); glVertex3fv(cube.v7.Data());
	glTexCoord2fv(mapping[2].Data()); glVertex3fv(cube.v6.Data());
	glTexCoord2fv(mapping[3].Data()); glVertex3fv(cube.v5.Data());

	glEnd();

	UtilGL::States::Set(UtilGL::States::TEXTURE2D, UtilGL::States::DISABLED);
	UtilGL::States::SetColor(m_v4FlatColor);

	glBegin(GL_QUADS);

	// left
	glVertex3fv(cube.v5.Data());
	glVertex3fv(cube.v6.Data());
	glVertex3fv(cube.v2.Data());
	glVertex3fv(cube.v1.Data());

	//right
	glVertex3fv(cube.v4.Data());
	glVertex3fv(cube.v3.Data());
	glVertex3fv(cube.v7.Data());
	glVertex3fv(cube.v8.Data());

	//bottom
	glVertex3fv(cube.v7.Data());
	glVertex3fv(cube.v3.Data());
	glVertex3fv(cube.v2.Data());
	glVertex3fv(cube.v6.Data());

	//top
	glVertex3fv(cube.v5.Data());
	glVertex3fv(cube.v1.Data());
	glVertex3fv(cube.v4.Data());
	glVertex3fv(cube.v8.Data());

	glEnd();
/*
	glLineWidth(1.0f);
	UtilGL::States::SetColor(CVector4(0.0f, 0.0f, 0.0f, 0.0f));
	UtilGL::States::Set(UtilGL::States::POLYGONMODE, UtilGL::States::POLYGONMODE_LINE);

	glBegin(GL_QUADS);

	// left
	glVertex3fv(cube.v5.Data());
	glVertex3fv(cube.v6.Data());
	glVertex3fv(cube.v2.Data());
	glVertex3fv(cube.v1.Data());

	//right
	glVertex3fv(cube.v4.Data());
	glVertex3fv(cube.v3.Data());
	glVertex3fv(cube.v7.Data());
	glVertex3fv(cube.v8.Data());

	//bottom
	glVertex3fv(cube.v7.Data());
	glVertex3fv(cube.v3.Data());
	glVertex3fv(cube.v2.Data());
	glVertex3fv(cube.v6.Data());

	//top
	glVertex3fv(cube.v5.Data());
	glVertex3fv(cube.v1.Data());
	glVertex3fv(cube.v4.Data());
	glVertex3fv(cube.v8.Data());

	glEnd();

	UtilGL::States::Set(UtilGL::States::POLYGONMODE, UtilGL::States::POLYGONMODE_FILL);
*/
	return true;
}