本文整理汇总了C#中System.Windows.Media.Media3D.Point3D.ToVector方法的典型用法代码示例。如果您正苦于以下问题:C# Point3D.ToVector方法的具体用法?C# Point3D.ToVector怎么用?C# Point3D.ToVector使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Windows.Media.Media3D.Point3D
的用法示例。
在下文中一共展示了Point3D.ToVector方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Dot
public Dot(bool isStatic, Point3D position)
{
this.IsStatic = isStatic;
_position = position;
ModelVisual3D model = BuildDot(isStatic);
this.Visual = model;
_transform = new TranslateTransform3D(position.ToVector());
model.Transform = _transform;
}
示例2: Dot
public Dot(bool isStatic, Point3D position, double repulseMult = 1d)
{
this.IsStatic = isStatic;
_position = position;
this.RepulseMult = repulseMult;
ModelVisual3D model = BuildDot(isStatic, repulseMult);
this.Visual = model;
_transform = new TranslateTransform3D(position.ToVector());
model.Transform = _transform;
}
示例3: Egg
public Egg(Point3D position, World world, int materialID, ItemOptions itemOptions, ShipDNA dna)
{
// The radius should be 20% the size of the adult ship
this.Radius = dna.PartsByLayer.SelectMany(o => o.Value).
Max(o => o.Position.ToVector().Length + Math1D.Max(o.Scale.X, o.Scale.Y, o.Scale.Z))
* .2d;
Vector3D scale = new Vector3D(.75d, .75d, 1d);
#region WPF Model
// Material
MaterialGroup materials = new MaterialGroup();
materials.Children.Add(new DiffuseMaterial(new SolidColorBrush(WorldColors.EggColor)));
materials.Children.Add(WorldColors.EggSpecular);
// Geometry Model
GeometryModel3D geometry = new GeometryModel3D();
geometry.Material = materials;
geometry.BackMaterial = materials;
geometry.Geometry = UtilityWPF.GetSphere_LatLon(5, this.Radius);
geometry.Transform = new ScaleTransform3D(scale);
this.Model = geometry;
// Model Visual
ModelVisual3D model = new ModelVisual3D();
model.Content = geometry;
#endregion
#region Physics Body
Transform3DGroup transform = new Transform3DGroup();
transform.Children.Add(new RotateTransform3D(new QuaternionRotation3D(Math3D.GetRandomRotation())));
transform.Children.Add(new TranslateTransform3D(position.ToVector()));
double volume = (4d / 3d) * Math.PI * scale.X * this.Radius * scale.Y * this.Radius * scale.Z * this.Radius;
double mass = volume * itemOptions.Egg_Density;
using (CollisionHull hull = CollisionHull.CreateSphere(world, 0, scale * this.Radius, null))
{
this.PhysicsBody = new Body(hull, transform.Value, mass, new Visual3D[] { model });
this.PhysicsBody.MaterialGroupID = materialID;
this.PhysicsBody.LinearDamping = .01f;
this.PhysicsBody.AngularDamping = new Vector3D(.001f, .001f, .001f);
}
#endregion
this.CreationTime = DateTime.UtcNow;
}
示例4: Projectile
public Projectile(double radius, double mass, Point3D position, World world, int materialID, Color? color = null, double? maxAge = null, Map map = null)
{
if (maxAge != null && map == null)
{
throw new ArgumentException("Map must be populated if max age is set");
}
this.Radius = radius;
_maxAge = maxAge;
_map = map;
#region WPF Model
this.Model = GetModel(color);
this.Model.Transform = new ScaleTransform3D(radius, radius, radius);
// Model Visual
ModelVisual3D visual = new ModelVisual3D();
visual.Content = this.Model;
#endregion
#region Physics Body
Transform3DGroup transform = new Transform3DGroup();
transform.Children.Add(new RotateTransform3D(new QuaternionRotation3D(Math3D.GetRandomRotation())));
transform.Children.Add(new TranslateTransform3D(position.ToVector()));
using (CollisionHull hull = CollisionHull.CreateSphere(world, 0, new Vector3D(radius, radius, radius), null))
{
this.PhysicsBody = new Body(hull, transform.Value, mass, new Visual3D[] { visual });
//this.PhysicsBody.IsContinuousCollision = true;
this.PhysicsBody.MaterialGroupID = materialID;
this.PhysicsBody.LinearDamping = .01d;
this.PhysicsBody.AngularDamping = new Vector3D(.01d, .01d, .01d);
//this.PhysicsBody.ApplyForceAndTorque += new EventHandler<BodyApplyForceAndTorqueArgs>(Body_ApplyForceAndTorque);
}
#endregion
this.CreationTime = DateTime.UtcNow;
}
示例5: Mineral
public Mineral(MineralType mineralType, Point3D position, double volumeInCubicMeters, World world, int materialID, SharedVisuals sharedVisuals, double densityMult = 1d, double scale = 1d, decimal credits = 0m)
{
this.MineralType = mineralType;
this.VolumeInCubicMeters = volumeInCubicMeters;
this.Scale = scale;
this.Credits = credits;
this.Model = GetNewVisual(mineralType, sharedVisuals, scale);
// Model Visual
ModelVisual3D visual = new ModelVisual3D(); // this is the expensive one, so as few of these should be made as possible
visual.Content = this.Model;
this.Density = GetSettingsForMineralType(mineralType).Density * densityMult;
#region Physics Body
Transform3DGroup transform = new Transform3DGroup();
transform.Children.Add(new RotateTransform3D(new QuaternionRotation3D(Math3D.GetRandomRotation())));
transform.Children.Add(new TranslateTransform3D(position.ToVector()));
ScaleTransform3D scaleTransform = new ScaleTransform3D(scale, scale, scale);
Point3D[] hullPoints = UtilityWPF.GetPointsFromMesh((MeshGeometry3D)sharedVisuals.GetMineralMesh(mineralType), scaleTransform);
using (CollisionHull hull = CollisionHull.CreateConvexHull(world, 0, hullPoints))
{
this.PhysicsBody = new Body(hull, transform.Value, this.Density * volumeInCubicMeters, new Visual3D[] { visual });
this.PhysicsBody.MaterialGroupID = materialID;
this.PhysicsBody.LinearDamping = .01f;
this.PhysicsBody.AngularDamping = new Vector3D(.01f, .01f, .01f);
//this.PhysicsBody.ApplyForce += new BodyForceEventHandler(Body_ApplyForce);
}
#endregion
// Calculate radius
Point3D aabbMin, aabbMax;
this.PhysicsBody.GetAABB(out aabbMin, out aabbMax);
this.Radius = (aabbMax - aabbMin).Length / 2d;
this.CreationTime = DateTime.UtcNow;
}
示例6: AddDot
private void AddDot(Point3D position, double radius, Color color, bool isHiRes = true)
{
// Material
MaterialGroup materials = new MaterialGroup();
materials.Children.Add(new DiffuseMaterial(new SolidColorBrush(color)));
materials.Children.Add(new SpecularMaterial(new SolidColorBrush(UtilityWPF.AlphaBlend(Colors.White, color, .3d)), 30d));
// Geometry Model
GeometryModel3D geometry = new GeometryModel3D();
geometry.Material = materials;
geometry.BackMaterial = materials;
geometry.Geometry = UtilityWPF.GetSphere_Ico(radius, isHiRes ? 3 : 0, true);
// Model Visual
ModelVisual3D visual = new ModelVisual3D();
visual.Content = geometry;
visual.Transform = new TranslateTransform3D(position.ToVector());
// Temporarily add to the viewport
_viewport.Children.Add(visual);
_visuals.Add(visual);
}
示例7: AddText3D
private void AddText3D(string text, Point3D center, double height, Color color)
{
MaterialGroup faceMaterial = new MaterialGroup();
faceMaterial.Children.Add(new DiffuseMaterial(new SolidColorBrush(color)));
faceMaterial.Children.Add(new SpecularMaterial(new SolidColorBrush(UtilityWPF.ColorFromHex("60FFFFFF")), 5d));
MaterialGroup edgeMaterial = new MaterialGroup();
edgeMaterial.Children.Add(new DiffuseMaterial(new SolidColorBrush(UtilityWPF.OppositeColor(color))));
edgeMaterial.Children.Add(new SpecularMaterial(new SolidColorBrush(UtilityWPF.ColorFromHex("80808080")), 1d));
double edgeDepth = height / 15;
ModelVisual3D visual = new ModelVisual3D();
visual.Content = UtilityWPF.GetText3D(text, _font.Value, faceMaterial, edgeMaterial, height, edgeDepth);
visual.Transform = new TranslateTransform3D(center.ToVector());
// Temporarily add to the viewport
_viewport.Children.Add(visual);
_visuals.Add(visual);
}
示例8: GetModel_Rod_Moon
private static void GetModel_Rod_Moon(Model3DGroup geometries, WeaponHandleDNA dna, WeaponHandleDNA finalDNA, WeaponMaterialCache materials)
{
const double PERCENT = 1;
Random rand = StaticRandom.GetRandomForThread();
var from = dna.KeyValues;
var to = finalDNA.KeyValues;
#region Shaft
GeometryModel3D shaft = new GeometryModel3D();
shaft.Material = materials.Handle_Moon;
shaft.BackMaterial = shaft.Material;
double maxRad1 = WeaponDNA.GetKeyValue("maxRad1", from, to, rand.NextDouble(.7, 1.02));
double maxRad2 = WeaponDNA.GetKeyValue("maxRad2", from, to, rand.NextDouble(.7, 1.02));
double maxRad12 = Math.Max(maxRad1, maxRad2); // this is used in several places
List<TubeRingBase> rings = new List<TubeRingBase>();
rings.Add(new TubeRingRegularPolygon(0, false, maxRad1 * .4, maxRad1 * .4, true));
rings.Add(new TubeRingRegularPolygon(WeaponDNA.GetKeyValue("tube1", from, to, rand.NextPercent(.25, PERCENT)), false, maxRad1 * .8, maxRad1 * .8, false));
rings.Add(new TubeRingRegularPolygon(WeaponDNA.GetKeyValue("tube2", from, to, rand.NextPercent(.3, PERCENT)), false, maxRad1 * .85, maxRad1 * .85, false));
rings.Add(new TubeRingRegularPolygon(WeaponDNA.GetKeyValue("tube3", from, to, rand.NextPercent(.75, PERCENT)), false, maxRad1 * .6, maxRad1 * .6, false));
rings.Add(new TubeRingRegularPolygon(WeaponDNA.GetKeyValue("tube4", from, to, rand.NextPercent(20, PERCENT)), false, maxRad2 * .8, maxRad2 * .8, false));
rings.Add(new TubeRingRegularPolygon(WeaponDNA.GetKeyValue("tube5", from, to, rand.NextPercent(1, PERCENT)), false, maxRad2 * .9, maxRad2 * .9, false));
rings.Add(new TubeRingRegularPolygon(WeaponDNA.GetKeyValue("tube6", from, to, rand.NextPercent(1, PERCENT)), false, maxRad2 * 1, maxRad2 * 1, false));
rings.Add(new TubeRingDome(WeaponDNA.GetKeyValue("tube7", from, to, rand.NextPercent(2.5, PERCENT)), false, 4));
rings = TubeRingBase.FitNewSize(rings, maxRad12 * dna.Radius, maxRad12 * dna.Radius, dna.Length);
shaft.Geometry = UtilityWPF.GetMultiRingedTube(10, rings, true, true, new RotateTransform3D(new AxisAngleRotation3D(new Vector3D(0, 1, 0), -90))); // the tube builds along z, but this class wants along x
#endregion
// Number of gems
int numIfNew = 0;
if (rand.NextDouble() > .66d) // only 33% will get gems
{
// Of the handles with gems, only 5% will get 2
numIfNew = rand.NextDouble() > .95 ? 2 : 1;
}
int numGems = Convert.ToInt32(WeaponDNA.GetKeyValue("numGems", from, to, numIfNew));
if (numGems == 0)
{
geometries.Children.Add(shaft);
return;
}
#region Gems
List<double> percents = new List<double>();
for (int cntr = 0; cntr < numGems; cntr++)
{
string keyPrefix = "gem" + cntr.ToString();
// Get a placement for this gem
double percentIfNew = 0;
do
{
percentIfNew = rand.NextDouble(.15, .85);
if (percents.Count == 0)
{
break;
}
} while (percents.Any(o => Math.Abs(percentIfNew - o) < .15));
double percent = WeaponDNA.GetKeyValue(keyPrefix + "Percent", from, to, percentIfNew);
percents.Add(percent);
// Gem
GeometryModel3D gem = new GeometryModel3D();
gem.Material = materials.Handle_MoonGem;
gem.BackMaterial = gem.Material;
double width = WeaponDNA.GetKeyValue(keyPrefix + "Width", from, to, rand.NextDouble(maxRad12 * 1d, maxRad12 * 1.4d));
gem.Geometry = UtilityWPF.GetSphere_LatLon(5, dna.Radius * width);
Point3D position = new Point3D((dna.Length * percent) - (dna.Length / 2d), 0, 0);
gem.Transform = new TranslateTransform3D(position.ToVector());
// Light
PointLight pointLight = new PointLight(materials.Handle_MoonGemLight, position);
UtilityWPF.SetAttenuation(pointLight, dna.Radius * 120d, .1d);
geometries.Children.Add(pointLight);
geometries.Children.Add(gem);
}
// Adding this after so that you don't see the shaft through the gems
geometries.Children.Add(shaft);
//.........这里部分代码省略.........
示例9: CreateCollisionHull
internal static CollisionHull CreateCollisionHull(WorldBase world, Vector3D scale, Quaternion orientation, Point3D position)
{
Transform3DGroup transform = new Transform3DGroup();
//transform.Children.Add(new ScaleTransform3D(scale)); // it ignores scale
transform.Children.Add(new RotateTransform3D(new QuaternionRotation3D(orientation)));
transform.Children.Add(new TranslateTransform3D(position.ToVector()));
Vector3D size = new Vector3D(scale.X * .5d, scale.Y * .5d, scale.Z * .5d);
return CollisionHull.CreateSphere(world, 0, size, transform.Value);
}
示例10: CreateStation
//.........这里部分代码省略.........
// Model Group
models.Children.Add(geometry);
}
#endregion
#region Hull - Top inner
// Material
material = new MaterialGroup();
material.Children.Add(new DiffuseMaterial(new SolidColorBrush(UtilityWPF.AlphaBlend(Colors.White, _hullColor, .25d))));
material.Children.Add(new SpecularMaterial(Brushes.Silver, 75d));
// Geometry Model
geometry = new GeometryModel3D();
geometry.Material = material;
geometry.BackMaterial = material;
geometry.Geometry = UtilityWPF.GetCylinder_AlongX(20, _radius * .11, _radius * .01);
Transform3DGroup spokeTransform2 = new Transform3DGroup();
spokeTransform2.Children.Add(new TranslateTransform3D((_radius * .51) - .5, 0, 0)); // the cylinder is built along the x axis, but is centered halfway
spokeTransform2.Children.Add(new RotateTransform3D(new AxisAngleRotation3D(new Vector3D(0, -1, 0), 90d)));
geometry.Transform = spokeTransform2;
// Model Group
models.Children.Add(geometry);
#endregion
#region Hull - Top outer
//TODO: The two cylinders cause flicker, come up with the definition of a ring
// Material
material = new MaterialGroup();
material.Children.Add(new DiffuseMaterial(new SolidColorBrush(UtilityWPF.AlphaBlend(Colors.Black, _hullColor, .25d))));
material.Children.Add(new SpecularMaterial(Brushes.Silver, 75d));
// Geometry Model
geometry = new GeometryModel3D();
geometry.Material = material;
geometry.BackMaterial = material;
geometry.Geometry = UtilityWPF.GetCylinder_AlongX(20, _radius * .12, _radius * .0095);
Transform3DGroup spokeTransform3 = new Transform3DGroup();
spokeTransform3.Children.Add(new TranslateTransform3D((_radius * .5) - .5, 0, 0)); // the cylinder is built along the x axis, but is centered halfway
spokeTransform3.Children.Add(new RotateTransform3D(new AxisAngleRotation3D(new Vector3D(0, -1, 0), 90d)));
geometry.Transform = spokeTransform3;
// Model Group
models.Children.Add(geometry);
#endregion
#endregion
#region Glass
// Material
//NOTE: There is an issue with drawing objects inside a semitransparent object - they have to be added in order (so stuff added after a semitransparent won't be visible behind it)
//Brush skinBrush = new SolidColorBrush(Color.FromArgb(25, 190, 240, 240)); // making the skin semitransparent, so you can see the components inside
Brush skinBrush = new SolidColorBrush(Color.FromArgb(25, 220, 240, 240)); // making the skin semitransparent, so you can see the components inside
material = new MaterialGroup();
material.Children.Add(new DiffuseMaterial(skinBrush));
material.Children.Add(new SpecularMaterial(Brushes.White, 85d)); // more reflective (and white light)
MaterialGroup backMaterial = new MaterialGroup();
backMaterial.Children.Add(new DiffuseMaterial(skinBrush));
backMaterial.Children.Add(new SpecularMaterial(new SolidColorBrush(Color.FromArgb(255, 20, 20, 20)), 10d)); // dark light, and not very reflective
// Geometry Model
geometry = new GeometryModel3D();
geometry.Material = material;
geometry.BackMaterial = backMaterial;
geometry.Geometry = UtilityWPF.GetSphere_LatLon(6, _radius * 1, _radius * 1, _radius * .25);
// Model Group
models.Children.Add(geometry);
#endregion
#region Exterior Visuals
// There is a bug in WPF where visuals added after a semitransparent one won't show inside. So if you want to add exterior
// bits that aren't visible inside, this would be the place
#endregion
_mainTransform = new Transform3DGroup();
_mainTransform.Children.Add(new RotateTransform3D(new AxisAngleRotation3D(new Vector3D(1, 0, 0), 0)));
_mainTransform.Children.Add(new TranslateTransform3D(worldPosition.ToVector()));
// Model Visual
ModelVisual3D model = new ModelVisual3D(); // this is the expensive one. make as few of these as I can get away with
model.Content = models;
model.Transform = _mainTransform;
// Add to my list
_visuals.Add(model);
_map.Viewport.Children.Add(model);
_map.AddItem(this);
}
示例11: Brain_StraightToTarget_VelocityAware2
private void Brain_StraightToTarget_VelocityAware2()
{
// Velocity should be zero when touching the chase point
//TODO: Implement this (when not attacking, velocity should slow to a max speed the closer to the chase point)
// Convert everything to local coords
Point3D position = new Point3D(0, 0, 0);
Point3D chasePoint = this.PhysicsBody.PositionFromWorld(_chasePoint);
Vector3D directionToGo = chasePoint.ToVector() - position.ToVector();
Vector3D axis;
double radians;
#region Adjust for current velocity attempt1a
Vector3D currentVelocity = this.VelocityWorld;
if (!Math1D.IsNearZero(currentVelocity.LengthSquared))
{
currentVelocity = this.PhysicsBody.DirectionFromWorld(currentVelocity);
Math3D.GetRotation(out axis, out radians, directionToGo, currentVelocity);
// This is how much to rotate direction to align with current velocity, I want to go against the current velocity (if aligned,
// the angle will be zero, so negating won't make a difference)
radians *= -1;
// If it's greater than 90 degrees, then just use the original direction (because it will pull the velocity in line
// eventually) I don't multiply by .5, because when it is very close to 90 degrees, the bot will thrash a bit
if (Math.Abs(radians) < Math.PI * .4d)
{
// Change the direction by the angle
directionToGo = directionToGo.GetRotatedVector(axis, Math1D.RadiansToDegrees(radians));
}
}
#endregion
// Now that I know where to go, rotate the original thruster direction (0,1,0) to line up with the desired direction
Math3D.GetRotation(out axis, out radians, _origThrustDirection, directionToGo);
// Thrust Direction
_thrustTransform = new RotateTransform3D(new AxisAngleRotation3D(axis, Math1D.RadiansToDegrees(radians)));
// Thrust Strength
if (_isAttacking)
{
_thrustPercent = 1d;
}
else
{
_thrustPercent = .5d;
}
}
示例12: Neuron_SensorPosition
public Neuron_SensorPosition(Point3D position, bool isPositiveOnly, bool ignoreSetValue = true)
{
_position = position;
_isPositiveOnly = isPositiveOnly;
_ignoreSetValue = ignoreSetValue;
if (Math3D.IsNearZero(position))
{
_positionUnit = null;
_positionLength = 0d;
}
else
{
_positionUnit = position.ToVector().ToUnit();
_positionLength = position.ToVector().Length;
}
}
示例13: AddDot
private void AddDot(Point3D position, Color color, double radius = .1)
{
// Material
MaterialGroup materials = new MaterialGroup();
materials.Children.Add(new DiffuseMaterial(new SolidColorBrush(color)));
materials.Children.Add(new SpecularMaterial(new SolidColorBrush(UtilityWPF.AlphaBlend(color, Colors.White, .5d)), 50d));
// Geometry Model
GeometryModel3D geometry = new GeometryModel3D();
geometry.Material = materials;
geometry.BackMaterial = materials;
geometry.Geometry = UtilityWPF.GetSphere_LatLon(3, radius, radius, radius);
// Model Visual
ModelVisual3D model = new ModelVisual3D();
model.Content = geometry;
model.Transform = new TranslateTransform3D(position.ToVector());
// Temporarily add to the viewport
_viewport.Children.Add(model);
_visuals.Add(model);
}
示例14: CreateTankCollisionHull
internal static CollisionHull CreateTankCollisionHull(WorldBase world, Vector3D scale, Quaternion orientation, Point3D position)
{
Transform3DGroup transform = new Transform3DGroup();
//transform.Children.Add(new ScaleTransform3D(this.Scale)); // it ignores scale
transform.Children.Add(new RotateTransform3D(new AxisAngleRotation3D(new Vector3D(0, 1, 0), 90))); // the physics hull is along x, but dna is along z
transform.Children.Add(new RotateTransform3D(new QuaternionRotation3D(orientation)));
transform.Children.Add(new TranslateTransform3D(position.ToVector()));
double radius = RADIUSPERCENTOFSCALE * (scale.X + scale.Y) * .5d;
double height = scale.Z;
if (height < radius * 2d)
{
// Newton keeps the capsule caps spherical, but the visual scales them. So when the height is less than the radius, newton
// make a sphere. So just make a cylinder instead
//return CollisionHull.CreateChamferCylinder(world, 0, radius, height, transform.Value);
return CollisionHull.CreateCylinder(world, 0, radius, height, transform.Value);
}
else
{
//NOTE: The visual changes the caps around, but I want the physics to be a capsule
return CollisionHull.CreateCapsule(world, 0, radius, height, transform.Value);
}
}
示例15: GetVisual_Dot
private static Visual3D GetVisual_Dot(Point3D position, double radius, Color color)
{
// Material
MaterialGroup materials = new MaterialGroup();
materials.Children.Add(new DiffuseMaterial(new SolidColorBrush(color)));
materials.Children.Add(new SpecularMaterial(new SolidColorBrush(UtilityWPF.AlphaBlend(color, Colors.White, .5d)), 50d));
// Geometry Model
GeometryModel3D geometry = new GeometryModel3D();
geometry.Material = materials;
geometry.BackMaterial = materials;
geometry.Geometry = UtilityWPF.GetSphere_LatLon(3, radius, radius, radius);
// Model Visual
ModelVisual3D retVal = new ModelVisual3D();
retVal.Content = geometry;
retVal.Transform = new TranslateTransform3D(position.ToVector());
return retVal;
}