本文整理汇总了C#中System.Vector3.TransformCoordinate方法的典型用法代码示例。如果您正苦于以下问题:C# Vector3.TransformCoordinate方法的具体用法?C# Vector3.TransformCoordinate怎么用?C# Vector3.TransformCoordinate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Vector3
的用法示例。
在下文中一共展示了Vector3.TransformCoordinate方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: distanceFromCameraPlain
public float distanceFromCameraPlain()
{
Vector3 currentCenter = new Vector3(center.X, center.Y, center.Z);
currentCenter.TransformCoordinate(device.Transform.World);
currentCenter.TransformCoordinate(device.Transform.View);
return currentCenter.Z;
}
示例2: doAction
public override void doAction(int Key)
{
foreach(Target ikx in cocs.allTargets){
if(this.center.Y > 0){
Vector3 foo = new Vector3(this.center.X,this.center.Y,center.Z);
foo.TransformCoordinate(device.Transform.World);
if(ikx.distanceFromPoint(foo) < 0.5f*size_of_one_rectangle){
if(ikx.active){
cocs.toRemoveFromUniverse.Add(ikx);
ikx.active = false;
cocs.aArea[ikx.posX,ikx.posZ] = true;
cocs.targets++;
cocs.numberOfTargets--;
}
cocs.toRemoveFromUniverse.Add(this);
}
}
}
}
示例3: RenderShadow
/// <summary>
/// Renders the 2D hard-edged shadow that would be cast from this ConvexHull's polygonal
/// geometry by a light positioned at lightPosWS.
/// </summary>
/// <param name="lightPosWS">The position of the light in world coordinates.</param>
public void RenderShadow(Vector2 lightPosWS)
{
Vector3 UVOffset = new Vector3(0.0f, -0.5f, 0.0f);
// Transform the light position into model space
Vector2 lightPos = Vector2.TransformCoordinate(lightPosWS, Matrix.Invert(worldMatrix));
List<Edge> contourEdges = new List<Edge>();
for (int edgeIndex = 0; edgeIndex < polygonGeometry.NumEdges; ++edgeIndex)
{
Edge edge = polygonGeometry.GetEdge(edgeIndex);
Vector2 edgeCenter = (edge.Vertex1Pos + edge.Vertex2Pos) * 0.5f;
Vector2 incidentLightDir = edgeCenter - lightPos;
// If the edge faces away from the light source
if (Vector2.Dot(incidentLightDir, edge.Normal) >= 0.0f)
{
contourEdges.Add(edge);
}
}
if (contourEdges.Count < 1 || contourEdges.Count == polygonGeometry.NumEdges)
{
return;
}
const float ExtrudeMagnitude = 1000.0f;
List<Quad> quads = new List<Quad>();
int quadIndex = 0;
foreach (Edge edge in contourEdges)
{
Vector3 lightPosVec3 = new Vector3(lightPos.X, lightPos.Y, 1.0f);
Vector3 vertex1 = new Vector3(
edge.Vertex1Pos.X, edge.Vertex1Pos.Y, 1.0f);
Vector3 vertex2 = new Vector3(
edge.Vertex2Pos.X, edge.Vertex2Pos.Y, 1.0f);
// Transform the position data from model space to world space
vertex1.TransformCoordinate(worldMatrix);
vertex2.TransformCoordinate(worldMatrix);
lightPosVec3.TransformCoordinate(worldMatrix);
Quad quad = new Quad();
Color shadowColor = Color.FromArgb((int)(1 * 255.0f), 0, 0, 0);
quad.Vertices[2 * quadIndex + 0].Position = vertex1 + UVOffset;
quad.Vertices[2 * quadIndex + 0].Color = shadowColor.ToArgb();
quad.Vertices[2 * quadIndex + 1].Position = vertex1 + ExtrudeMagnitude * (vertex1 - lightPosVec3)
+ UVOffset;
quad.Vertices[2 * quadIndex + 1].Color = shadowColor.ToArgb();
quad.Vertices[2 * quadIndex + 2].Position = vertex2 + UVOffset;
quad.Vertices[2 * quadIndex + 2].Color = shadowColor.ToArgb();
quad.Vertices[2 * quadIndex + 3].Position = vertex2 + ExtrudeMagnitude * (vertex2 - lightPosVec3)
+ UVOffset;
quad.Vertices[2 * quadIndex + 3].Color = shadowColor.ToArgb();
quads.Add(quad);
}
renderer.Begin(effect);
renderer.WorldMatrix = Matrix.Identity;
effect.SetValue("world", renderer.WorldMatrix);
effect.SetValue("worldViewProj", renderer.WorldViewProjectionMatrix);
renderer.SetPass(3);
renderer.Device.VertexFormat = Direct3D.CustomVertex.PositionColoredTextured.Format;
foreach (Quad quad in quads)
{
renderer.Device.DrawUserPrimitives(Direct3D.PrimitiveType.TriangleStrip, 2, quad.Vertices);
}
renderer.End();
}
示例4: ComputeBoundingSphere
private void ComputeBoundingSphere(JointFrame frame, Matrix parentMatrix)
{
// Give the meshes their proper relative positions within the cell
Matrix combinedMatrix = frame.TransformationMatrix * parentMatrix;
// If this frame contains a mesh, transform its bounding sphere and
// combine it with the overall bounds for the cell
if (frame.MeshContainer!=null)
{
Cytoplasm cyt = (Cytoplasm)frame.MeshContainer;
float radius = cyt.BoundRadius;
Vector3 centre = cyt.BoundCentre;
// transform the sphere's centre
centre.TransformCoordinate(combinedMatrix);
// Transform the sphere's radius (to scale it - the original vertices are probably not at their final scale
Vector3 radiusVector = new Vector3(radius, 0, 0); // create a vector of size radius
radiusVector.TransformCoordinate(combinedMatrix); // transform it to rescale it
radius = radiusVector.Length(); // scaled radius is the length of the transformed vector
// Combine this sphere with the others in the cell
RelSphere.CombineBounds(centre, radius);
}
// Now propagate the new combined matrix through to my siblings and children
if (frame.Sibling != null) // recurse through siblings
{
ComputeBoundingSphere(frame.Sibling, parentMatrix);
}
if (frame.FirstChild != null) // recurse through children
{
ComputeBoundingSphere(frame.FirstChild, combinedMatrix);
}
}
示例5: world2Screen
protected override void world2Screen(ILPoint3Df p1_3D, ILPoint3Df p2_3D, out Point p1_2D, out Point p2_2D ) {
Matrix mat = m_device.Transform.World;
mat *= m_device.Transform.View;
mat *= m_device.Transform.Projection;
Vector3 s = new Vector3(p1_3D.X, p1_3D.Y, p1_3D.Z);
Vector3 e = new Vector3(p2_3D.X, p2_3D.Y, p2_3D.Z);
s.TransformCoordinate(mat);
e.TransformCoordinate(mat);
s.X = (s.X / 2.0f + 0.5f);
e.X = (e.X / 2.0f + 0.5f);
s.Y = -(s.Y / 2.0f - 0.5f);
e.Y = -(e.Y / 2.0f - 0.5f);
// variant with margin over viewport
//float multMarg = (m_device.Viewport.Width / 100.0f);
//startX = (int)(multMarg * (100.0f - 0.0f * m_margin) * s.X + m_margin * multMarg);
//endX = (int)(multMarg * (100.0f - 0.0f * m_margin) * e.X + m_margin * multMarg);
//multMarg = (m_device.Viewport.Height / 100.0f);
//startY = (int)(multMarg * (100.0f - 0.0f * m_margin) * s.Y + m_margin * multMarg);
//endY = (int)(multMarg * (100.0f - 0.0f * m_margin) * e.Y + m_margin * multMarg);
float multMarg = (m_device.Viewport.Width);
p1_2D = new Point ((int)(multMarg * s.X),(int)(m_device.Viewport.Height * s.Y));
p2_2D = new Point ((int)(multMarg * e.X),(int)(m_device.Viewport.Height * e.Y));
}
示例6: distanceFromPoint
public float distanceFromPoint(float x, float y, float z)
{
Vector3 currentCenter = new Vector3(center.X, center.Y, center.Z);
currentCenter.TransformCoordinate(device.Transform.World);
return (float)Math.Sqrt(Math.Pow(currentCenter.X - x, 2) + Math.Pow(currentCenter.Y - y, 2) + Math.Pow(currentCenter.Z - z, 2));
}
示例7: DrawAxis
private void DrawAxis()
{
Matrix mtxWorld = Matrix.Identity;
if(!this.IsRoot)
mtxWorld = Translation * this.Parent_DX.CombinedTransformationMatrix;
else
mtxWorld = Translation * this.CombinedTransformationMatrix;
float fltScale = ((this.MinDimension + this.MaxDimension)/2 * 0.15f);
if(fltScale > 0.1f) fltScale = 0.1f;
//Draw X Axis
m_d3dDevice.Material = m_matXAxis;
m_d3dDevice.Transform.World = Matrix.RotationY(Geometry.DegreeToRadian(-90)) * Matrix.Translation(10 * fltScale, 0.0f, 0.0f) * mtxWorld * Device.Transform.World1;
m_mshAxisCylinder.DrawSubset(0);
m_d3dDevice.Transform.World = Matrix.RotationY(Geometry.DegreeToRadian(-90)) * Matrix.Translation(20 * fltScale, 0.0f, 0.0f) * mtxWorld * Device.Transform.World1;
m_mshAxisCone.DrawSubset(0);
//Draw Y Axis
m_d3dDevice.Material = m_matYAxis;
m_d3dDevice.Transform.World = Matrix.RotationX(Geometry.DegreeToRadian(-90)) * Matrix.Translation(0.0f, 10 * fltScale, 0.0f) * mtxWorld * Device.Transform.World1;
m_mshAxisCylinder.DrawSubset(0);
m_d3dDevice.Transform.World = Matrix.RotationX(Geometry.DegreeToRadian(90)) * Matrix.Translation(0.0f, 20 * fltScale, 0.0f) * mtxWorld * Device.Transform.World1;
m_mshAxisCone.DrawSubset(0);
//Draw Z Axis
m_d3dDevice.Material = m_matZAxis;
m_d3dDevice.Transform.World = Matrix.Translation(0.0f, 0.0f, 10 * fltScale) * mtxWorld * Device.Transform.World1;
m_mshAxisCylinder.DrawSubset(0);
m_d3dDevice.Transform.World = Matrix.RotationY(Geometry.DegreeToRadian(180)) * Matrix.Translation(0.0f, 0.0f, 20 * fltScale) * mtxWorld * Device.Transform.World1;
m_mshAxisCone.DrawSubset(0);
//Draw X axis label
m_d3dDevice.Transform.World = Matrix.Translation(25 * fltScale, 0.0f, 0.0f) * mtxWorld * Device.Transform.World1;
Vector3 tmp = new Vector3();
tmp.TransformCoordinate(m_d3dDevice.Transform.World);
Matrix m =m_d3dDevice.Transform.View;
m.Invert();
m.M41 = tmp.X;
m.M42 = tmp.Y;
m.M43 = tmp.Z;
m_d3dDevice.Transform.World = m;
Device.Material = Util_DX.WhiteMaterial();
Device.SetTexture(0,texX);
m_mshAxisLabel.DrawSubset(0);
Device.SetTexture(0,null);
//Draw Y Axis Label
m_d3dDevice.Transform.World = Matrix.Translation(0.0f, 25 * fltScale, 0.0f) * mtxWorld * Device.Transform.World1;
tmp = new Vector3();
tmp.TransformCoordinate(m_d3dDevice.Transform.World);
m =m_d3dDevice.Transform.View;
m.Invert();
m.M41 = tmp.X;
m.M42 = tmp.Y;
m.M43 = tmp.Z;
m_d3dDevice.Transform.World = m;
Device.Material = Util_DX.WhiteMaterial();
Device.SetTexture(0,texY);
m_mshAxisLabel.DrawSubset(0);
Device.SetTexture(0,null);
//Draw Z Axis Label
m_d3dDevice.Transform.World = Matrix.Translation(0.0f, 0.0f, 25 * fltScale) * mtxWorld * Device.Transform.World1;
tmp = new Vector3();
tmp.TransformCoordinate(m_d3dDevice.Transform.World);
m =m_d3dDevice.Transform.View;
m.Invert();
m.M41 = tmp.X;
m.M42 = tmp.Y;
m.M43 = tmp.Z;
m_d3dDevice.Transform.World = m;
Device.Material = Util_DX.WhiteMaterial();
Device.SetTexture(0,texZ);
m_mshAxisLabel.DrawSubset(0);
Device.SetTexture(0,null);
}
示例8: OnMouseMove
protected override void OnMouseMove(System.Windows.Forms.MouseEventArgs e)
{
if ( !GetAsyncKeyState(ArcBall.CameraControlKey) && (e.Button == MouseButtons.Left) && selectedObjects.Count != 0 )
{
if (_editMode == EditMode.Rotate)
{
Vector3 direction = camera.TargetPoint - camera.EyePosition;
Vector3 horizontal = Vector3.Cross(direction, camera.UpVector);
Vector3 upVector = camera.UpVector;
horizontal.Normalize();
upVector.Normalize();
float rotateX = (0.5f * (mouseDownX - e.X)) * upVector.X +
(0.5f * (e.Y - mouseDownY)) * horizontal.X + _startRotation.X;
float rotateY = (0.5f * (mouseDownX - e.X)) * upVector.Y +
(0.5f * (e.Y - mouseDownY)) * horizontal.Y + _startRotation.Y;
float rotateZ = (0.5f * (mouseDownX - e.X)) * upVector.Z +
(0.5f * (e.Y - mouseDownY)) * horizontal.Z + _startRotation.Z;
Midget.Events.EventFactory.Instance.GenerateTransformationRequestEvent(this,selectedObjects,
new AxisValue(rotateX, rotateY, rotateZ),
Midget.Events.Object.Transformation.Transformation.Rotate);
mouseDownX = e.X;
mouseDownY = e.Y;
dm.UpdateViews();
}
else if (_editMode == EditMode.Move)
{
// our picking
Vector3 pickRayOrigin = new Vector3();
Vector3 pickRayDir = new Vector3();
Vector3 pickRayOriginNew = new Vector3();
Vector3 pickRayDirNew = new Vector3();
Vector3 direction = camera.TargetPoint - camera.EyePosition;
Vector3 horizontal = Vector3.Cross(direction, camera.UpVector);
Vector3 upVector = camera.UpVector;
horizontal.Normalize();
upVector.Normalize();
// grab the last selected object
IObject3D selObj = (IObject3D)selectedObjects[selectedObjects.Count - 1];
// original mouse position
camera.UnProjectCoordinates(mouseDownX, mouseDownY, this.Width,
this.Height, ref pickRayOrigin, ref pickRayDir);
// new mouse position
camera.UnProjectCoordinates(e.X,
e.Y, this.Width,
this.Height, ref pickRayOriginNew, ref pickRayDirNew);
// transform by world and object model space
pickRayOrigin.TransformCoordinate(Matrix.Invert(camera.WorldMatrix));
pickRayOriginNew.TransformCoordinate(Matrix.Invert(camera.WorldMatrix));
// find the movement vector
Vector3 result = pickRayOriginNew - pickRayOrigin;
// pretty crappy compensation
if (this.Camera is PerspectiveMidgetCamera)
{
result *= 10.0f;
}
// generate an axis value to move by
AxisValue axes = new AxisValue(
selObj.Translation.X + result.X,
selObj.Translation.Y + result.Y,
selObj.Translation.Z + result.Z);
Midget.Events.EventFactory.Instance.GenerateTransformationRequestEvent(this, selectedObjects,
axes,
Midget.Events.Object.Transformation.Transformation.Translate);
mouseDownX = e.X;
mouseDownY = e.Y;
dm.UpdateViews();
}
else if (_editMode == EditMode.Scale)
{
float scaleX = 0.05f * (mouseDownX - e.X) + _startScaling.X;
float scaleY = 0.05f * (mouseDownY - e.Y) + _startScaling.Y;
Midget.Events.EventFactory.Instance.GenerateTransformationRequestEvent(this,selectedObjects,
new AxisValue(scaleY,scaleY,scaleY),
Midget.Events.Object.Transformation.Transformation.Scale);
mouseDownX = e.X;
mouseDownY = e.Y;
//.........这里部分代码省略.........
示例9: DrawAxis
private void DrawAxis()
{
//Draw X Axis
m_d3dDevice.Material = m_matXAxis;
m_d3dDevice.Transform.World = Matrix.RotationY(Geometry.DegreeToRadian(-90)) * Matrix.Translation(1.0f, 0.0f, 0.0f) * m_d3dDevice.Transform.World1;
m_mshAxisCylinder.DrawSubset(0);
m_d3dDevice.Transform.World = Matrix.RotationY(Geometry.DegreeToRadian(-90)) * Matrix.Translation(2.0f, 0.0f, 0.0f) * m_d3dDevice.Transform.World1;
m_mshAxisCone.DrawSubset(0);
//Draw Y Axis
m_d3dDevice.Material = m_matYAxis;
m_d3dDevice.Transform.World = Matrix.RotationX(Geometry.DegreeToRadian(-90)) * Matrix.Translation(0.0f, 1.0f, 0.0f) * m_d3dDevice.Transform.World1;
m_mshAxisCylinder.DrawSubset(0);
m_d3dDevice.Transform.World = Matrix.RotationX(Geometry.DegreeToRadian(90)) * Matrix.Translation(0.0f, 2.0f, 0.0f) * m_d3dDevice.Transform.World1;
m_mshAxisCone.DrawSubset(0);
//Draw Z Axis
m_d3dDevice.Material = m_matZAxis;
m_d3dDevice.Transform.World = Matrix.Translation(0.0f, 0.0f, 1.0f) * m_d3dDevice.Transform.World1;
m_mshAxisCylinder.DrawSubset(0);
m_d3dDevice.Transform.World = Matrix.RotationY(Geometry.DegreeToRadian(180)) * Matrix.Translation(0.0f, 0.0f, 2.0f) * m_d3dDevice.Transform.World1;
m_mshAxisCone.DrawSubset(0);
//Draw X axis label
m_d3dDevice.Transform.World = Matrix.Translation(2.5f, 0.0f, 0.0f) * m_d3dDevice.Transform.World1;
Vector3 tmp = new Vector3();
tmp.TransformCoordinate(m_d3dDevice.Transform.World);
Matrix m =m_d3dDevice.Transform.View;
m.Invert();
m.M41 = tmp.X;
m.M42 = tmp.Y;
m.M43 = tmp.Z;
m_d3dDevice.Transform.World = m;
Device.Material = Util_DX.WhiteMaterial();
Device.SetTexture(0,texX);
m_mshAxisLabel.DrawSubset(0);
Device.SetTexture(0,null);
//Draw Y Axis Label
m_d3dDevice.Transform.World = Matrix.Translation(0.0f, 2.5f, 0.0f) * m_d3dDevice.Transform.World1;
tmp = new Vector3();
tmp.TransformCoordinate(m_d3dDevice.Transform.World);
m =m_d3dDevice.Transform.View;
m.Invert();
m.M41 = tmp.X;
m.M42 = tmp.Y;
m.M43 = tmp.Z;
m_d3dDevice.Transform.World = m;
Device.Material = Util_DX.WhiteMaterial();
Device.SetTexture(0,texY);
m_mshAxisLabel.DrawSubset(0);
Device.SetTexture(0,null);
//Draw Z Axis Label
m_d3dDevice.Transform.World = Matrix.Translation(0.0f, 0.0f, 2.5f) * m_d3dDevice.Transform.World1;
tmp = new Vector3();
tmp.TransformCoordinate(m_d3dDevice.Transform.World);
m =m_d3dDevice.Transform.View;
m.Invert();
m.M41 = tmp.X;
m.M42 = tmp.Y;
m.M43 = tmp.Z;
m_d3dDevice.Transform.World = m;
Device.Material = Util_DX.WhiteMaterial();
Device.SetTexture(0,texZ);
m_mshAxisLabel.DrawSubset(0);
Device.SetTexture(0,null);
}
示例10: DrawCenterSelectionBox
protected void DrawCenterSelectionBox()
{
//set the location of the center selection box
Vector3 tmp = new Vector3();
tmp.TransformCoordinate(CombinedTransformationMatrix * Device.Transform.World1);
//get the current view matrix and invert it
Matrix m = this.Device.Transform.View;
m.Invert();
//set the location of the inverted view matrix to the location of the selection box
m.M41 = tmp.X;
m.M42 = tmp.Y;
m.M43 = tmp.Z;
//set the device world matrix
this.Device.Transform.World = m;
//set a white material
this.Device.Material = Util_DX.WhiteMaterial();
//disable the z buffer
this.Device.RenderState.ZBufferEnable = false;
//set the texture of the selection box
Device.SetTexture(0,texCB);
//draw the selection box
m_mshCB.DrawSubset(0);
//set the texture back to null
Device.SetTexture(0,null);
//renable the z buffer
this.Device.RenderState.ZBufferEnable = true;
}
示例11: getDirectionVector
private Vector3 getDirectionVector(int i, int u)
{
Vector3 directionVector = new Vector3(mirrorBallDirectionVector.X, mirrorBallDirectionVector.Y, mirrorBallDirectionVector.Z);
directionVector.TransformCoordinate(Matrix.RotationY(mirrorBallFov * i + (mirrorBallFov - FastMath.PI) / 2));
Vector3 xAxis = new Vector3(directionVector.X, directionVector.Y, directionVector.Z);
xAxis.TransformCoordinate(Matrix.RotationY(FastMath.PI_HALF));
directionVector.TransformCoordinate(Matrix.RotationAxis(xAxis, mirrorBallFov * u + (mirrorBallFov - FastMath.PI) / 2));
return directionVector;
}
示例12: ExtractModelAsSingleMesh
//.........这里部分代码省略.........
vertcount += this.BSPRawDataMetaChunks[x].VerticeCount;
}
#endregion
SW.Close();
FS.Close();
#region ExportBSPPermutationMeshes
FS = new FileStream(path.Substring(0, path.LastIndexOf('.')) + "-permutations.obj", FileMode.Create);
SW = new StreamWriter(FS);
SW.WriteLine("# ------------------------------------");
SW.WriteLine("# Halo 2 BSP Permutation Mesh");
SW.WriteLine("# ------------------------------------");
SW.WriteLine("mtllib " + mtllib);
vertcount = 0;
for (int tx = 0; tx < this.PermutationInfo.Length; tx++)
{
int x = this.PermutationInfo[tx].sceneryIndex;
if ((this.BSPPermutationRawDataMetaChunks[x].RawDataChunkInfo.Length == 0) ||
(this.BSPPermutationRawDataMetaChunks[x].VerticeCount == 0))
{
continue;
}
for (int y = 0; y < this.BSPPermutationRawDataMetaChunks[x].VerticeCount; y++)
{
Vector3 tv3 = new Vector3(
this.BSPPermutationRawDataMetaChunks[x].Vertices[y].X,
this.BSPPermutationRawDataMetaChunks[x].Vertices[y].Y,
this.BSPPermutationRawDataMetaChunks[x].Vertices[y].Z);
tv3.TransformCoordinate(this.PermutationInfo[tx].mat);
string temps = "v " + tv3.X.ToString("R") + " " + tv3.Y.ToString("R") + " " + tv3.Z.ToString("R");
SW.WriteLine(temps);
}
SW.WriteLine("# " + this.BSPPermutationRawDataMetaChunks[x].Vertices.Count + " vertices");
for (int y = 0; y < this.BSPPermutationRawDataMetaChunks[x].VerticeCount; y++)
{
string temps = "vt " + this.BSPPermutationRawDataMetaChunks[x].UVs[y].X.ToString("R") + " " +
this.BSPPermutationRawDataMetaChunks[x].UVs[y].Y.ToString("R");
SW.WriteLine(temps);
}
SW.WriteLine("# " + this.BSPPermutationRawDataMetaChunks[x].Vertices.Count + " texture vertices");
for (int y = 0; y < this.BSPPermutationRawDataMetaChunks[x].VerticeCount; y++)
{
Vector3 tv3 = new Vector3(
this.BSPPermutationRawDataMetaChunks[x].Normals[y].X,
this.BSPPermutationRawDataMetaChunks[x].Normals[y].Y,
this.BSPPermutationRawDataMetaChunks[x].Normals[y].Z);
tv3.TransformNormal(this.PermutationInfo[tx].mat);
string temps = "vn " + tv3.X.ToString("R") + " " + tv3.Y.ToString("R") + " " + tv3.Z.ToString("R");
/*
string temps = "vn " + this.BSPPermutationRawDataMetaChunks[x].Normals[y].X.ToString()
+ " " + this.BSPPermutationRawDataMetaChunks[x].Normals[y].Y.ToString()
+ " " + this.BSPPermutationRawDataMetaChunks[x].Normals[y].Z.ToString();
*/
SW.WriteLine(temps);
}
SW.WriteLine("# " + this.BSPPermutationRawDataMetaChunks[x].Vertices.Count + " normals");
for (int y = 0; y < this.BSPPermutationRawDataMetaChunks[x].SubMeshInfo.Length; y++)
{
示例13: Intersect
public override int Intersect( Vector3 rayPosition, Vector3 rayDirection, ref Object3DCommon obj, Matrix worldSpace )
{
Matrix myModelSpace = scalingMatrix * rotationMatrix * translationMatrix * worldSpace;
// transform world space to object space
Vector3 pickRayOriginTemp = new Vector3(rayPosition.X, rayPosition.Y, rayPosition.Z);
Vector3 pickRayDirectionTemp = new Vector3(rayDirection.X,rayDirection.Y,rayDirection.Z);
// convert ray from 3d space to model space
pickRayOriginTemp.TransformCoordinate(Matrix.Invert(myModelSpace));
pickRayDirectionTemp.TransformNormal (Matrix.Invert(myModelSpace));
// check to see if I intersect
int zDistance = CheckIntersect(pickRayOriginTemp,pickRayDirectionTemp);
if (zDistance > 0)
{
obj = this;
}
if (_children != null)
{
foreach (Object3DCommon childObj in _children)
{
int newZDistance = childObj.Intersect(rayPosition, rayDirection, ref obj, myModelSpace);
if (newZDistance > zDistance)
{
zDistance = newZDistance;
}
}
}
return zDistance;
}
示例14: GenerateShadow
public static void GenerateShadow( Mesh polygonGeometry, Matrix worldMatrix, Vector2 lightPosWS,
float zValue, Vector2 shadowCasterCenter)
{
Vector3 UVOffset = new Vector3( 0.0f, -0.5f, 0.0f );
// Transform the light position into model space
Vector2 lightPos = Vector2.TransformCoordinate( lightPosWS, Matrix.Invert( worldMatrix ) );
List<Edge> contourEdges = new List<Edge>();
for ( int edgeIndex = 0; edgeIndex < polygonGeometry.NumEdges; ++edgeIndex )
{
Edge edge = polygonGeometry.GetEdge( edgeIndex );
Vector2 edgeCenter = ( edge.Vertex1Pos + edge.Vertex2Pos ) * 0.5f;
Vector2 incidentLightDir = edgeCenter - lightPos;
// If the edge faces away from the light source
if ( Vector2.Dot( incidentLightDir, edge.Normal ) >= 0.0f )
{
contourEdges.Add( edge );
}
}
if ( contourEdges.Count < 1 || contourEdges.Count == polygonGeometry.NumEdges )
{
return;
}
const float ExtrudeMagnitude = 1280;
Shadow shadow = new Shadow();
Vector3 lightPosVec3 = new Vector3( lightPos.X, lightPos.Y, zValue );
lightPosVec3.TransformCoordinate( worldMatrix );
int quadIndex = 0;
foreach ( Edge edge in contourEdges )
{
Vector3 vertex1 = new Vector3(
edge.Vertex1Pos.X, edge.Vertex1Pos.Y, zValue );
Vector3 vertex2 = new Vector3(
edge.Vertex2Pos.X, edge.Vertex2Pos.Y, zValue );
// Transform the position data from model space to world space
vertex1.TransformCoordinate( worldMatrix );
vertex2.TransformCoordinate( worldMatrix );
Quad quad = new Quad();
Color shadowColor = Color.FromArgb( 1, 0, 0, 0 );
quad.Vertices[ 2 * quadIndex + 0 ].Position = vertex1 + UVOffset -
18.0f * Vector3.Normalize( vertex1 - lightPosVec3 );
quad.Vertices[ 2 * quadIndex + 0 ].Color = shadowColor.ToArgb();
quad.Vertices[ 2 * quadIndex + 1 ].Position = vertex1 + ExtrudeMagnitude * ( vertex1 - lightPosVec3 )
+ UVOffset;
quad.Vertices[ 2 * quadIndex + 1 ].Color = shadowColor.ToArgb();
quad.Vertices[ 2 * quadIndex + 2 ].Position = vertex2 + UVOffset -
18.0f * Vector3.Normalize( vertex2 - lightPosVec3 );
quad.Vertices[ 2 * quadIndex + 2 ].Color = shadowColor.ToArgb();
quad.Vertices[ 2 * quadIndex + 3 ].Position = vertex2 + ExtrudeMagnitude * ( vertex2 - lightPosVec3 )
+ UVOffset;
quad.Vertices[ 2 * quadIndex + 3 ].Color = shadowColor.ToArgb();
shadow.Quads.Add( quad );
}
shadows.Add( shadow );
}
示例15: Run
//.........这里部分代码省略.........
jSelection.Add(l.J, null);
joints.Add(l.J, null);
}
}
else if (item is AreaElement)
{
AreaElement a = (AreaElement)item;
aSelection.Add(a);
areas.Add(a);
if (!jSelection.ContainsKey(a.J1))
{
jSelection.Add(a.J1, null);
joints.Add(a.J1, null);
}
if (!jSelection.ContainsKey(a.J2))
{
jSelection.Add(a.J2, null);
joints.Add(a.J2, null);
}
if (!jSelection.ContainsKey(a.J3))
{
jSelection.Add(a.J3, null);
joints.Add(a.J3, null);
}
if (a.J4 != null && !jSelection.ContainsKey(a.J4))
{
jSelection.Add(a.J4, null);
joints.Add(a.J4, null);
}
}
}
Microsoft.DirectX.Vector3 v, v2;
uint n = (uint)services.GetSingle(Culture.Get("getArrayRepetition"));
float dAngle = float.Parse(services.GetString(Culture.Get("getPolarArrayAngle")));
dAngle *= (float)Math.PI / 180.0F;
float angle = 0.0F;
Controller.Snap.Magnet m = services.GetPoint(Culture.Get("getPolarRotationCenter"));
if (m == null) return;
v = m.SnapPosition;
services.TrackingService = LineTrackingService.Instance;
services.TrackingService.SetPoint(m.SnapPositionInt);
m = services.GetPoint(Culture.Get("getPolarRotationCenter"));
if (m == null) return;
v2 = m.SnapPosition;
if (v2.Equals(v))
{
Canguro.View.GraphicView view = Canguro.View.GraphicViewManager.Instance.ActiveView;
Vector3 v1Tmp = new Vector3(0, 0, 0);
Vector3 v2Tmp = new Vector3(0, 0, 1);
view.Unproject(ref v1Tmp);
view.Unproject(ref v2Tmp);
v2 = v2 + v1Tmp - v2Tmp;
}
services.TrackingService = null;
List<Joint> newJoints = new List<Joint>();
List<LineElement> newLines = new List<LineElement>();
List<AreaElement> newAreas = new List<AreaElement>();
for (int i = 1; i <= n; i++)
{
angle += dAngle;
Matrix trans1 = new Matrix();
trans1.Translate(-v);
Matrix rot = new Matrix();
rot.RotateAxis(v2 - v, angle);
Matrix trans2 = new Matrix();
trans2.Translate(v);
rot = trans1 * rot * trans2;
foreach (Joint j in joints.Keys)
{
Vector3 pos = new Vector3(j.X, j.Y, j.Z);
pos.TransformCoordinate(rot);
jList.Add(nJoint = new Joint(pos.X, pos.Y, pos.Z));
nJoint.Masses = j.Masses;
nJoint.DoF = j.DoF;
jSelection[j] = nJoint;
newJoints.Add(nJoint);
}
foreach (LineElement l in lines)
{
lList.Add(nLine = new LineElement(l, jSelection[l.I], jSelection[l.J]));
newLines.Add(nLine);
}
foreach (AreaElement a in areas)
{
aList.Add(nArea = new AreaElement(a, jSelection[a.J1], jSelection[a.J2], jSelection[a.J3], (a.J4 != null) ? jSelection[a.J4] : null));
newAreas.Add(nArea);
}
}
JoinCmd.Join(services.Model, newJoints, newLines, newAreas);
}