public static DAEMatrix4 operator *(DAEMatrix4 left, DAEMatrix4 right) { if (left.IsIdentity) { return(right); } if (right.IsIdentity) { return(left); } DAEMatrix4 result = DAEMatrix4.Identity; result.M11 = (left.M11 * right.M11) + (left.M12 * right.M21) + (left.M13 * right.M31) + (left.M14 * right.M41); result.M12 = (left.M11 * right.M12) + (left.M12 * right.M22) + (left.M13 * right.M32) + (left.M14 * right.M42); result.M13 = (left.M11 * right.M13) + (left.M12 * right.M23) + (left.M13 * right.M33) + (left.M14 * right.M43); result.M14 = (left.M11 * right.M14) + (left.M12 * right.M24) + (left.M13 * right.M34) + (left.M14 * right.M44); result.M21 = (left.M21 * right.M11) + (left.M22 * right.M21) + (left.M23 * right.M31) + (left.M24 * right.M41); result.M22 = (left.M21 * right.M12) + (left.M22 * right.M22) + (left.M23 * right.M32) + (left.M24 * right.M42); result.M23 = (left.M21 * right.M13) + (left.M22 * right.M23) + (left.M23 * right.M33) + (left.M24 * right.M43); result.M24 = (left.M21 * right.M14) + (left.M22 * right.M24) + (left.M23 * right.M34) + (left.M24 * right.M44); result.M31 = (left.M31 * right.M11) + (left.M32 * right.M21) + (left.M33 * right.M31) + (left.M34 * right.M41); result.M32 = (left.M31 * right.M12) + (left.M32 * right.M22) + (left.M33 * right.M32) + (left.M34 * right.M42); result.M33 = (left.M31 * right.M13) + (left.M32 * right.M23) + (left.M33 * right.M33) + (left.M34 * right.M43); result.M34 = (left.M31 * right.M14) + (left.M32 * right.M24) + (left.M33 * right.M34) + (left.M34 * right.M44); result.M41 = (left.M41 * right.M11) + (left.M42 * right.M21) + (left.M43 * right.M31) + (left.M44 * right.M41); result.M42 = (left.M41 * right.M12) + (left.M42 * right.M22) + (left.M43 * right.M32) + (left.M44 * right.M42); result.M43 = (left.M41 * right.M13) + (left.M42 * right.M23) + (left.M43 * right.M33) + (left.M44 * right.M43); result.M44 = (left.M41 * right.M14) + (left.M42 * right.M24) + (left.M43 * right.M34) + (left.M44 * right.M44); return(result); }
public static DAEMatrix4 Scaling(double scaleX, double scaleY, double scaleZ) { DAEMatrix4 result = DAEMatrix4.Identity; result.M11 = scaleX == 0 ? 0.001f : scaleX; result.M22 = scaleY == 0 ? 0.001f : scaleY; result.M33 = scaleZ == 0 ? 0.001f : scaleZ; return(result); }
public static DAEMatrix4 Translation(double dx, double dy, double dz) { DAEMatrix4 result = DAEMatrix4.Identity; result.M14 = dx; result.M24 = dy; result.M34 = dz; return(result); }
public static DAEMatrix4 operator *(DAEMatrix4 left, double right) { DAEMatrix4 result = DAEMatrix4.Identity; result.M11 = left.M11 * right; result.M12 = left.M12 * right; result.M13 = left.M13 * right; result.M14 = left.M14 * right; result.M21 = left.M21 * right; result.M22 = left.M22 * right; result.M23 = left.M23 * right; result.M24 = left.M24 * right; result.M31 = left.M31 * right; result.M32 = left.M32 * right; result.M33 = left.M33 * right; result.M34 = left.M34 * right; result.M41 = left.M41 * right; result.M42 = left.M42 * right; result.M43 = left.M43 * right; result.M44 = left.M44 * right; return(result); }
public static DAEMatrix4 operator -(DAEMatrix4 left, DAEMatrix4 right) { DAEMatrix4 result = DAEMatrix4.Identity; result.M11 = left.M11 - right.M11; result.M12 = left.M12 - right.M12; result.M13 = left.M13 - right.M13; result.M14 = left.M14 - right.M14; result.M21 = left.M21 - right.M21; result.M22 = left.M22 - right.M22; result.M23 = left.M23 - right.M23; result.M24 = left.M24 - right.M24; result.M31 = left.M31 - right.M31; result.M32 = left.M32 - right.M32; result.M33 = left.M33 - right.M33; result.M34 = left.M34 - right.M34; result.M41 = left.M41 - right.M41; result.M42 = left.M42 - right.M42; result.M43 = left.M43 - right.M43; result.M44 = left.M44 - right.M44; return(result); }
public static DAEMatrix4 operator +(DAEMatrix4 left, DAEMatrix4 right) { DAEMatrix4 result = DAEMatrix4.Identity; result.M11 = left.M11 + right.M11; result.M12 = left.M12 + right.M12; result.M13 = left.M13 + right.M13; result.M14 = left.M14 + right.M14; result.M21 = left.M21 + right.M21; result.M22 = left.M22 + right.M22; result.M23 = left.M23 + right.M23; result.M24 = left.M24 + right.M24; result.M31 = left.M31 + right.M31; result.M32 = left.M32 + right.M32; result.M33 = left.M33 + right.M33; result.M34 = left.M34 + right.M34; result.M41 = left.M41 + right.M41; result.M42 = left.M42 + right.M42; result.M43 = left.M43 + right.M43; result.M44 = left.M44 + right.M44; return(result); }
internal IDAESceneNode GetSceneNode(DAELoaderNode loader) { List <IDAESceneNode> children = new List <IDAESceneNode>(); // load geometry if (_node.instance_geometry != null && _node.instance_geometry.Length > 0) { foreach (var instGeo in _node.instance_geometry) { Dictionary <string, string> instanceMaterials = new Dictionary <string, string>(); if (instGeo.bind_material != null) { foreach (instance_material instMat in instGeo.bind_material.technique_common) { instanceMaterials.Add(instMat.symbol, instMat.target); } } DAEGeometry geo = loader.LibGeometries.GetGeometry(loader, DAEUtils.GetUrl(instGeo.url).Id); List <IDAEShapeNode> shapes = geo.GetShapeNodes(loader, instanceMaterials, _node.name); foreach (IDAEShapeNode shape in shapes) { children.Add(shape); } } } // load lights if (_node.instance_light != null && _node.instance_light.Length > 0) { foreach (var instLight in _node.instance_light) { IDAESceneNode lightNode = loader.LibLights.GetLightNode(loader, DAEUtils.GetUrl(instLight.url).Id); if (lightNode != null) { children.Add(lightNode); } } } // load local children if (_node.node1 != null && _node.node1.Length > 0) { foreach (node child in _node.node1) { DAENode n = new DAENode(child); IDAESceneNode childNode = n.GetSceneNode(loader); if (childNode != null) { children.Add(childNode); } } } // load remote children if (_node.instance_node != null) { foreach (InstanceWithExtra child in _node.instance_node) { IDAESceneNode childNode = null; var url = DAEUtils.GetUrl(child.url); if (string.IsNullOrEmpty(url.FilePath)) { childNode = loader.LibNodes.GetSceneNode(loader, url.Id); } else { var extLoader = loader.GetLoaderForUrl(url); childNode = extLoader.GetSceneGraph(); //TODO only load node with url.Id } if (childNode != null) { children.Add(childNode); } } } // load transformation DAEMatrix4 finalTrans = DAEMatrix4.Identity; if (_node.Items != null) { for (int i = 0; i < _node.Items.Length; i++) { object trans = _node.Items[i]; ItemsChoiceType2 transType = _node.ItemsElementName[i]; if (transType == ItemsChoiceType2.matrix) { matrix m = trans as matrix; DAEMatrix4 k = DAEMatrix4.Identity; k.M11 = m.Values[0]; k.M12 = m.Values[1]; k.M13 = m.Values[2]; k.M14 = m.Values[3]; k.M21 = m.Values[4]; k.M22 = m.Values[5]; k.M23 = m.Values[6]; k.M24 = m.Values[7]; k.M31 = m.Values[8]; k.M32 = m.Values[9]; k.M33 = m.Values[10]; k.M34 = m.Values[11]; k.M41 = m.Values[12]; k.M42 = m.Values[13]; k.M43 = m.Values[14]; k.M44 = m.Values[15]; finalTrans *= k; } else if (transType == ItemsChoiceType2.rotate) { rotate r = trans as rotate; finalTrans *= DAEMatrix4.Rotation(r.Values[0], r.Values[1], r.Values[2], (r.Values[3] * System.Math.PI / 180)); } else if (transType == ItemsChoiceType2.lookat) { //lookat l = trans as lookat; //finalTrans *= SharpDX.Matrix.LookAtLH( // new SharpDX.Vector3((float)l.Values[0], (float)l.Values[1], (float)l.Values[2]), // new SharpDX.Vector3((float)l.Values[3], (float)l.Values[4], (float)l.Values[5]), // new SharpDX.Vector3((float)l.Values[6], (float)l.Values[7], (float)l.Values[8])); // not implemented } else if (transType == ItemsChoiceType2.scale) { TargetableFloat3 s = trans as TargetableFloat3; finalTrans *= DAEMatrix4.Scaling(s.Values[0], s.Values[1], s.Values[2]); } else if (transType == ItemsChoiceType2.translate) { TargetableFloat3 t = trans as TargetableFloat3; finalTrans *= DAEMatrix4.Translation(t.Values[0], t.Values[1], t.Values[2]); } else if (transType == ItemsChoiceType2.skew) { // not implemented } } } return(loader.Context.CreateGroupNode(_node.name, finalTrans, children.ToArray())); }
abstract public IDAEGroupNode CreateGroupNode(string name, DAEMatrix4 localTransformation, params IDAESceneNode[] childNodes);