示例#1
0
TransformMatrix
TransformMatrix::rotation(double angle, Type type )
{
  switch (type) {
  case SVG:
    return TransformMatrix( cos(angle), sin(angle), 0.0,
                            -sin(angle), cos(angle), 0.0 );
    break;
  default:
    return TransformMatrix( cos(angle), -sin(angle), 0.0,
                            sin(angle), cos(angle), 0.0 );
    break;
  }
}
示例#2
0
void rPrimitiveGrid::DoRecalculateBoundingVolume(){
	rMatrix4 transform = TransformMatrix();

	float halfWidth = m_width / 2.0f;
	float halfDepth = m_depth / 2.0f;

	rVector3 pt;
	rAlignedBox3 b;

	pt.Set(-halfWidth, 0, halfDepth);
	transform.TransformVector3(pt);
	b.AddPoint(pt);

	pt.Set(halfWidth, 0, halfDepth);
	transform.TransformVector3(pt);
	b.AddPoint(pt);

	pt.Set(halfWidth, 0, -halfDepth);
	transform.TransformVector3(pt);
	b.AddPoint(pt);

	pt.Set(-halfWidth, 0, -halfDepth);
	transform.TransformVector3(pt);
	b.AddPoint(pt);

	m_boundingVolume.SetBox(b);
}
示例#3
0
void rPrimitive::Draw(){
	if (m_geometryInvalid){
		RecreateGeometry();
	}

	rMaterial* material = m_engine->content->GetMaterialAsset("default_colored");
	if (!material) return;

	material->SetColor("fragColor", m_faceColor);
		
	rMatrix4& transform = TransformMatrix();

	if (m_drawable->LineVisibility() && m_drawable->FaceVisibility()){
		material->SetColor("fragColor", m_faceColor);
		m_engine->renderer->RenderShadedWithEdges(m_geometry, transform, material, m_edgeColor);
	}
	else if (m_drawable->LineVisibility()){
		material->SetColor("fragColor", m_edgeColor);
		m_engine->renderer->RenderGeometry(m_geometry, transform, "wire", material);
	}
	else if (m_drawable->FaceVisibility()){
		material->SetColor("fragColor", m_faceColor);
		m_engine->renderer->RenderGeometry(m_geometry, transform, "shaded", material);
	}
}
示例#4
0
void rPrimitiveCone::DoRecalculateBoundingVolume() {
    rMatrix4 transform = TransformMatrix();

    rAlignedBox3 b;
    rVector3 pt = rVector3::ForwardVector * m_radius;
    transform.TransformVector3(pt);
    b.AddPoint(pt);

    pt = rVector3::BackwardVector * m_radius;
    transform.TransformVector3(pt);
    b.AddPoint(pt);

    pt = rVector3::LeftVector * m_radius;
    transform.TransformVector3(pt);
    b.AddPoint(pt);

    pt = rVector3::RightVector * m_radius;
    transform.TransformVector3(pt);
    b.AddPoint(pt);

    pt = rVector3::UpVector * m_height;
    transform.TransformVector3(pt);
    b.AddPoint(pt);

    m_boundingVolume.SetBox(b);
}
示例#5
0
TransformMatrix TransformMatrix::RotateZ( float rads )
{
    return TransformMatrix( cos( rads ), -sin( rads ), 0.0, 0.0,
        sin( rads ), cos( rads ), 0.0, 0.0,
        0.0, 0.0, 1.0, 0.0,
        0.0, 0.0, 0.0, 1.0 );
}
    TransformMatrix operator*(const TransformMatrix& other) const {
        float a = _m[0] * other._m[0] + _m[1] * other._m[3];
        float b = _m[0] * other._m[1] + _m[1] * other._m[4];
        float c = _m[0] * other._m[2] + _m[1] * other._m[5] + _m[2];
        float d = _m[3] * other._m[0] + _m[4] * other._m[3];
        float e = _m[3] * other._m[1] + _m[4] * other._m[4];
        float f = _m[3] * other._m[2] + _m[4] * other._m[5] + _m[5];

        return TransformMatrix(a, b, c, d, e, f);
    }
