using System;
using System.Xml;
using CDAColladaNET.Import.Attributes;
// Copyright (c) 2005 Accelerated Pictures, LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
namespace ColladaNET.Import{
public class TransformNode : SidNode
{
#region Enums
public enum ETransformNodeType { lookat , matrix , perspective , rotate , scale , skew , translate };
#endregion
#region Static Methods
public static bool IsTransformNode( XmlNode node )
{
try
{
ETransformNodeType test = ((ETransformNodeType)(Enum.Parse( typeof(ETransformNodeType) , node.LocalName , true )));
}
catch
{
return false;
}
return true;
}
#endregion
#region Accessors
#region TransformNodeType
private bool mbTransformNodeType = false;
private ETransformNodeType mTransformNodeType;
public ETransformNodeType TransformNodeType
{
get
{
if ( mbTransformNodeType == false )
{
mTransformNodeType = ((ETransformNodeType)(Enum.Parse( typeof(ETransformNodeType) , XmlSource.LocalName , true )));
mbTransformNodeType = true;
}
return mTransformNodeType;
}
}
#endregion
#region Values
private bool mbValues = false;
private float [] mValues;
public float [] Values
{
get
{
if ( mbValues == false )
{
string innerText = XmlSource.InnerText;
string [] tokens = innerText.Split( kWhitespace );
int nonNullTokenCount = 0;
for ( int scanIndex = 0 ; scanIndex < tokens.Length ; scanIndex++ )
{
if ( tokens[scanIndex].Length > 0 )
{
nonNullTokenCount++;
}
}
mValues = new float[nonNullTokenCount];
int valueIndex = 0;
for( int tokenIndex = 0 ; (tokenIndex < tokens.Length)&&(valueIndex < mValues.Length) ; tokenIndex++ )
{
string token = tokens[tokenIndex];
if ( token.Length > 0 )
{
mValues[valueIndex++] = float.Parse(token);
}
}
mbValues = true;
}
return mValues;
}
}
#endregion
#region Specific Type Accessors
#region Lookat
public float [] Lookat_EyePosition
{
get
{
float [] result = new float[3];
result[0] = Values[0];
result[1] = Values[1];
result[2] = Values[2];
return result;
}
}
public float [] Lookat_InterestPosition
{
get
{
float [] result = new float[3];
result[0] = Values[3];
result[1] = Values[4];
result[2] = Values[5];
return result;
}
}
public float [] Lookat_Up
{
get
{
float [] result = new float[3];
result[0] = Values[6];
result[1] = Values[7];
result[2] = Values[8];
return result;
}
}
#endregion
#region Matrix
public float [][] Matrix
{
get
{
float [][] result = new float[4][];
result[0][0] = Values[0];
result[0][1] = Values[1];
result[0][2] = Values[2];
result[0][3] = Values[3];
result[1][0] = Values[4];
result[1][1] = Values[5];
result[1][2] = Values[6];
result[1][3] = Values[7];
result[2][0] = Values[8];
result[2][1] = Values[9];
result[2][2] = Values[10];
result[2][3] = Values[11];
result[3][0] = Values[12];
result[3][1] = Values[13];
result[3][2] = Values[14];
result[3][3] = Values[15];
return result;
}
}
#endregion
#region Perspective
public float PerspectiveFov
{
get
{
return Values[0];
}
}
#endregion
#region Rotate
public float [] RotationAxis
{
get
{
float [] result = new float[3];
result[0] = Values[0];
result[1] = Values[1];
result[2] = Values[2];
return result;
}
}
public float RotationAngle
{
get
{
return Values[3];
}
}
#endregion
#region Scale
public float [] Scale
{
get
{
return Values;
}
}
#endregion
#region Skew
public float [] Skew
{
get
{
return Values;
}
}
#endregion
#region Translate
public float [] Translate
{
get
{
return Values;
}
}
#endregion
#endregion
#endregion
#region Constructors
public TransformNode( XmlNode source ) : base( source )
{
}
#endregion
}
}
|