示例#1
0
void CMD5Model::PrepareMesh( SMesh* a_Mesh, const SFrameSkeleton& a_Skeleton )
{
	CMatrix4 rotationMatrix;

	for ( Uint i = 0; i < a_Mesh->m_VertexCount; ++i )
	{
		const SVertex vertex = a_Mesh->m_VertexInfo[i];
		CVector3 position;
		CVector3 normal;

		for ( Uint j = 0; j < vertex.m_WeightCount; ++j )
		{
			const SWeight& weight = a_Mesh->m_Weights[vertex.m_StartWeight + j];
			const SSkeletonJoint& joint = a_Skeleton.m_Joints[weight.m_JointID];

			rotationMatrix = CMatrix4( joint.m_Orientation );
			CVector3 rotatedPosition = rotationMatrix.Inverted() * weight.m_Position;
			position += ( joint.m_Position + rotatedPosition ) * weight.m_Bias;
			normal += ( rotationMatrix * vertex.m_Normal ) * weight.m_Bias;
		}

		memcpy( &a_Mesh->m_Vertices[( i * 3 )], position.Cell, sizeof( Float ) * 3 );
		memcpy( &a_Mesh->m_Normals[( i * 3 )], normal.Cell, sizeof( Float ) * 3 );

	}
}
示例#2
0
void CCamera::SetPerspectiveProjection(float fovY, float aspectRatio, float near, float far, HANDEDNESS handedness)
{
	float yScale = 1 / tan(fovY / 2);
	float xScale = yScale / aspectRatio;

	CMatrix4 proj;
	proj.Clear();

	if(handedness == HANDEDNESS_LEFTHANDED)
	{
		proj(0, 0) = xScale;
		proj(1, 1) = yScale;
		proj(2, 2) = far / (far - near);
		proj(3, 3) = 0;

		proj(3, 2) = -near * far / (far - near);
		proj(2, 3) = 1;
	}
	else
	{
		proj(0, 0) = xScale;
		proj(1, 1) = yScale;
		proj(2, 2) = far / (near - far);
		proj(3, 3) = 0;

		proj(3, 2) = near * far / (near - far);
		proj(2, 3) = -1;
	}

	m_projMatrix = proj;
}
示例#3
0
void CMD5Model::PrepareMesh( SMesh* a_Mesh )
{
	a_Mesh->m_Vertices = new Float[ a_Mesh->m_VertexCount * 3 ];
	a_Mesh->m_UVs = new Float[ a_Mesh->m_VertexCount << 1 ];

	CMatrix4 rotationMatrix;

	for ( Uint i = 0; i < a_Mesh->m_VertexCount; ++i )
	{
		CVector3 finalPosition;
		SVertex vertex = a_Mesh->m_VertexInfo[i];

		for ( Uint j = 0; j < vertex.m_WeightCount; ++j )
		{
			SWeight weight = a_Mesh->m_Weights[vertex.m_StartWeight + j ];
			SJoint joint = m_Joints[weight.m_JointID];

			rotationMatrix = CMatrix4( joint.m_Orientation );
			//Convert the weight position from bone space to model space
			CVector3 rotationPosition = rotationMatrix.Inverted() * weight.m_Position;
			finalPosition += ( joint.m_Position + rotationPosition ) * weight.m_Bias;
		}

		memcpy( &a_Mesh->m_Vertices[( i * 3 )], finalPosition.Cell, sizeof( Float ) * 3 );
		memcpy( &a_Mesh->m_UVs[( i * 2 )], vertex.m_UV.Cell, sizeof( Float ) * 2 );
	}
}
CMatrix4 CRenderableQueueMember::getLastTransformMatrix() const {
    CMatrix4 m;

	mLastOrientation.toRotationMatrix(m);
	m.setTransform(mLastPosition);

	return m;
}
void IARManager::translate_nodes(ARUint8 *dataPtr)
{
	const int thresh = 100;
	ARMarkerInfo *marker_info;
	int marker_num;
	int p;
	
	//check
	if(!this->patt_loaded) return;
	
	//run ARTK's detection function
	arDetectMarker(dataPtr, thresh, &marker_info, &marker_num);
	
	//check each pattern
	for(p=0; p < this->patt_loaded; p++)
	{
		int i,j,k;
		double gl_para[16];
		float glf_para[16];
		CMatrix4<float> mat;
		double patt_width = 80.0;
		double patt_center[2] = {0.0, 0.0};
		double patt_trans[3][4];
		
		//find most visible detection of this pattern
		for(k=-1,j=0; j < marker_num; j++ ) 
			if( patt_id[p] == marker_info[j].id ) 
			{
				if(k==-1) k = j;
				else if(marker_info[k].cf < marker_info[j].cf) k = j;
			}
			
		//was it found?
		if(k == -1)
		{
			patt_node[p]->setVisible(false);
			continue;
		}
		
		//begin the matrix process
		arGetTransMat(&marker_info[k], patt_center, patt_width, patt_trans);
		
		this->our_convert_trans_para(patt_trans, gl_para);
		for(i=0;i<16;i++) glf_para[i] = (float)gl_para[i];
		
		mat.setM(glf_para);
	
		//vector3d<f32> scale_vec = mat.getScale();
		vector3d<f32> rot_vec = mat.getRotationDegrees();
		vector3d<f32> pos_vec = mat.getTranslation();
		
		rot_vec.X -= 90;
		
		patt_node[p]->setRotation(rot_vec);
		patt_node[p]->setPosition(pos_vec);
		patt_node[p]->setVisible(true);
	}
}
CMatrix4 CRenderableQueueMember::getInverseTransformMatrix() const {
	CMatrix4 m;

	CQuaternion q = mOrientation;
	q.invert();
	q.toRotationMatrix(m);
	m.setTransform(-mPosition);

	return m;
}
示例#7
0
文件: Model.cpp 项目: bananu7/Engine
void CModel::Draw(const CVector3& pos, const CVector3& rot, const CVector3& scale) const
{
	CMatrix4 PMat = CCamera::CreateTranslation(pos.X, pos.Y, pos.Z);
	CMatrix4 RMat = CCamera::CreateRotation(rot.X, rot.Y, rot.Z);
	CMatrix4 SMat = CCamera::CreateScale(scale.X, scale.Y, scale.Z);
	PMat.Mult(RMat);
	PMat.Mult(SMat);
	Shader->SetUniformMatrix4("ModelMatrix", PMat);
	Draw();
}
示例#8
0
void CCamera::SetOrthoProjection(float width, float height, float near, float far)
{
	CMatrix4 proj;
	proj.Clear();

	proj(0, 0) =  2.0f / width;
	proj(1, 1) =  2.0f / height;
	proj(2, 2) =  1.0f / (far - near);
	proj(3, 3) = 1;

	proj(3, 2) = near / (near - far);

	m_projMatrix = proj;
}
示例#9
0
/* ----------------------------------------------------------------------------
make the camera display an orthagonal view
*/
void DLL_EXPORT IrrSetCameraOrthagonal( ICameraSceneNode* camera, f32 x, f32 y, f32 z )
{
    CMatrix4<f32> projectionMatrix;
    vector3d<f32> camDistance( x,y,z );

    f32 viewScale = camDistance.getLength();

    // calculate the orthagonal projection matrix
    projectionMatrix.buildProjectionMatrixOrthoLH(
            viewScale * camera->getAspectRatio(), viewScale,
            camera->getNearValue(), camera->getFarValue());

    // set the cameras projection matrix to this orthaonal construct
    camera->setProjectionMatrix(projectionMatrix, true);
}
示例#10
0
CMatrix4 CMatrix4::Inverse(const CMatrix4& m, float* determinant)
{
    const float det = m.Determinant();

    if(determinant)
        *determinant = det;

    if(almost_equals(0.0f, std::abs(det), 1))
        return CMatrix4::IDENTITY;

    // 余因子行列を求める.
    CMatrix4 adjugate;
    adjugate.m11 = m.m22 * (m.m33 * m.m44 - m.m34 * m.m43) + m.m23 * (m.m34 * m.m42 - m.m32 * m.m44) + m.m24 * (m.m32 * m.m43 - m.m33 * m.m42);
    adjugate.m21 = m.m21 * (m.m34 * m.m43 - m.m33 * m.m44) + m.m23 * (m.m31 * m.m44 - m.m34 * m.m41) + m.m24 * (m.m33 * m.m41 - m.m31 * m.m43);
    adjugate.m31 = m.m21 * (m.m32 * m.m44 - m.m34 * m.m42) + m.m22 * (m.m34 * m.m41 - m.m31 * m.m44) + m.m24 * (m.m31 * m.m42 - m.m32 * m.m41);
    adjugate.m41 = m.m21 * (m.m33 * m.m42 - m.m32 * m.m43) + m.m22 * (m.m31 * m.m43 - m.m33 * m.m41) + m.m23 * (m.m32 * m.m41 - m.m31 * m.m42);

    adjugate.m12 = m.m12 * (m.m34 * m.m43 - m.m33 * m.m44) + m.m13 * (m.m32 * m.m44 - m.m34 * m.m42) + m.m14 * (m.m33 * m.m42 - m.m32 * m.m43);
    adjugate.m22 = m.m11 * (m.m33 * m.m44 - m.m34 * m.m43) + m.m13 * (m.m34 * m.m41 - m.m31 * m.m44) + m.m14 * (m.m31 * m.m43 - m.m33 * m.m41);
    adjugate.m32 = m.m11 * (m.m34 * m.m42 - m.m32 * m.m44) + m.m12 * (m.m31 * m.m44 - m.m34 * m.m41) + m.m14 * (m.m32 * m.m41 - m.m31 * m.m42);
    adjugate.m42 = m.m11 * (m.m32 * m.m43 - m.m33 * m.m42) + m.m12 * (m.m33 * m.m41 - m.m31 * m.m43) + m.m13 * (m.m31 * m.m42 - m.m32 * m.m41);

    adjugate.m13 = m.m12 * (m.m23 * m.m44 - m.m24 * m.m43) + m.m13 * (m.m24 * m.m42 - m.m22 * m.m44) + m.m14 * (m.m22 * m.m43 - m.m23 * m.m42);
    adjugate.m23 = m.m11 * (m.m24 * m.m43 - m.m23 * m.m44) + m.m13 * (m.m21 * m.m44 - m.m24 * m.m41) + m.m14 * (m.m23 * m.m41 - m.m21 * m.m43);
    adjugate.m33 = m.m11 * (m.m22 * m.m44 - m.m24 * m.m42) + m.m12 * (m.m24 * m.m41 - m.m21 * m.m44) + m.m14 * (m.m21 * m.m42 - m.m22 * m.m41);
    adjugate.m43 = m.m11 * (m.m23 * m.m42 - m.m22 * m.m43) + m.m12 * (m.m21 * m.m43 - m.m23 * m.m41) + m.m13 * (m.m22 * m.m41 - m.m21 * m.m42);

    adjugate.m14 = m.m12 * (m.m24 * m.m33 - m.m23 * m.m34) + m.m13 * (m.m22 * m.m34 - m.m24 * m.m32) + m.m14 * (m.m23 * m.m32 - m.m22 * m.m33);
    adjugate.m24 = m.m11 * (m.m23 * m.m34 - m.m24 * m.m33) + m.m13 * (m.m24 * m.m31 - m.m21 * m.m34) + m.m14 * (m.m21 * m.m33 - m.m23 * m.m31);
    adjugate.m34 = m.m11 * (m.m24 * m.m32 - m.m22 * m.m34) + m.m12 * (m.m21 * m.m34 - m.m24 * m.m31) + m.m14 * (m.m22 * m.m31 - m.m21 * m.m32);
    adjugate.m44 = m.m11 * (m.m22 * m.m33 - m.m23 * m.m32) + m.m12 * (m.m23 * m.m31 - m.m21 * m.m33) + m.m13 * (m.m21 * m.m32 - m.m22 * m.m31);
    // 逆行列を求める.
    return (1.0f / det) * adjugate;
}
示例#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 );
	}
}
示例#12
0
void CRendererGL::reshape(int32 width, int32 height)
{
	CMatrix4::orthographic(0.f, 100.f, 0.f, (float)width, 0.f, (float)height, g_Projection);

	glViewport(0, -20, width, height);

	g_ViewportSize[0] = (float)(width);
	g_ViewportSize[1] = (float)(height);

	GLint uniformProjection = glGetUniformLocation(g_DefaultShaderProgram, "proj");
	glUniformMatrix4fv(uniformProjection, 1, GL_FALSE, g_Projection.get());
}
示例#13
0
void CCamera3D::OnTransformed()
{
	m_View = CMatrix4::IDENTY;
		
	CMatrix4 rotate = CMatrix4::IDENTY;

	CNode* node = m_Node;
	node->GetTransform();

	//TODO: Optimize rotation
	CVector3 rot = CVector3(0.0f, 0.0f, node->GetRotation().Z);
	rotate.Rotate(rot);

	m_View *= rotate;

	rot = CVector3(node->GetRotation().X, 0.0f, 0.0f);
	rotate.Rotate(rot);

	m_View *= rotate;

	rot = CVector3(0.0f, node->GetRotation().Y, 0.0f);
	rotate.Rotate(rot);

	m_View *= rotate;

	CMatrix4 translate = CMatrix4::IDENTY;
	translate.Translate(node->GetPosition());

	m_View *= translate;

	CMatrix4 frustum = CMatrix4::IDENTY;

	frustum *= m_Projection;
	frustum *= m_View;

	m_Frustum.Setup(frustum);
}
示例#14
0
	iCamera()
	{
		view_matrix.loadIdentity();
		projection_matrix.loadIdentity();
	}