示例#7
0
TransformMatrix
TransformMatrix::operator*(const TransformMatrix & other) const
{
  return TransformMatrix( _m11*other._m11+_m12*other._m21,
                          _m11*other._m12+_m12*other._m22,
                          _m11*other._m13+_m12*other._m23+_m13,
                          _m21*other._m11+_m22*other._m21,
                          _m21*other._m12+_m22*other._m22,
                          _m21*other._m13+_m22*other._m23+_m23 );
}
void SceneAnimator::Init(const aiScene* pScene){// this will build the skeleton based on the scene passed to it and CLEAR EVERYTHING
	if(!pScene->HasAnimations()) return;
	Release();
	
	Skeleton = CreateBoneTree( pScene->mRootNode, NULL);
	ExtractAnimations(pScene);
	
	for (unsigned int i = 0; i < pScene->mNumMeshes;++i){
		const aiMesh* mesh = pScene->mMeshes[i];
		
		for (unsigned int n = 0; n < mesh->mNumBones;++n){
			const aiBone* bone = mesh->mBones[n];
			std::map<std::string, cBone*>::iterator found = BonesByName.find(bone->mName.data);
			if(found != BonesByName.end()){// FOUND IT!!! woohoo, make sure its not already in the bone list
				bool skip = false;
				for(size_t j(0); j< Bones.size(); j++){
					std::string bname = bone->mName.data;
					if(Bones[j]->Name == bname) {
						skip = true;// already inserted, skip this so as not to insert the same bone multiple times
						break;
					}
				}
				if(!skip){// only insert the bone if it has not already been inserted
					std::string tes = found->second->Name;
					TransformMatrix(found->second->Offset, bone->mOffsetMatrix);
					found->second->Offset.Transpose();// transpoce their matrix to get in the correct format
					Bones.push_back(found->second);
					BonesToIndex[found->first] = (unsigned int)Bones.size()-1;
				}
			} 
		}
	}
	Transforms.resize( Bones.size());
	float timestep = 1.0f/30.0f;// 30 per second
	for(size_t i(0); i< Animations.size(); i++){// pre calculate the animations
		SetAnimIndex((unsigned int)i);
		float dt = 0;
		for(float ticks = 0; ticks < Animations[i].Duration; ticks += Animations[i].TicksPerSecond/30.0f){
			dt +=timestep;
			Calculate(dt);
			Animations[i].Transforms.push_back(std::vector<mat4>());
			std::vector<mat4>& trans = Animations[i].Transforms.back();
			for( size_t a = 0; a < Transforms.size(); ++a){
				mat4 rotationmat =  Bones[a]->Offset * Bones[a]->GlobalTransform;
				trans.push_back(rotationmat);
			}
		}
	}
	OUTPUT_DEBUG_MSG("Finished loading animations with "<<Bones.size()<<" bones");
}
static void
SampleValue(float aPortion, Animation& aAnimation, nsStyleAnimation::Value& aStart,
            nsStyleAnimation::Value& aEnd, Animatable* aValue)
{
  nsStyleAnimation::Value interpolatedValue;
  NS_ASSERTION(aStart.GetUnit() == aEnd.GetUnit() ||
               aStart.GetUnit() == nsStyleAnimation::eUnit_None ||
               aEnd.GetUnit() == nsStyleAnimation::eUnit_None, "Must have same unit");
  nsStyleAnimation::Interpolate(aAnimation.property(), aStart, aEnd,
                                aPortion, interpolatedValue);
  if (aAnimation.property() == eCSSProperty_opacity) {
    *aValue = interpolatedValue.GetFloatValue();
    return;
  }

  nsCSSValueList* interpolatedList = interpolatedValue.GetCSSValueListValue();

  TransformData& data = aAnimation.data().get_TransformData();
  nsPoint origin = data.origin();
  // we expect all our transform data to arrive in css pixels, so here we must
  // adjust to dev pixels.
  double cssPerDev = double(nsDeviceContext::AppUnitsPerCSSPixel())
                     / double(data.appUnitsPerDevPixel());
  gfxPoint3D mozOrigin = data.mozOrigin();
  mozOrigin.x = mozOrigin.x * cssPerDev;
  mozOrigin.y = mozOrigin.y * cssPerDev;
  gfxPoint3D perspectiveOrigin = data.perspectiveOrigin();
  perspectiveOrigin.x = perspectiveOrigin.x * cssPerDev;
  perspectiveOrigin.y = perspectiveOrigin.y * cssPerDev;
  nsDisplayTransform::FrameTransformProperties props(interpolatedList,
                                                     mozOrigin,
                                                     perspectiveOrigin,
                                                     data.perspective());
  gfx3DMatrix transform =
    nsDisplayTransform::GetResultingTransformMatrix(props, origin,
                                                    data.appUnitsPerDevPixel(),
                                                    &data.bounds());
  gfxPoint3D scaledOrigin =
    gfxPoint3D(NS_round(NSAppUnitsToFloatPixels(origin.x, data.appUnitsPerDevPixel())),
               NS_round(NSAppUnitsToFloatPixels(origin.y, data.appUnitsPerDevPixel())),
               0.0f);

  transform.Translate(scaledOrigin);

  InfallibleTArray<TransformFunction> functions;
  functions.AppendElement(TransformMatrix(transform));
  *aValue = functions;
}
// ------------------------------------------------------------------------------------------------
// Recursively creates an internal node structure matching the current scene and animation.
cBone* SceneAnimator::CreateBoneTree( aiNode* pNode, cBone* pParent){
	cBone* internalNode = new cBone();// create a node
	internalNode->Name = pNode->mName.data;// get the name of the bone
	internalNode->Parent = pParent; //set the parent, in the case this is theroot node, it will be null

	BonesByName[internalNode->Name] = internalNode;// use the name as a key
	TransformMatrix(internalNode->LocalTransform, pNode->mTransformation);
	internalNode->LocalTransform.Transpose();
	internalNode->OriginalLocalTransform = internalNode->LocalTransform;// a copy saved
	CalculateBoneToWorldTransform(internalNode);

	// continue for all child nodes and assign the created internal nodes as our children
	for( unsigned int a = 0; a < pNode->mNumChildren; a++){// recursivly call this function on all children
		internalNode->Children.push_back(CreateBoneTree( pNode->mChildren[a], internalNode));
	}
	return internalNode;
}
示例#11
0
D3DXMATRIX SUIPictureBox::TransformMatrixImage()
{
	D3DXMATRIX transformMatrix;

	if(picture->GetTarget())
	{
		D3DXMatrixTransformation2D(
		&transformMatrix, 
		&D3DXVECTOR2(PositionImage().x, PositionImage().y),
		0, 
		&D3DXVECTOR2((float)GetTexRect().Width / picture->GetTarget()->GetWidth(), 
			(float)GetTexRect().Height / picture->GetTarget()->GetHeight()),
		&D3DXVECTOR2(0, 0),
		0, 
		&D3DXVECTOR2(0, 0));
	}
	else
	{
		D3DXMatrixTransformation2D(
		&transformMatrix, 
		&D3DXVECTOR2(PositionImage().x, PositionImage().y),
		0, 
		&D3DXVECTOR2(1, 1),
		&D3DXVECTOR2(0, 0),
		0, 
		&D3DXVECTOR2(0, 0));
	}	

	if (isAbsoluteRender && father)
	{
		D3DXMATRIX fMatrix = TransformMatrix();
		D3DXMATRIX result = transformMatrix * fMatrix;
		return result;
	}

	return transformMatrix;
}
 // Translation
 static TransformMatrix translate(const Point& delta) {
     return TransformMatrix(1, 0, delta.x, 0, 1, delta.y);
 }
 // Uniform scale
 static TransformMatrix scale(float s) {
     return TransformMatrix(s, 0, 0, 0, s, 0);
 }
// ------------------------------------------------------------------------------------------------
// Evaluates the animation tracks for a given time stamp. 
void cAnimEvaluator::Evaluate( float pTime, std::map<std::string, cBone*>& bones) {

	pTime *= TicksPerSecond;
	
	float time = 0.0f;
	if( Duration > 0.0)
		time = fmod( pTime, Duration);

	// calculate the transformations for each animation channel
	for( unsigned int a = 0; a < Channels.size(); a++){
		const cAnimationChannel* channel = &Channels[a];
		std::map<std::string, cBone*>::iterator bonenode = bones.find(channel->Name);

		if(bonenode == bones.end()) { 
			OUTPUT_DEBUG_MSG("did not find the bone node "<<channel->Name);
			continue;
		}

		// ******** Position *****
		aiVector3D presentPosition( 0, 0, 0);
		if( channel->mPositionKeys.size() > 0){
			// Look for present frame number. Search from last position if time is after the last time, else from beginning
			// Should be much quicker than always looking from start for the average use case.
			unsigned int frame = (time >= mLastTime) ? std::get<0>(mLastPositions[a]): 0;
			while( frame < channel->mPositionKeys.size() - 1){
				if( time < channel->mPositionKeys[frame+1].mTime){
					break;
				}
				frame++;
			}

			// interpolate between this frame's value and next frame's value
			unsigned int nextFrame = (frame + 1) % channel->mPositionKeys.size();
	
			const aiVectorKey& key = channel->mPositionKeys[frame];
			const aiVectorKey& nextKey = channel->mPositionKeys[nextFrame];
			double diffTime = nextKey.mTime - key.mTime;
			if( diffTime < 0.0)
				diffTime += Duration;
			if( diffTime > 0) {
				float factor = float( (time - key.mTime) / diffTime);
				presentPosition = key.mValue + (nextKey.mValue - key.mValue) * factor;
			} else {
				presentPosition = key.mValue;
			}
			std::get<0>(mLastPositions[a]) = frame;
		}
		// ******** Rotation *********
		aiQuaternion presentRotation( 1, 0, 0, 0);
		if( channel->mRotationKeys.size() > 0)
		{
			unsigned int frame = (time >= mLastTime) ? std::get<1>(mLastPositions[a]) : 0;
			while( frame < channel->mRotationKeys.size()  - 1){
				if( time < channel->mRotationKeys[frame+1].mTime)
					break;
				frame++;
			}

			// interpolate between this frame's value and next frame's value
			unsigned int nextFrame = (frame + 1) % channel->mRotationKeys.size() ;

			const aiQuatKey& key = channel->mRotationKeys[frame];
			const aiQuatKey& nextKey = channel->mRotationKeys[nextFrame];
			double diffTime = nextKey.mTime - key.mTime;
			if( diffTime < 0.0) diffTime += Duration;
			if( diffTime > 0) {
				float factor = float( (time - key.mTime) / diffTime);
				aiQuaternion::Interpolate( presentRotation, key.mValue, nextKey.mValue, factor);
			} else presentRotation = key.mValue;
			std::get<1>(mLastPositions[a]) = frame;
		}

		// ******** Scaling **********
		aiVector3D presentScaling( 1, 1, 1);
		if( channel->mScalingKeys.size() > 0) {
			unsigned int frame = (time >= mLastTime) ? std::get<2>(mLastPositions[a]) : 0;
			while( frame < channel->mScalingKeys.size() - 1){
				if( time < channel->mScalingKeys[frame+1].mTime)
					break;
				frame++;
			}

			presentScaling = channel->mScalingKeys[frame].mValue;
			std::get<2>(mLastPositions[a]) = frame;
		}

		aiMatrix4x4 mat = aiMatrix4x4( presentRotation.GetMatrix());

		mat.a1 *= presentScaling.x; mat.b1 *= presentScaling.x; mat.c1 *= presentScaling.x;
		mat.a2 *= presentScaling.y; mat.b2 *= presentScaling.y; mat.c2 *= presentScaling.y;
		mat.a3 *= presentScaling.z; mat.b3 *= presentScaling.z; mat.c3 *= presentScaling.z;
		mat.a4 = presentPosition.x; mat.b4 = presentPosition.y; mat.c4 = presentPosition.z;
		mat.Transpose();
		
		TransformMatrix(bonenode->second->LocalTransform, mat);
	}
	mLastTime = time;
}
 // Non-uniform scale
 static TransformMatrix scale(float x, float y) {
     return TransformMatrix(x, 0, 0, 0, y, 0);
 }
示例#16
0
TransformMatrix
TransformMatrix::scaling(double sx, double sy)
{
  return TransformMatrix( sx, 0.0, 0.0,
                          0.0, sy, 0.0 );
}
示例#17
0
TransformMatrix
TransformMatrix::translation(const Point & point)
{
  return TransformMatrix( 1.0, 0.0, point.x,
                          0.0, 1.0, point.y );
}
示例#18
0
TransformMatrix
TransformMatrix::translation(double dx, double dy)
{
  return TransformMatrix( 1.0, 0.0, dx,
                          0.0, 1.0, dy );
}
    // Rotation in radians around origin
    static TransformMatrix rotate(float angle) {
        float c = cos(angle);
        float s = sin(angle);

        return TransformMatrix(c, -s, 0, s, c, 0);
    }
示例#20
0
void rPawn::Draw(){
	if (_modelInstance){
		rMatrix4 transform = TransformMatrix();
		m_engine->renderer->RenderAnimatedModel(_modelInstance.get(), transform, &m_animationController);
	}
}