示例#15
0
void CCamera::LookAt(const CVector3& eye, const CVector3& target, const CVector3& up, HANDEDNESS handedness)
{
	CMatrix4 view;
	view.Clear();

	if(handedness == HANDEDNESS_LEFTHANDED)
	{
		//zaxis = normal(At - Eye)
		//xaxis = normal(cross(Up, zaxis))
		//yaxis = cross(zaxis, xaxis)

		CVector3 axisZ = (target - eye).Normalize();
		CVector3 axisX = (up.Cross(axisZ)).Normalize();
		CVector3 axisY = axisZ.Cross(axisX);

		view(0, 0) = axisX.x;
		view(1, 0) = axisX.y;
		view(2, 0) = axisX.z;
		view(3, 0) = -axisX.Dot(eye);

		view(0, 1) = axisY.x;
		view(1, 1) = axisY.y;
		view(2, 1) = axisY.z;
		view(3, 1) = -axisY.Dot(eye);

		view(0, 2) = axisZ.x;
		view(1, 2) = axisZ.y;
		view(2, 2) = axisZ.z;
		view(3, 2) = -axisZ.Dot(eye);

		view(3, 3) = 1;
	}
	else
	{
		//zaxis = normal(Eye - At)
		//xaxis = normal(cross(Up, zaxis))
		//yaxis = cross(zaxis, xaxis)

		CVector3 axisZ = (eye - target).Normalize();
		CVector3 axisX = (up.Cross(axisZ)).Normalize();
		CVector3 axisY = axisZ.Cross(axisX);

		view(0, 0) = axisX.x;
		view(1, 0) = axisX.y;
		view(2, 0) = axisX.z;
		view(3, 0) = -axisX.Dot(eye);

		view(0, 1) = axisY.x;
		view(1, 1) = axisY.y;
		view(2, 1) = axisY.z;
		view(3, 1) = -axisY.Dot(eye);

		view(0, 2) = axisZ.x;
		view(1, 2) = axisZ.y;
		view(2, 2) = axisZ.z;
		view(3, 2) = -axisZ.Dot(eye);

		view(3, 3) = 1;
	}

	m_viewMatrix = view;
}
示例#16
0
void CParticleSystem::render(CRenderer &r, const CMatrix4 &transform){
    CArrays *a = r.getArrays();
    
    a->mVertexBuffer = mVertexBuffer;
    a->verts.setupBuffer(mVertexBuffer, CVertexBuffer::POSITION);
    a->normals.setupBuffer(mVertexBuffer, CVertexBuffer::NORMAL);
	a->tex_st.setupBuffer(mVertexBuffer, CVertexBuffer::TEX_COORD);

	CMatrix4 invTrans = transform;
	invTrans.invert();

    CMatrix4 &mv = r.getModelViewMatrix();

    // And setup up up,right vectors
    CVector3 up, right, forward, campos, trans;
    up[0] = mv.m[0][0];
	up[1] = mv.m[1][0];
	up[2] = mv.m[2][0];

	right[0] = mv.m[0][1];
	right[1] = mv.m[1][1];
	right[2] = mv.m[2][1];

    forward[0] = mv.m[0][2];
	forward[1] = mv.m[1][2];
	forward[2] = mv.m[2][2];

	// Local camera position
    campos  = invTrans * r.getCamera()->getDerivedPosition();

	trans[0] = mv.m[3][0];
	trans[1] = mv.m[3][1];
	trans[2] = mv.m[3][2];

    U32 count = mParticles.size();
    ParticleList::const_iterator i, pend;
    pend = mParticles.end();

    TParticleVertex *v = mSVertexBuffer;
    for(i = mParticles.begin() ; i != pend ; ++i){
        F32 sizeX = (*i)->mSizeX;
        F32 sizeY = (*i)->mSizeY;
        if(mDef->mParticleType == PARTICLE_BILLBOARD){
            CQuaternion q;
            q.fromAngleAxis(forward, (*i)->mRotation);
            CMatrix3 m;
            q.toRotationMatrix(m);
            CVector3 upR = m * up;
            CVector3 rightR = m * right;

            const CVector3 &color = (*i)->mColor;
            const CVector3 corner = (*i)->mPosition - (upR * sizeY + rightR * sizeX)  * 0.5;
            v->position = corner;
            v->color = color;
            v->texCoord = CTexCoord(0.0,  0.0);
            ++v;
            v->position = corner + upR * sizeY;
            v->color = color;
            v->texCoord = CTexCoord(0.0,  1.0);
            ++v;
            v->position = corner + (upR * sizeY + rightR * sizeX);
            v->color = color;
            v->texCoord = CTexCoord(1.0,1.0);
            ++v;
            v->position = corner + rightR * sizeX;
            v->color = color;
            v->texCoord = CTexCoord(1.0,0.0);
            ++v;
        } else {

            CVector3 upR = (*i)->mVelocity;
			float l = upR.length();
			if(l < 1.0){
				upR /= l;
			}

			CVector3 pos = (*i)->mPosition;
			pos.y += 10.0;

			CVector3 eyevec = campos - pos;
			
            CVector3 rightR = ((*i)->mVelocity ^ eyevec).normalized();
			
            const CVector3 &color = (*i)->mColor;
            const CVector3 corner = pos - (upR * sizeY + rightR * sizeX)  * 0.5;
            v->position = corner;
            v->color = color;
            v->texCoord = CTexCoord(0.0,  0.0);
            ++v;
            v->position = corner + upR * sizeY;
            v->color = color;
            v->texCoord = CTexCoord(0.0,  1.0);
            ++v;
            v->position = corner + (upR * sizeY + rightR * sizeX);
            v->color = color;
            v->texCoord = CTexCoord(1.0,1.0);
            ++v;
            v->position = corner + rightR * sizeX;
            v->color = color;
            v->texCoord = CTexCoord(1.0,0.0);
            ++v;
        }
    }

    a->numVerts = count * 4;
    a->numElems = count * 6;

    mVertexBuffer->uploadData(mSVertexBuffer, 0, 4 * count * sizeof(TParticleVertex));
    
    a->mElems = mElems;
}
示例#17
0
// Update =============================================================================
CStatus gStretchOp2Multi_Update( CRef& in_ctxt )
{

	OperatorContext ctxt( in_ctxt );

		// User Datas ------------------------------------
		CValue::siPtrType pUserData = ctxt.GetUserData();
		OpUserData* pOpState = (OpUserData*)pUserData;

		if ( pOpState == NULL || pOpState->index >= 2)
		{
			// First time called
			pOpState = new OpUserData();
			ctxt.PutUserData( (CValue::siPtrType)pOpState );

			// Inputs ---------------------------------------
			KinematicState kRoot(ctxt.GetInputValue(0));
			KinematicState kCtrl(ctxt.GetInputValue(1));
			CTransformation tRoot(kRoot.GetTransform());
			CTransformation tCtrl(kCtrl.GetTransform());
			CVector3 vRoot = tRoot.GetTranslation();
			CVector3 vCtrl = tCtrl.GetTranslation();
			CMatrix4 mRoot = tRoot.GetMatrix4();
			CMatrix4 mRootNeg;
			mRootNeg.Invert(mRoot);

			double dRestLength = ctxt.GetParameterValue(L"restlength");
			double dScale      = ctxt.GetParameterValue(L"scale");
			double dSoftness   = ctxt.GetParameterValue(L"soft");
			double dMaxStretch = ctxt.GetParameterValue(L"maxstretch");

			// Distance with MaxStretch ---------------------
			dRestLength = dRestLength * dScale - .00001;
			CVector3 vDistance;
			vDistance.MulByMatrix4(vCtrl, mRootNeg);
			double dDistance = vDistance.GetLength();
			double dDistance2 = dDistance;
			if (dDistance > (dRestLength * dMaxStretch))
			{
				vDistance.NormalizeInPlace();
				vDistance.ScaleInPlace(dRestLength * dMaxStretch);
				dDistance = dRestLength * dMaxStretch;
			}

			Application app;
			app.LogMessage(L"dist : "+CString(dDistance));
			app.LogMessage(L"dist2 : "+CString(dDistance2));

			// Adapt Softness value to chain length --------
			dSoftness = dSoftness * dRestLength *.1;

			// Stretch and softness ------------------------
			/// We use the real distance from root to controler to calculate the softness
			/// This way we have softness working even when there is no stretch
			double dStretch = dDistance/dRestLength;
			if (dStretch < 1)
				dStretch = 1;
			double da = dRestLength - dSoftness;
			if (dSoftness > 0 && dDistance2 > da)
			{
				double newlen = dSoftness*(1.0 - exp(-(dDistance2 -da)/dSoftness)) + da;
				dStretch = dDistance / newlen;
			}

			double dScaleX = dStretch * dScale;
			app.LogMessage(L"scalex : "+CString(dScaleX));

			// Effector Position ----------------------------
			CTransformation t;
			vDistance.MulByMatrix4(vDistance, mRoot);
			t.SetTranslation(vDistance);

			pOpState->index = 0;
			pOpState->t = t;
			pOpState->dLength0 = dScaleX;
		}

	// Outputs -------------------------------------
	CRef outputPortRef=ctxt.GetOutputPort();
	OutputPort OutPort(outputPortRef);

	// Effector Transform
	if (OutPort.GetIndex() == 2)
	{
		KinematicState kOut = ctxt.GetOutputTarget();
		kOut.PutTransform(pOpState->t);
	}
	// Bone 0 Length
	else if (OutPort.GetIndex() == 3)
	{
		OutPort.PutValue(pOpState->dLength0);
	}

	pOpState->index += 1;

	return CStatus::OK;
}
示例#18
0
// Update =================================================================================
CStatus gStretchOp2_Update( CRef& in_ctxt )
{
	OperatorContext ctxt( in_ctxt );

	// User Datas ------------------------------------
	CValue::siPtrType pUserData = ctxt.GetUserData();
	OpUserData* pOpState = (OpUserData*)pUserData;

	if ( pOpState == NULL || pOpState->index >= 4)
	{
		// First time called
		pOpState = new OpUserData();
		ctxt.PutUserData( (CValue::siPtrType)pOpState );

		// Inputs ---------------------------------------
		KinematicState kRoot(ctxt.GetInputValue(0));
		KinematicState kCtrl(ctxt.GetInputValue(1));
		CTransformation tRoot(kRoot.GetTransform());
		CTransformation tCtrl(kCtrl.GetTransform());
		CVector3 vRoot = tRoot.GetTranslation();
		CVector3 vCtrl = tCtrl.GetTranslation();
		CMatrix4 mRoot = tRoot.GetMatrix4();
		CMatrix4 mRootNeg;
		mRootNeg.Invert(mRoot);

		double dRest0      = ctxt.GetParameterValue(L"rest0");
		double dRest1      = ctxt.GetParameterValue(L"rest1");
		double dPrefRot    = ctxt.GetParameterValue(L"prefrot");
		double dScale0     = ctxt.GetParameterValue(L"scale0");
		double dScale1     = ctxt.GetParameterValue(L"scale1");
		double dSoftness   = ctxt.GetParameterValue(L"soft");
		double dMaxStretch = ctxt.GetParameterValue(L"maxstretch");
		double dSlide      = ctxt.GetParameterValue(L"slide");
		double dReverse    = ctxt.GetParameterValue(L"reverse");

		// Distance with MaxStretch ---------------------
		double dRestLength = dRest0 * dScale0 + dRest1 * dScale1;
		CVector3 vDistance;
		vDistance.MulByMatrix4(vCtrl, mRootNeg);
		double dDistance = vDistance.GetLength();
		double dDistance2 = dDistance;
		if (dDistance > (dRestLength * dMaxStretch))
		{
			vDistance.NormalizeInPlace();
			vDistance.ScaleInPlace(dRestLength * dMaxStretch);
			dDistance = dRestLength * dMaxStretch;
		}

		// Adapt Softness value to chain length --------
		dSoftness *= dRestLength*.1;

		// Stretch and softness ------------------------
		/// We use the real distance from root to controler to calculate the softness
		/// This way we have softness working even when there is no stretch
		double dStretch = dDistance/dRestLength;
		if (dStretch < 1)
			dStretch = 1;
		double da = dRestLength - dSoftness;
		if (dSoftness > 0 && dDistance2 > da)
		{
			double newlen = dSoftness*(1.0 - exp(-(dDistance2 -da)/dSoftness)) + da;
			dStretch = dDistance / newlen;
		}

		double dLength0 = dRest0 * dStretch * dScale0;
		double dLength1 = dRest1 * dStretch * dScale1;

		// Reverse -------------------------------------
		double d = dDistance/(dLength0 + dLength1);

		double dScale;
		if (dReverse < 0.5)
			dScale = 1-(dReverse*2 * (1-d));
		else
			dScale = 1-((1-dReverse)*2 * (1-d));

		dLength0 *= dScale;
		dLength1 *= dScale;

		dPrefRot = -(dReverse-0.5) * 2 * dPrefRot;

		// Slide ---------------------------------------
		double dAdd;
		if (dSlide < .5)
			dAdd = (dLength0 * (dSlide*2)) - (dLength0);
		else
			dAdd = (dLength1 * (dSlide*2)) - (dLength1);

		dLength0 += dAdd;
		dLength1 -= dAdd;

		// Effector Position ----------------------------
		CTransformation t;
		vDistance.MulByMatrix4(vDistance, mRoot);
		t.SetTranslation(vDistance);

		pOpState->index = 0;
		pOpState->t = t;
		pOpState->dLength0 = dLength0;
		pOpState->dLength1 = dLength1;
		pOpState->dPrefRot = dPrefRot;
	}

	// Outputs -------------------------------------
	CRef outputPortRef=ctxt.GetOutputPort();
	OutputPort OutPort(outputPortRef);

	// Effector Transform
	if (OutPort.GetIndex() == 2)
	{
		KinematicState kOut = ctxt.GetOutputTarget();
		kOut.PutTransform(pOpState->t);
	}
	// Bone 0 Length
	else if (OutPort.GetIndex() == 3)
	{
		OutPort.PutValue(pOpState->dLength0);
	}
	// Bone 1 Length
	else if (OutPort.GetIndex() == 4)
	{
		OutPort.PutValue(pOpState->dLength1);
	}
	// Bone 1 PrefRot
	else if (OutPort.GetIndex() == 5)
	{
		OutPort.PutValue(pOpState->dPrefRot);
	}

	pOpState->index += 1;

	return CStatus::OK;
}
示例#19
0
bool CMatrix4::Inverse(CMatrix4 &m2)
{
 int i, j, k, swap;
   float t;
   float temp[4][4];

   for (i = 0; i < 4; i++)
	   for (j = 0; j < 4; j++)
         temp[i][j] = m_Matrix[(i * 4) + j];

   m2.LoadIdentity();

   for (i = 0; i < 4; i++)
   {
      /*
      ** Look for largest element in column
      */
      swap = i;
      for (j = i + 1; j < 4; j++)
         if (fabs(temp[j][i]) > fabs(temp[i][i]))
            swap = j;
   
      if (swap != i)
      {
         /*
         ** Swap rows.
         */
         for (k = 0; k < 4; k++)
         {
            t = temp[i][k];
            temp[i][k] = temp[swap][k];
            temp[swap][k] = t;

            t = m2.m_Matrix[(i * 4) + k];
            m2.m_Matrix[(i * 4) + k] = m2.m_Matrix[(swap * 4) + k];
            m2.m_Matrix[(swap * 4) + k] = t;
         }
      }

      /*
      ** No non-zero pivot.  The matrix is singular, which shouldn't
      ** happen.  This means the user gave us a bad matrix.
      */
      if (temp[i][i] == 0)
         return 0;

      t = temp[i][i];
      for (k = 0; k < 4; k++)
      {
         temp[i][k] /= t;
         m2.m_Matrix[(i * 4) + k] /= t;
      }
      for (j = 0; j < 4; j++)
      {
         if (j != i)
         {
            t = temp[j][i];
            for (k = 0; k < 4; k++)
            {
               temp[j][k] -= temp[i][k] * t;
               m2.m_Matrix[(j * 4) + k] -= m2.m_Matrix[(i * 4) + k] * t;
            }
         }
      }
   }
   return 1;
}
示例#20
0
    GLlink(ISceneNode *i_parent, ISceneManager *i_mgr, s32 i_id,
           const LinkInfo &i_li, BodyInfo_var i_binfo) :
        ISceneNode(i_parent, i_mgr, i_id),
        m_jointId(i_li.jointId) {
        setAutomaticCulling(scene::EAC_OFF);


        setPosition(vector3df( i_li.translation[0],
                               -i_li.translation[1],
                               i_li.translation[2]));
        Vector3 axis(i_li.rotation[0],
                     i_li.rotation[1],
                     i_li.rotation[2]);
        Matrix33 R;
        hrp::calcRodrigues(R, axis, i_li.rotation[3]);
        Vector3 rpy(rpyFromRot(R));
        //std::cout << "rpy:" << rpy << std::endl;
        setRotation(vector3df(-180/M_PI*rpy[0],
                              180/M_PI*rpy[1],
                              -180/M_PI*rpy[2]));

        m_axis << i_li.jointAxis[0], i_li.jointAxis[1], i_li.jointAxis[2];

        ShapeInfoSequence_var sis = i_binfo->shapes();
        AppearanceInfoSequence_var ais = i_binfo->appearances();
        MaterialInfoSequence_var mis = i_binfo->materials();
        TextureInfoSequence_var txs = i_binfo->textures();
        const TransformedShapeIndexSequence& tsis = i_li.shapeIndices;


        core::vector3df vertex;
        core::vector3df normal;

        for (unsigned int l=0; l<tsis.length(); l++) {
            SMesh* mesh = new SMesh();
            SMeshBuffer* meshBuffer = new SMeshBuffer();
            mesh->addMeshBuffer(meshBuffer);
            meshBuffer->drop();

            const TransformedShapeIndex &tsi = tsis[l];
            short index = tsi.shapeIndex;
            ShapeInfo& si = sis[index];
            const float *vertices = si.vertices.get_buffer();
            const LongSequence& triangles = si.triangles;
            const AppearanceInfo& ai = ais[si.appearanceIndex];
            const float *normals = ai.normals.get_buffer();
            //std::cout << "length of normals = " << ai.normals.length() << std::endl;
            const LongSequence& normalIndices = ai.normalIndices;
            //std::cout << "length of normalIndices = " << normalIndices.length() << std::endl;
            const int numTriangles = triangles.length() / 3;
            //std::cout << "numTriangles = " << numTriangles << std::endl;

            video::SColor color(0xffffffff);
            if (ai.colors.length()) {
                color.set(0xff,
                          0xff*ai.colors[0],
                          0xff*ai.colors[1],
                          0xff*ai.colors[2]);
            } else if (ai.materialIndex >= 0) {
                const MaterialInfo& mi = mis[ai.materialIndex];
                color.set(0xff,
                          0xff*mi.diffuseColor[0],
                          0xff*mi.diffuseColor[1],
                          0xff*mi.diffuseColor[2]);
            } else {
                std::cout << "no material" << std::endl;
            }


            SMeshBuffer* mb = reinterpret_cast<SMeshBuffer*>(mesh->getMeshBuffer(mesh->getMeshBufferCount()-1));
            u32 vCount = mb->getVertexCount();

            const DblArray12& tfm = tsi.transformMatrix;
            CMatrix4<f32> cmat;
            for (int i=0; i<3; i++) {
                for (int j=0; j<4; j++) {
                    cmat[j*4+i] = tfm[i*4+j];
                }
            }
            cmat[3] = cmat[7] = cmat[11] = 0.0;
            cmat[15] = 1.0;
            vector3df pos = cmat.getTranslation();
            pos.Y *= -1;
            vector3df rpy = cmat.getRotationDegrees();
            rpy.X *= -1;
            rpy.Z *= -1;
            vector3df scale = cmat.getScale();

            const float *textureCoordinate = NULL;
            if (ai.textureIndex >= 0) {
                textureCoordinate = ai.textureCoordinate.get_buffer();
                //std::cout << "length of textureCoordinate:" << ai.textureCoordinate.length() << std::endl;
                //std::cout << "length of vertices:" << si.vertices.length() << std::endl;

            }

            for(int j=0; j < numTriangles; ++j) {
                if (!ai.normalPerVertex) {
                    int p;
                    if (normalIndices.length() == 0) {
                        p = j*3;
                    } else {
                        p = normalIndices[j]*3;
                    }
                    if ( normals != NULL ) {
                        normal.X =  normals[p];
                        normal.Y = -normals[p+1]; //left-handed->right-handed
                        normal.Z =  normals[p+2];
                    } else {
                        normal.X = 0;
                        normal.Y = 0;
                        normal.Z = 1;
                    }
                }
                for(int k=0; k < 3; ++k) {
                    long orgVertexIndex = si.triangles[j * 3 + k];
                    if (ai.normalPerVertex) {
                        int p;
                        if (normalIndices.length()) {
                            p = normalIndices[j*3+k]*3;
                        } else {
                            p = orgVertexIndex*3;
                        }
                        normal.X =  normals[p];
                        normal.Y = -normals[p+1]; //left-handed -> right-handed
                        normal.Z =  normals[p+2];
                    }
                    int p = orgVertexIndex * 3;
                    vertex.X =  scale.X*vertices[p];
                    vertex.Y = -scale.Y*vertices[p+1]; // left-handed -> right-handed
                    vertex.Z =  scale.Z*vertices[p+2];
                    //std::cout << vertices[p] <<"," << vertices[p+1] << "," << vertices[p+2] << std::endl;
                    vector2df texc;
                    if (textureCoordinate) {

                        texc.X = textureCoordinate[ai.textureCoordIndices[j*3+k]*2];
                        texc.Y = textureCoordinate[ai.textureCoordIndices[j*3+k]*2+1];
                    }
                    // redundant vertices
                    mb->Vertices.push_back(video::S3DVertex(vertex,normal,color, texc));
                }
                mb->Indices.push_back(vCount);
                mb->Indices.push_back(vCount+2);
                mb->Indices.push_back(vCount+1);
                vCount += 3;
            }
            mesh->getMeshBuffer(0)->recalculateBoundingBox();

            // Create the Animated mesh if there's anything in the mesh
            SAnimatedMesh* pAM = 0;
            if ( 0 != mesh->getMeshBufferCount() )
            {
                mesh->recalculateBoundingBox();
                pAM = new SAnimatedMesh();
                pAM->Type = EAMT_OBJ;
                pAM->addMesh(mesh);
                pAM->recalculateBoundingBox();
            }

            mesh->drop();

            vector3df noscale(1,1,1);

            IMeshSceneNode *node
                = i_mgr->addMeshSceneNode(mesh, this, -1,
                                          pos,
                                          rpy,
                                          noscale);

            if (ai.textureIndex >= 0) {
                const TextureInfo& ti = txs[ai.textureIndex];
                //std::cout << "url:" << ti.url << std::endl;
                video::IVideoDriver* driver = i_mgr->getVideoDriver();
                const char *path = ti.url;
                SMaterial& mat = node->getMaterial(0);
                ITexture *texture = driver->getTexture(path);
                mat.setTexture( 0, texture);
            }

        }

        const SensorInfoSequence& sensors = i_li.sensors;
        for (unsigned int i=0; i<sensors.length(); i++) {
            const SensorInfo& si = sensors[i];
            std::string type(si.type);
            if (type == "Vision") {
                //std::cout << si.name << std::endl;
                ISceneNode *camera = i_mgr->addEmptySceneNode(this);
                camera->setName(si.name);
                camera->setPosition(vector3df( si.translation[0],
                                               -si.translation[1],
                                               si.translation[2]));
                Vector3 axis(si.rotation[0],
                             si.rotation[1],
                             si.rotation[2]);
                Matrix33 R;
                hrp::calcRodrigues(R, axis, si.rotation[3]);
                Vector3 rpy(rpyFromRot(R));
                camera->setRotation(vector3df(-180/M_PI*rpy[0],
                                              180/M_PI*rpy[1],
                                              -180/M_PI*rpy[2]));
                m_cameraInfos.push_back(new GLcamera(si, camera));
            }
        }
    }
示例#21
0
bool 
ProcTitle::OnInit(irr::IrrlichtDevice& device)
{	
	device.setWindowCaption(L"Pair - title");
	//device.getCursorControl()->setVisible(false);

	u32 width = IrrDvc.GetDriver()->getScreenSize().Width;
	u32 height = IrrDvc.GetDriver()->getScreenSize().Height;

	scene::ISceneManager* pSmgr = IrrDvc.GetSmgr();
	IVideoDriver* pDriver = IrrDvc.GetDriver();

	// camera setting 
	{		
		irr::scene::ICameraSceneNode* pCamera = pSmgr->addCameraSceneNode(0, core::vector3df(0,0,-100), core::vector3df(0,0,0));		
		//f32 zNear = 1;
		//f32 zFar = 3000;
		//f32 zNear = pCamera->getNearValue();
		//f32 zFar = pCamera->getFarValue();
#if 0
		CMatrix4<f32> matOrtho;				
		matOrtho.buildProjectionMatrixOrthoLH(width, height, zNear, zFar);
		pCamera->setProjectionMatrix(matOrtho, true);
#else
		//CMatrix4<f32> matPerspective;
		//matPerspective.buildProjectionMatrixPerspectiveLH((f32)width, (f32)height, zNear, zFar);
		//pCamera->setProjectionMatrix(matPerspective, false);
#endif
	}

	// title
	{		
		m_p2DSprite = pSmgr->addBillboardSceneNode();
		video::ITexture* pTexture = pDriver->getTexture("Rsrc/title.png");		
		m_p2DSprite->setMaterialTexture(0, pTexture);
		m_p2DSprite->setMaterialFlag(video::EMF_LIGHTING, false);
		m_p2DSprite->setMaterialFlag(video::EMF_ZBUFFER, true);
		m_p2DSprite->setMaterialFlag(video::EMF_ZWRITE_ENABLE, false);
		m_p2DSprite->setMaterialFlag(video::EMF_ANTI_ALIASING, true);
		m_p2DSprite->setMaterialFlag(video::EMF_BILINEAR_FILTER, true);
		m_p2DSprite->setSize(dimension2df((f32)width, (f32)height));
		m_p2DSprite->setPosition(vector3df(0.f, 0.f, 300.f));
		m_p2DSprite->setID(1004);
		m_p2DSprite->getMaterial(0).getTextureMatrix(0).setTextureScale(1.0f, 1.0f);

		// animation test
		//scene::ISceneNodeAnimator* pAni = pSmgr->createFlyCircleAnimator(core::vector3df(0,0,200), 20.0f);
		//m_p2DSprite->addAnimator(pAni);
	}

	// card
	{
		for (int i = 0; i < 3; i++)
		{
			IMeshSceneNode* pCard = pSmgr->addCubeSceneNode();
			char buff[20];
			sprintf_s(buff, 20, "Rsrc/card%d.png", i);
			video::ITexture* pTexture = pDriver->getTexture(buff);			
			pCard->setMaterialTexture(0, pTexture);
			pCard->setScale(vector3df(4.f, 4.f * 1.618f, 0.1f));
			pCard->setPosition(vector3df(-60.f + 60.f * i, 0.f, 0.f));
			pCard->setMaterialFlag(video::EMF_LIGHTING, false);

			// animation test
			scene::ISceneNodeAnimator* pAni = pSmgr->createRotationAnimator(vector3df(0.f, 1.f, 0.f));
			pCard->addAnimator(pAni);
			pAni->drop();
		}
	}

	// mesh
	{
		IAnimatedMesh* mesh = pSmgr->getMesh("Rsrc/sydney.md2");
		IAnimatedMeshSceneNode* pNode = pSmgr->addAnimatedMeshSceneNode(mesh);
		if (pNode)
		{
			//pNode->setScale(vector3df(10.f, 10.f, 10.f));
			pNode->setMaterialFlag(EMF_LIGHTING, false);
			//pNode->setMaterialFlag(EMF_ZBUFFER, false);
			pNode->setMD2Animation(scene::EMAT_STAND);
			pNode->setMaterialTexture( 0, pDriver->getTexture("Rsrc/sydney.bmp") );
			pNode->setPosition(vector3df(0.0f, -5.f, -55.f));
		}
	}

	// button 
	{
		IGUIEnvironment* env = device.getGUIEnvironment();
		
		video::ITexture* pTexture = pDriver->getTexture("Rsrc/new_game_btn_normal.PNG");	// refcount = 1
		dimension2d<u32> dim = pTexture->getOriginalSize();
		s32 offsetX = width / 2 - dim.Width / 2;
		s32 offsetY = height - dim.Height * 3;
		IGUIButton* pButton = env->addButton(rect<s32>(offsetX, offsetY, offsetX + dim.Width, offsetY + dim.Height), 0, GUI_ID_START_BUTTON);
		pButton->setDrawBorder(false);		
		pButton->setImage(pTexture);										// refcount += 2, means when button released refcount will be 1	
		pButton->setUseAlphaChannel(true);									// 1 will be decreased pDriver->removeAllTextures();

		{
			ITexture* pTexture = pDriver->getTexture("Rsrc/new_game_btn_pressed.PNG");
			pButton->setPressedImage(pTexture);
		}
	}

	// sound test
	IrrSnd.GetSndEngine()->play2D("Rsrc/getout.ogg", true);

	return true;
}
示例#22
0
bool CManipRot::UIEventHandler( const ui::Event& EV )
{	
	int ex = EV.miX;
	int ey = EV.miY;
	
	CVector2 posubp = EV.GetUnitCoordBP();

	CCamera *pcam = mManager.GetActiveCamera();
	
	bool brval = false;
			
	bool isshift = false; //CSystem::IsKeyDepressed(VK_SHIFT );
	bool isctrl = false; //CSystem::IsKeyDepressed(VK_CONTROL );
	
	switch( EV.miEventCode )
	{
		case ui::UIEV_PUSH:
		{	
			mManager.mManipHandler.Init(posubp, pcam->mCameraData.GetIVPMatrix(), pcam->QuatC );
			mBaseTransform = mManager.mCurTransform;

			SelectBestPlane(posubp);

			brval = true;
		}
		break;

		case ui::UIEV_RELEASE:
		{
			mManager.DisableManip();

			brval = true;
		}
		break;

		case ui::UIEV_DRAG:
		{
			IntersectWithPlanes( posubp );

			if ( CheckIntersect() )
			{	
				///////////////////////////////////////////
				// calc normalvectors from base:origin to point on activeintersection plane (in world space)
				const CVector3 & Origin = mBaseTransform.GetTransform().GetPosition();
				CVector3 D1 = (Origin-mActiveIntersection->mIntersectionPoint).Normal();
				CVector3 D0 = (Origin-mActiveIntersection->mBaseIntersectionPoint).Normal();
				///////////////////////////////////////////
				// calc matrix to put worldspace vector into plane local space
				CMatrix4 MatWldToObj = mBaseTransform.GetTransform().GetMatrix(); //GetRotation();
				MatWldToObj.Inverse();
				CVector4 bAxisAngle = mLocalRotationAxis; 
				CQuaternion brq;
				brq.FromAxisAngle(bAxisAngle);
				CMatrix4 MatObjToPln = brq.ToMatrix();
				MatObjToPln.Inverse();
				CMatrix4 MatWldToPln = MatObjToPln*MatWldToObj;
				//CMatrix4 MatInvRot = InvQuat.ToMatrix();
				///////////////////////////////////////////
				// calc plane local rotation
				CVector4 AxisAngle = mLocalRotationAxis; 
				CVector4 D0I = CVector4(D0,CReal(0.0f)).Transform(MatWldToPln);
				CVector4 D1I = CVector4(D1,CReal(0.0f)).Transform(MatWldToPln);
				//orkprintf( "D0 <%f %f %f>\n", float(D0.GetX()), float(D0.GetY()), float(D0.GetZ()) );
				//orkprintf( "D1 <%f %f %f>\n", float(D1.GetX()), float(D1.GetY()), float(D1.GetZ()) );
				//orkprintf( "D0I <%f %f %f>\n", float(D0I.GetX()), float(D0I.GetY()), float(D0I.GetZ()) );
				//orkprintf( "D1I <%f %f %f>\n", float(D1I.GetX()), float(D1I.GetY()), float(D1I.GetZ()) );
				AxisAngle.SetW( CalcAngle(D0I,D1I) );
				CQuaternion RotQ;
				RotQ.FromAxisAngle( AxisAngle );
				///////////////////
				// Rot Snap
				if( isshift )
				{	CReal SnapAngleVal( PI2/16.0f );
					CVector4 NewAxisAngle = RotQ.ToAxisAngle();
					CReal Angle = NewAxisAngle.GetW();
					Angle = SnapReal( Angle, SnapAngleVal );
					NewAxisAngle.SetW( Angle );
					RotQ.FromAxisAngle( NewAxisAngle );
				}
				///////////////////
				// accum rotation
				CQuaternion oq = mBaseTransform.GetTransform().GetRotation();
				CQuaternion NewQ = RotQ.Multiply(oq);
				///////////////////
				// Rot Reset To Identity
				if( isctrl && isshift )
				{
					NewQ.FromAxisAngle( CVector4( CReal(0.0f), CReal(1.0f), CReal(0.0f), CReal(0.0f) ) );
				}
				///////////////////
				TransformNode mset = mManager.mCurTransform;
				mset.GetTransform().SetRotation( NewQ );
				mManager.ApplyTransform( mset );
				///////////////////
			}

			brval = true;
		}
		break;

		default:
			break;
	}

	return brval;
}
示例#23
0
///////////////////////////////////////////////////////////////
// METHODS
///////////////////////////////////////////////////////////////
// GetIKTransform =============================================
CTransformation GetIKTransform(s_GetIKTransform values, CString outportName)
{
   // prepare all variables
   CTransformation result;
   CVector3 bonePos,rootPos,effPos,upvPos,rootEff, xAxis,yAxis,zAxis, rollAxis;

   rootPos = values.root.GetTranslation();
   effPos = values.eff.GetTranslation();
   upvPos = values.upv.GetTranslation();
   rootEff.Sub(effPos,rootPos);
   rollAxis.Normalize(rootEff);

   CMatrix4 rootMatrix = values.root.GetMatrix4();
   CMatrix4 rootMatrixNeg;
   rootMatrixNeg.Invert(rootMatrix);

   double rootEffDistance = rootEff.GetLength();

   // init the scaling
   double global_scale = values.root.GetScaling().GetX();
   result.SetScaling(values.root.GetScaling());

   // Distance with MaxStretch ---------------------
   double restLength = values.lengthA * values.scaleA + values.lengthB * values.scaleB;
   CVector3 distanceVector;
   distanceVector.MulByMatrix4(effPos, rootMatrixNeg);
   double distance = distanceVector.GetLength();
   double distance2 = distance;
   if (distance > (restLength * (values.maxstretch)))
   {
      distanceVector.NormalizeInPlace();
      distanceVector.ScaleInPlace(restLength * (values.maxstretch) );
      distance = restLength * (values.maxstretch);
   }

   // Adapt Softness value to chain length --------
   values.softness = values.softness * restLength *.1;

   // Stretch and softness ------------------------
   // We use the real distance from root to controler to calculate the softness
   // This way we have softness working even when there is no stretch
   double stretch = max(1, distance / restLength);
   double da = restLength - values.softness;
   if (values.softness > 0 && distance2 > da)
   {
      double newlen = values.softness*(1.0 - exp(-(distance2 -da)/values.softness)) + da;
      stretch = distance / newlen;
   }

   values.lengthA = values.lengthA * stretch * values.scaleA * global_scale;
   values.lengthB = values.lengthB * stretch * values.scaleB * global_scale;

   // Reverse -------------------------------------
   double d = distance / (values.lengthA + values.lengthB);

   double reverse_scale;
   if (values.reverse < 0.5)
      reverse_scale = 1-(values.reverse*2 * (1-d));
   else
      reverse_scale = 1-((1-values.reverse)*2 * (1-d));

   values.lengthA *= reverse_scale;
   values.lengthB *= reverse_scale;

   bool invert = values.reverse > 0.5;

   // Slide ---------------------------------------
   double slide_add;
   if (values.slide < .5)
      slide_add = (values.lengthA * (values.slide * 2)) - (values.lengthA);
   else
      slide_add = (values.lengthB * (values.slide * 2)) - (values.lengthB);

   values.lengthA += slide_add;
   values.lengthB -= slide_add;

   // calculate the angle inside the triangle!
   double angleA = 0;
   double angleB = 0;

   // check if the divider is not null otherwise the result is nan
   // and the output disapear from xsi, that breaks constraints
   if((rootEffDistance < values.lengthA + values.lengthB) && (rootEffDistance > fabs(values.lengthA - values.lengthB) + 1E-6))
   {
      // use the law of cosine for lengthA
      double a = values.lengthA;
      double b = rootEffDistance;
      double c = values.lengthB;

         angleA = acos(min(1, (a * a + b * b - c * c ) / ( 2 * a * b)));

      // use the law of cosine for lengthB
      a = values.lengthB;
      b = values.lengthA;
      c = rootEffDistance;
      angleB = acos(min(1, (a * a + b * b - c * c ) / ( 2 * a * b)));

      // invert the angles if need be
      if(invert)
      {
         angleA = -angleA;
         angleB = -angleB;
      }
   }

   // start with the X and Z axis
   xAxis = rootEff;
   yAxis.LinearlyInterpolate(rootPos,effPos,.5);
   yAxis.Sub(upvPos,yAxis);
   yAxis = rotateVectorAlongAxis(yAxis, rollAxis, values.roll);
   zAxis.Cross(xAxis,yAxis);
   xAxis.NormalizeInPlace();
   zAxis.NormalizeInPlace();

   // switch depending on our mode
   if(outportName == "OutBoneA")  // Bone A
   {
      // check if we need to rotate the bone
      if(angleA != 0.0)
      {
         CRotation rot;
         rot.SetFromAxisAngle(zAxis,angleA);
         xAxis.MulByMatrix3InPlace(rot.GetMatrix());
      }

      if (values.negate)
         xAxis.NegateInPlace();

      // cross the yAxis and normalize
      yAxis.Cross(zAxis,xAxis);
      yAxis.NormalizeInPlace();

      // output the rotation
      result.SetRotationFromXYZAxes(xAxis,yAxis,zAxis);

      // set the scaling + the position
      result.SetSclX(values.lengthA);
      result.SetTranslation(rootPos);
   }
   else if(outportName == "OutBoneB")  // Bone B
   {
      // check if we need to rotate the bone
      if(angleA != 0.0)
      {
         CRotation rot;
         rot.SetFromAxisAngle(zAxis,angleA);
         xAxis.MulByMatrix3InPlace(rot.GetMatrix());
      }

      // calculate the position of the elbow!
      bonePos.Scale(values.lengthA,xAxis);
      bonePos.AddInPlace(rootPos);

      // check if we need to rotate the bone
      if(angleB != 0.0)
      {
         CRotation rot;
         rot.SetFromAxisAngle(zAxis,angleB-XSI::MATH::PI);
         xAxis.MulByMatrix3InPlace(rot.GetMatrix());
      }

      if (values.negate)
         xAxis.NegateInPlace();

      // cross the yAxis and normalize
      yAxis.Cross(zAxis,xAxis);
      yAxis.NormalizeInPlace();

      // output the rotation
      result.SetRotationFromXYZAxes(xAxis,yAxis,zAxis);

      // set the scaling + the position
      result.SetSclX(values.lengthB);
      result.SetTranslation(bonePos);
   }
   else if(outportName == "OutCenter")  // center
   {
      // check if we need to rotate the bone
      bonePos.Scale(values.lengthA,xAxis);
      if(angleA != 0.0)
      {
         CRotation rot;
         rot.SetFromAxisAngle(zAxis,angleA);
         bonePos.MulByMatrix3InPlace(rot.GetMatrix());
      }
      bonePos.AddInPlace(rootPos);

      // cross the yAxis and normalize
      yAxis.Sub(upvPos,bonePos);
      zAxis.Cross(xAxis,yAxis);
      zAxis.NormalizeInPlace();

      if (values.negate)
         xAxis.NegateInPlace();

      yAxis.Cross(zAxis,xAxis);
      yAxis.NormalizeInPlace();

      // output the rotation
      result.SetRotationFromXYZAxes(xAxis,yAxis,zAxis);

      // set the scaling + the position
      result.SetSclX(stretch * values.root.GetSclX());

      result.SetTranslation(bonePos);
   }
   else if(outportName == "OutCenterN")  // center normalized
   {
      // check if we need to rotate the bone
      if(angleA != 0.0)
      {
         CRotation rot;
         rot.SetFromAxisAngle(zAxis,angleA);
         xAxis.MulByMatrix3InPlace(rot.GetMatrix());
      }

      // calculate the position of the elbow!
      bonePos.Scale(values.lengthA,xAxis);
      bonePos.AddInPlace(rootPos);

      // check if we need to rotate the bone
      if(angleB != 0.0)
      {
         if(invert)
            angleB += XSI::MATH::PI * 2;
         CRotation rot;
         rot.SetFromAxisAngle(zAxis,angleB*.5-XSI::MATH::PI*.5);
         xAxis.MulByMatrix3InPlace(rot.GetMatrix());
      }      // cross the yAxis and normalize
      // yAxis.Sub(upvPos,bonePos); // this was flipping the centerN when the elbow/upv was aligned to root/eff
      zAxis.Cross(xAxis,yAxis);
      zAxis.NormalizeInPlace();

      if (values.negate)
         xAxis.NegateInPlace();

      yAxis.Cross(zAxis,xAxis);
      yAxis.NormalizeInPlace();

      // output the rotation
      result.SetRotationFromXYZAxes(xAxis,yAxis,zAxis);

      // set the scaling + the position
      // result.SetSclX(stretch * values.root.GetSclX());

      result.SetTranslation(bonePos);
   }
   else if(outportName == "OutEff")  // effector
   {
      // check if we need to rotate the bone
      effPos = rootPos;
      if(angleA != 0.0)
      {
         CRotation rot;
         rot.SetFromAxisAngle(zAxis,angleA);
         xAxis.MulByMatrix3InPlace(rot.GetMatrix());
      }

      // calculate the position of the elbow!
      bonePos.Scale(values.lengthA,xAxis);
      effPos.AddInPlace(bonePos);

      // check if we need to rotate the bone
      if(angleB != 0.0)
      {
         CRotation rot;
         rot.SetFromAxisAngle(zAxis,angleB-XSI::MATH::PI);
         xAxis.MulByMatrix3InPlace(rot.GetMatrix());
      }

      // calculate the position of the effector!
      bonePos.Scale(values.lengthB,xAxis);
      effPos.AddInPlace(bonePos);

      // cross the yAxis and normalize
      yAxis.Cross(zAxis,xAxis);
      yAxis.NormalizeInPlace();

      // output the rotation
      result = values.eff;
      result.SetTranslation(effPos);
   }


   CRotation r = result.GetRotation();
   CVector3 eulerAngles = r.GetXYZAngles();

   double rx = eulerAngles.GetX();
   double ry = eulerAngles.GetY();
   double rz = eulerAngles.GetZ();

   return result;
}
示例#24
0
void CDx11UmbralEffect::UpdateConstants(const Palleon::DX11VIEWPORT_PARAMS& viewportParams, Palleon::CMaterial* material, const CMatrix4& worldMatrix)
{
	//Update vertex shader params
	{
		auto worldITMatrix = worldMatrix.Inverse().Transpose();
		auto viewITMatrix = viewportParams.viewMatrix.Inverse().Transpose();
		auto worldViewMatrix = worldMatrix * viewportParams.viewMatrix;
		auto worldViewProjMatrix = worldViewMatrix * viewportParams.projMatrix;
		CVector3 modelBBoxOffset(0, 0, 0);
		CVector3 modelBBoxScale(1, 1, 1);

		auto vertexOcclusionScale = material->GetEffectParamOrDefault("vs_vertexOcclusionScale", 0.0f, m_vertexOcclusionScaleOffset != -1);
		auto vertexColorBias = material->GetEffectParamOrDefault("vs_vertexColorBias", CVector4(0, 0, 0, 0), m_vertexColorBiasOffset != -1);

		D3D11_MAPPED_SUBRESOURCE mappedResource = {};
		HRESULT result = m_deviceContext->Map(m_vertexConstantBuffer, 0, D3D11_MAP_WRITE_DISCARD, 0, &mappedResource);
		assert(SUCCEEDED(result));
		auto constantBufferPtr = reinterpret_cast<uint8*>(mappedResource.pData);

		memset(constantBufferPtr, 0, mappedResource.RowPitch);

		SetParamValue(constantBufferPtr, m_modelBBoxOffsetOffset, modelBBoxOffset);
		SetParamValue(constantBufferPtr, m_modelBBoxScaleOffset, modelBBoxScale);
		SetParamValue(constantBufferPtr, m_vertexOcclusionScaleOffset, vertexOcclusionScale);
		SetParamValue(constantBufferPtr, m_vertexColorBiasOffset, vertexColorBias);
		SetParamValue<uint32>(constantBufferPtr, m_isUseInstancingOffset, 0);
		if(m_viewITMatrixOffset != -1)			*reinterpret_cast<CMatrix4*>(constantBufferPtr + m_viewITMatrixOffset) = viewITMatrix.Transpose();
		if(m_worldITMatrixOffset != -1)			*reinterpret_cast<CMatrix4*>(constantBufferPtr + m_worldITMatrixOffset) = worldITMatrix.Transpose();
		if(m_worldMatrixOffset != -1)			*reinterpret_cast<CMatrix4*>(constantBufferPtr + m_worldMatrixOffset) = worldMatrix.Transpose();
		if(m_worldViewMatrixOffset != -1)		*reinterpret_cast<CMatrix4*>(constantBufferPtr + m_worldViewMatrixOffset) = worldViewMatrix.Transpose();
		if(m_worldViewProjMatrixOffset != -1)	*reinterpret_cast<CMatrix4*>(constantBufferPtr + m_worldViewProjMatrixOffset) = worldViewProjMatrix.Transpose();

		m_deviceContext->Unmap(m_vertexConstantBuffer, 0);
	}

	//Update pixel shader params
	{
		auto modulateColor = material->GetEffectParamOrDefault("ps_modulateColor", CVector4(1, 1, 1, 1), m_modulateColorOffset != -1);
		auto ambientColor = material->GetEffectParamOrDefault("ps_ambientColor", CVector4(0, 0, 0, 0), m_ambientColorOffset != -1);
		auto diffuseColor = material->GetEffectParamOrDefault("ps_diffuseColor", CVector4(0, 0, 0, 0), m_diffuseColorOffset != -1);
		auto specularColor = material->GetEffectParamOrDefault("ps_specularColor", CVector4(0, 0, 0, 0), m_specularColorOffset != -1);
		auto shininess = material->GetEffectParamOrDefault("ps_shininess", 128.f, m_shininessOffset != -1);
		auto reflectivity = material->GetEffectParamOrDefault("ps_reflectivity", CVector3(0, 0, 0), m_reflectivityOffset != -1);
		auto normalPower = material->GetEffectParamOrDefault("ps_normalPower", 1.f, m_normalPowerOffset != -1);

		auto multiDiffuseColor = material->GetEffectParamOrDefault("ps_multiDiffuseColor", CVector4(0, 0, 0, 0), m_multiDiffuseColorOffset != -1);
		auto multiSpecularColor = material->GetEffectParamOrDefault("ps_multiSpecularColor", CVector4(0, 0, 0, 0), m_multiSpecularColorOffset != -1);
		auto multiShininess = material->GetEffectParamOrDefault("ps_multiShininess", 128.f, m_multiShininessOffset != -1);
		auto multiReflectivity = material->GetEffectParamOrDefault("ps_multiReflectivity", CVector3(0, 0, 0), m_multiReflectivityOffset != -1);
		auto multiNormalPower = material->GetEffectParamOrDefault("ps_multiNormalPower", 1.f, m_multiNormalPowerOffset != -1);

		auto fresnelExp = material->GetEffectParamOrDefault("ps_fresnelExp", 1.f, m_fresnelExpOffset != -1);
		auto fresnelLightDiffBias = material->GetEffectParamOrDefault("ps_fresnelLightDiffBias", 1.f, m_fresnelLightDiffBiasOffset != -1);
		auto specularInfluence = material->GetEffectParamOrDefault("ps_specularInfluence", 0.f, m_specularInfluenceOffset != -1);
		auto lightDiffusePower = material->GetEffectParamOrDefault("ps_lightDiffusePower", 0.67f, m_lightDiffusePowerOffset != -1);
		auto lightDiffuseInfluence = material->GetEffectParamOrDefault("ps_lightDiffuseInfluence", 0.56f, m_lightDiffuseInfluenceOffset != -1);
		auto reflectMapInfluence = material->GetEffectParamOrDefault("ps_reflectMapInfluence", 0.8f, m_reflectMapInfluenceOffset != -1);

		auto glareLdrScale = material->GetEffectParamOrDefault("ps_glareLdrScale", 1.0f, m_glareLdrScaleOffset != -1);
		auto refAlphaRestrain = material->GetEffectParamOrDefault("ps_refAlphaRestrain", 0.f, m_refAlphaRestrainOffset != -1);
		auto normalVector = material->GetEffectParamOrDefault("ps_normalVector", CVector4(0, 0, 0, 0), m_normalVectorOffset != -1);
		auto depthBias = material->GetEffectParamOrDefault("ps_depthBias", 0.f, m_depthBiasOffset != -1);
		auto velvetParam = material->GetEffectParamOrDefault("ps_velvetParam", CVector2(0, 0), m_velvetParamOffset != -1);

		auto ambientOcclusionColor = material->GetEffectParamOrDefault("ps_ambentOcclusionColor", CVector3(1, 1, 1), m_ambientOcclusionColorOffset != -1);
		auto mainLightOcclusionColor = material->GetEffectParamOrDefault("ps_mainLightOcclusionColor", CVector3(0, 0, 0), m_mainLightOcclusionColorOffset != -1);
		auto subLightOcclusionColor = material->GetEffectParamOrDefault("ps_subLightOcclusionColor", CVector3(0, 0, 0), m_subLightOcclusionColorOffset != -1);
		auto pointLightOcclusionColor = material->GetEffectParamOrDefault("ps_pointLightOcclusionColor", CVector3(0.5f, 0.5f, 0.5f), m_pointLightOcclusionColorOffset != -1);
		auto lightMapOcclusionColor = material->GetEffectParamOrDefault("ps_lightMapOcclusionColor", CVector3(0.3f, 0.3f, 0.3f), m_lightMapOcclusionColorOffset != -1);
		auto reflectMapOcclusionColor = material->GetEffectParamOrDefault("ps_reflectMapOcclusionColor", CVector3(0.3f, 0.3f, 0.3f), m_reflectMapOcclusionColorOffset != -1);
		auto specularOcclusionColor = material->GetEffectParamOrDefault("ps_specularOcclusionColor", CVector3(0, 0, 0), m_specularOcclusionColorOffset != -1);

		float lightDiffuseMapLod = 0;
		float reflectMapLod = 0;

		CVector2 pixelClippingDistance(-10000, 10000);
		CVector3 enableShadowFlag(1, 0, 1);
		CVector3 latitudeParam(1, 0, 1);
		CVector4 ambientLightColor = viewportParams.viewport->GetEffectParamOrDefault("ps_ambientLightColor", CVector4(0.1f, 0.1f, 0.1f, 0));

		CVector3 dirLightDirections[2] = 
		{
			viewportParams.viewport->GetEffectParamOrDefault("ps_dirLightDirection0", CVector3(0, 0, 0)),
			viewportParams.viewport->GetEffectParamOrDefault("ps_dirLightDirection1", CVector3(0, 0, 0))
		};

		CVector4 dirLightColors[2] =
		{
			viewportParams.viewport->GetEffectParamOrDefault("ps_dirLightColor0", CVector4(0, 0, 0, 0)),
			viewportParams.viewport->GetEffectParamOrDefault("ps_dirLightColor1", CVector4(0, 0, 0, 0))
		};

		D3D11_MAPPED_SUBRESOURCE mappedResource = {};
		HRESULT result = m_deviceContext->Map(m_pixelConstantBuffer, 0, D3D11_MAP_WRITE_DISCARD, 0, &mappedResource);
		assert(SUCCEEDED(result));
		auto constantBufferPtr = reinterpret_cast<uint8*>(mappedResource.pData);

		memset(constantBufferPtr, 0, mappedResource.RowPitch);

		SetParamValue(constantBufferPtr, m_pixelClippingDistanceOffset, pixelClippingDistance);

		SetParamValue(constantBufferPtr, m_modulateColorOffset, modulateColor);
		SetParamValue(constantBufferPtr, m_ambientColorOffset, ambientColor);
		SetParamValue(constantBufferPtr, m_diffuseColorOffset, diffuseColor);
		SetParamValue(constantBufferPtr, m_specularColorOffset, specularColor);
		SetParamValue(constantBufferPtr, m_shininessOffset, shininess);
		SetParamValue(constantBufferPtr, m_reflectivityOffset, reflectivity);
		SetParamValue(constantBufferPtr, m_normalPowerOffset, normalPower);

		SetParamValue(constantBufferPtr, m_multiDiffuseColorOffset, multiDiffuseColor);
		SetParamValue(constantBufferPtr, m_multiSpecularColorOffset, multiSpecularColor);
		SetParamValue(constantBufferPtr, m_multiShininessOffset, multiShininess);
		SetParamValue(constantBufferPtr, m_multiReflectivityOffset, multiReflectivity);
		SetParamValue(constantBufferPtr, m_multiNormalPowerOffset, multiNormalPower);

		SetParamValue(constantBufferPtr, m_fresnelExpOffset, fresnelExp);
		SetParamValue(constantBufferPtr, m_fresnelLightDiffBiasOffset, fresnelLightDiffBias);
		SetParamValue(constantBufferPtr, m_specularInfluenceOffset, specularInfluence);
		SetParamValue(constantBufferPtr, m_lightDiffusePowerOffset, lightDiffusePower);
		SetParamValue(constantBufferPtr, m_lightDiffuseInfluenceOffset, lightDiffuseInfluence);
		SetParamValue(constantBufferPtr, m_lightDiffuseMapLodOffset, lightDiffuseMapLod);
		SetParamValue(constantBufferPtr, m_reflectMapInfluenceOffset, reflectMapInfluence);
		SetParamValue(constantBufferPtr, m_reflectMapLodOffset, reflectMapLod);

		SetParamValue(constantBufferPtr, m_glareLdrScaleOffset, glareLdrScale);
		SetParamValue(constantBufferPtr, m_normalVectorOffset, normalVector);
		SetParamValue(constantBufferPtr, m_depthBiasOffset, depthBias);
		SetParamValue(constantBufferPtr, m_refAlphaRestrainOffset, refAlphaRestrain);
		SetParamValue(constantBufferPtr, m_velvetParamOffset, velvetParam);

		SetParamValue(constantBufferPtr, m_ambientOcclusionColorOffset, ambientOcclusionColor);
		SetParamValue(constantBufferPtr, m_specularOcclusionColorOffset, specularOcclusionColor);
		SetParamValue(constantBufferPtr, m_pointLightOcclusionColorOffset, pointLightOcclusionColor);
		SetParamValue(constantBufferPtr, m_mainLightOcclusionColorOffset, mainLightOcclusionColor);
		SetParamValue(constantBufferPtr, m_subLightOcclusionColorOffset, subLightOcclusionColor);
		SetParamValue(constantBufferPtr, m_lightMapOcclusionColorOffset, lightMapOcclusionColor);
		SetParamValue(constantBufferPtr, m_reflectMapOcclusionColorOffset, reflectMapOcclusionColor);

		SetParamValue(constantBufferPtr, m_ambientLightColorOffset, ambientLightColor);
		SetParamValue(constantBufferPtr, m_latitudeParamOffset, latitudeParam);
		SetParamValue(constantBufferPtr, m_enableShadowFlagOffset, enableShadowFlag);
		if(m_dirLightDirectionsOffset != -1) reinterpret_cast<CVector3*>(constantBufferPtr + m_dirLightDirectionsOffset)[0] = dirLightDirections[0];
		if(m_dirLightDirectionsOffset != -1) reinterpret_cast<CVector3*>(constantBufferPtr + m_dirLightDirectionsOffset)[1] = dirLightDirections[1];
		if(m_dirLightColorsOffset != -1) reinterpret_cast<CVector4*>(constantBufferPtr + m_dirLightColorsOffset)[0] = dirLightColors[0];
		if(m_dirLightColorsOffset != -1) reinterpret_cast<CVector4*>(constantBufferPtr + m_dirLightColorsOffset)[1] = dirLightColors[1];

		m_deviceContext->Unmap(m_pixelConstantBuffer, 0);
	}
}
示例#25
0
void CManipRot::Draw( GfxTarget *pTARG ) const
{	
	CMatrix4 Mat;
	CMatrix4 VisMat;
	CMatrix4 MatT;
	CMatrix4 MatS;
	CMatrix4 MatR; 
	CVector3 pos;
	CQuaternion rot;
	float scale;

	mManager.mCurTransform.GetMatrix(Mat);

	Mat.DecomposeMatrix(pos, rot, scale);
	VisMat.ComposeMatrix(pos, rot, 1.0f);

	bool bdrawok = true;
	CVector4 v_dir;
	const CReal vizthresh(0.15f);
	if( GetClass() == CManipRX::GetClassStatic() )
	{
		v_dir = CVector4( 1.0f, 0.0f, 0.0f, 0.0f );
	}
	else if( GetClass() == CManipRY::GetClassStatic() )
	{
		v_dir = CVector4( 0.0f, 1.0f, 0.0f, 0.0f );
	}
	else if( GetClass() == CManipRZ::GetClassStatic() )
	{
		v_dir = CVector4( 0.0f, 0.0f, 1.0f, 0.0f );
	}

	CMatrix4 VMatrix = pTARG->MTXI()->RefVMatrix();
	CVector4 wvx = v_dir.Transform(VisMat);
	CVector4 clip_vdir = wvx.Transform(VMatrix);
	if( CFloat::Abs( clip_vdir.GetZ() ) <= vizthresh )
	{
		bdrawok = false;
	}

	///////////////////////////////////////////////
	///////////////////////////////////////////////

	if(mManager.mbWorldTrans)
	{
		MatT.SetToIdentity();
		MatR.SetToIdentity();
		MatT.Translate(pos);

		MatR = rot.ToMatrix();
	}

	MatS.SetScale(mManager.GetManipScale() * MatRotScale);
	Mat = MatS * mmRotModel * MatR * MatT;

	float ColorScale = 1.0f;
	
	if(!bdrawok)
	{
		if(pTARG->FBI()->IsPickState())
			return;
		else
		{
			ColorScale = 0.3f;
		}
	}

	CColor4 ModColor = pTARG->RefModColor(); 


	pTARG->MTXI()->PushMMatrix(Mat);
	pTARG->PushModColor( ModColor*ColorScale );
	{
		pTARG->FXI()->InvalidateStateBlock();

		CVtxBuffer<SVtxV12C4T16>& vb = ork::lev2::CGfxPrimitives::GetCircleStripVB();

		int inumpasses = mManager.GetMaterial()->BeginBlock(pTARG);

		for( int ipass=0; ipass<inumpasses; ipass++ )
		{
			bool bDRAW = mManager.GetMaterial()->BeginPass( pTARG, ipass );

			if( bDRAW )
			{
				//DrawPrimitiveEML( VBuf, eType, bwire );
				pTARG->GBI()->DrawPrimitiveEML( vb );
			}

			mManager.GetMaterial()->EndPass(pTARG);

		}
		mManager.GetMaterial()->EndBlock(pTARG);
	}
	//ork::lev2::CGfxPrimitives::RenderCircleStrip( pTARG );
	pTARG->PopModColor();
	pTARG->MTXI()->PopMMatrix();
}