本文整理汇总了C#中Location.ToBVector方法的典型用法代码示例。如果您正苦于以下问题:C# Location.ToBVector方法的具体用法?C# Location.ToBVector怎么用?C# Location.ToBVector使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Location
的用法示例。
在下文中一共展示了Location.ToBVector方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: HassSolidEntity
public bool HassSolidEntity(Location min, Location max)
{
// TODO: Better alg!
BoundingBox bb = new BoundingBox(min.ToBVector(), max.ToBVector());
List<BroadPhaseEntry> entries = new List<BroadPhaseEntry>();
PhysicsWorld.BroadPhase.QueryAccelerator.GetEntries(bb, entries);
if (entries.Count == 0)
{
return false;
}
Location center = (max + min) * 0.5;
Location rel = max - min;
BoxShape box = new BoxShape((double)rel.X, (double)rel.Y, (double)rel.Z);
RigidTransform start = new RigidTransform(center.ToBVector(), Quaternion.Identity);
Vector3 sweep = new Vector3(0, 0, 0.01f);
RayHit rh;
foreach (BroadPhaseEntry entry in entries)
{
if (entry is EntityCollidable && Collision.ShouldCollide(entry) &&
entry.CollisionRules.Group != CollisionUtil.Player &&
entry.ConvexCast(box, ref start, ref sweep, out rh))
{
return true;
}
}
return false;
}
示例2: SpecialCaseConvexTrace
public bool SpecialCaseConvexTrace(ConvexShape shape, Location start, Location dir, double len, MaterialSolidity considerSolid, Func<BroadPhaseEntry, bool> filter, out RayCastResult rayHit)
{
RigidTransform rt = new RigidTransform(start.ToBVector(), BEPUutilities.Quaternion.Identity);
BEPUutilities.Vector3 sweep = (dir * len).ToBVector();
RayCastResult best = new RayCastResult(new RayHit() { T = len }, null);
bool hA = false;
if (considerSolid.HasFlag(MaterialSolidity.FULLSOLID))
{
RayCastResult rcr;
if (PhysicsWorld.ConvexCast(shape, ref rt, ref sweep, filter, out rcr))
{
best = rcr;
hA = true;
}
}
sweep = dir.ToBVector();
AABB box = new AABB();
box.Min = start;
box.Max = start;
box.Include(start + dir * len);
foreach (KeyValuePair<Vector3i, Chunk> chunk in LoadedChunks)
{
if (chunk.Value == null || chunk.Value.FCO == null)
{
continue;
}
if (!box.Intersects(new AABB() { Min = chunk.Value.WorldPosition.ToLocation() * Chunk.CHUNK_SIZE,
Max = chunk.Value.WorldPosition.ToLocation() * Chunk.CHUNK_SIZE + new Location(Chunk.CHUNK_SIZE, Chunk.CHUNK_SIZE, Chunk.CHUNK_SIZE) }))
{
continue;
}
RayHit temp;
if (chunk.Value.FCO.ConvexCast(shape, ref rt, ref sweep, len, considerSolid, out temp))
{
hA = true;
if (temp.T < best.HitData.T)
{
best.HitData = temp;
best.HitObject = chunk.Value.FCO;
}
}
}
rayHit = best;
return hA;
}
示例3: SetVelocity
/// <summary>
/// Sets the velocity of this entity.
/// </summary>
/// <param name="vel">The new velocity.</param>
public virtual void SetVelocity(Location vel)
{
LVel = vel;
if (Body != null)
{
Body.LinearVelocity = vel.ToBVector();
}
}
示例4: SetPosition
/// <summary>
/// Sets the position of this entity within the world.
/// </summary>
/// <param name="pos">The position to move the entity to.</param>
public override void SetPosition(Location pos)
{
if (Body != null)
{
Body.Position = pos.ToBVector();
}
else
{
WorldTransform.Translation = pos.ToBVector();
}
}
示例5: SetAngularVelocity
/// <summary>
/// Sets the angular velocity of this entity.
/// </summary>
/// <param name="vel">The new velocity.</param>
public virtual void SetAngularVelocity(Location vel)
{
AVel = vel;
if (Body != null)
{
Body.AngularVelocity = vel.ToBVector();
}
}
示例6: Steps
public void Steps(Location pos, Material mat, Location vel, float vlen)
{
const double spread = 0.5f;
int c = Utilities.UtilRandom.Next(5) + 3;
Vector3 tvec = vel.ToBVector();
for (int i = 0; i < c; i++)
{
Quaternion quat = Quaternion.CreateFromAxisAngle(Vector3.UnitZ, (float)(Utilities.UtilRandom.NextDouble() * (Math.PI / 2.0)));
Location nvel = new Location(Quaternion.Transform(tvec, quat));
nvel.Z += 3;
double xoff = Utilities.UtilRandom.NextDouble() * spread - spread * 0.5;
double yoff = Utilities.UtilRandom.NextDouble() * spread - spread * 0.5;
Location temp = new Location(xoff, yoff, TheClient.TheRegion.PhysicsWorld.ForceUpdater.Gravity.Z * 0.15f);
float ttl = (float)Utilities.UtilRandom.NextDouble() * 3f + 3f;
Texture tex = TheClient.Textures.GetTexture(TheClient.TBlock.IntTexs[mat.TextureID(MaterialSide.TOP)]);
Location size = new Location(0.1, 0.1, 0.1);
Engine.AddEffect(ParticleEffectType.SQUARE, (o) => pos + temp * (1 - o.TTL / o.O_TTL)
+ new Location(xoff, yoff, 0) * Math.Sqrt(1 - o.TTL / o.O_TTL) + nvel * (1 - o.TTL / o.O_TTL), (o) => size, (o) => 1, ttl, Location.One, Location.One, true, tex, 1);
}
}
示例7: SpecialCaseRayTrace
public bool SpecialCaseRayTrace(Location start, Location dir, float len, MaterialSolidity considerSolid, Func<BroadPhaseEntry, bool> filter, out RayCastResult rayHit)
{
Ray ray = new Ray(start.ToBVector(), dir.ToBVector());
RayCastResult best = new RayCastResult(new RayHit() { T = len }, null);
bool hA = false;
if (considerSolid.HasFlag(MaterialSolidity.FULLSOLID))
{
RayCastResult rcr;
if (PhysicsWorld.RayCast(ray, len, filter, out rcr))
{
best = rcr;
hA = true;
}
}
AABB box = new AABB();
box.Min = start;
box.Max = start;
box.Include(start + dir * len);
foreach (KeyValuePair<Vector3i, Chunk> chunk in LoadedChunks)
{
if (chunk.Value == null || chunk.Value.FCO == null)
{
continue;
}
if (!box.Intersects(new AABB() { Min = chunk.Value.WorldPosition.ToLocation() * Chunk.CHUNK_SIZE, Max = chunk.Value.WorldPosition.ToLocation() * Chunk.CHUNK_SIZE + new Location(Chunk.CHUNK_SIZE) }))
{
continue;
}
RayHit temp;
if (chunk.Value.FCO.RayCast(ray, len, null, considerSolid, out temp))
{
hA = true;
//temp.T *= len;
if (temp.T < best.HitData.T)
{
best.HitData = temp;
best.HitObject = chunk.Value.FCO;
}
}
}
rayHit = best;
return hA;
}
示例8: SkyMod
Location SkyMod(Location pos, Location norm, float light)
{
if (light > 0 && TheClient.CVars.r_treeshadows.ValueB)
{
BoundingBox bb = new BoundingBox(pos.ToBVector(), (pos + new Location(1, 1, 300)).ToBVector());
if (GenShadowCasters != null)
{
for (int i = 0; i < GenShadowCasters.Length; i++)
{
PhysicsEntity pe = GenShadowCasters[i];
if (pe.GenBlockShadows && pe.ShadowCenter.DistanceSquared_Flat(pos) < pe.ShadowRadiusSquaredXY)
{
light -= 0.05f;
if (pe.ShadowMainDupe.Intersects(bb))
{
light = 0;
break;
}
if (pe.ShadowCastShape.Intersects(bb))
{
light -= 0.1f;
}
if (light <= 0)
{
light = 0;
break;
}
}
}
}
}
return Math.Max(norm.Dot(SunLightPathNegative), 0.5) * new Location(light) * SkyLightMod;
}
示例9: NMTWOSetVelocity
void NMTWOSetVelocity(Location vel)
{
NMTWOCBody.Body.LinearVelocity = vel.ToBVector();
}
示例10: TickWorld
public void TickWorld(double delta)
{
rTicks++;
if (rTicks >= CVars.r_shadowpace.ValueI)
{
// TODO: Z+ -> max view rad + 30
TheSun.Direction = Utilities.ForwardVector_Deg(SunAngle.Yaw, SunAngle.Pitch);
TheSun.Reposition(Player.GetPosition().GetBlockLocation() - TheSun.Direction * 30 * 6);
TheSunClouds.Direction = TheSun.Direction;
TheSunClouds.Reposition(TheSun.EyePos);
PlanetDir = Utilities.ForwardVector_Deg(PlanetAngle.Yaw, PlanetAngle.Pitch);
ThePlanet.Direction = PlanetDir;
TheSunClouds.Reposition(Player.GetPosition().GetBlockLocation() - ThePlanet.Direction * 30 * 6);
Quaternion diff;
Vector3 tsd = TheSun.Direction.ToBVector();
Vector3 tpd = PlanetDir.ToBVector();
Quaternion.GetQuaternionBetweenNormalizedVectors(ref tsd, ref tpd, out diff);
PlanetSunDist = (float)Quaternion.GetAngleFromQuaternion(ref diff) / (float)Utilities.PI180;
if (PlanetSunDist < 75)
{
TheSun.InternalLights[0].color = new OpenTK.Vector3((float)Math.Min(SunLightDef.X * (PlanetSunDist / 15), 1),
(float)Math.Min(SunLightDef.Y * (PlanetSunDist / 20), 1), (float)Math.Min(SunLightDef.Z * (PlanetSunDist / 60), 1));
TheSunClouds.InternalLights[0].color = new OpenTK.Vector3((float)Math.Min(CloudSunLightDef.X * (PlanetSunDist / 15), 1),
(float)Math.Min(CloudSunLightDef.Y * (PlanetSunDist / 20), 1), (float)Math.Min(CloudSunLightDef.Z * (PlanetSunDist / 60), 1));
ThePlanet.InternalLights[0].color = new OpenTK.Vector3(0, 0, 0);
}
else
{
TheSun.InternalLights[0].color = ClientUtilities.Convert(SunLightDef);
TheSunClouds.InternalLights[0].color = ClientUtilities.Convert(CloudSunLightDef);
ThePlanet.InternalLights[0].color = ClientUtilities.Convert(PlanetLightDef * Math.Min((PlanetSunDist / 180f), 1f));
}
PlanetLight = PlanetSunDist / 180f;
if (SunAngle.Pitch < 10 && SunAngle.Pitch > -30)
{
float rel = 30 + (float)SunAngle.Pitch;
if (rel == 0)
{
rel = 0.00001f;
}
rel = 1f - (rel / 40f);
rel = Math.Max(Math.Min(rel, 1f), 0f);
float rel2 = Math.Max(Math.Min(rel * 1.5f, 1f), 0f);
TheSun.InternalLights[0].color = new OpenTK.Vector3(TheSun.InternalLights[0].color.X * rel2, TheSun.InternalLights[0].color.Y * rel, TheSun.InternalLights[0].color.Z * rel);
TheSunClouds.InternalLights[0].color = new OpenTK.Vector3(TheSunClouds.InternalLights[0].color.X * rel2, TheSunClouds.InternalLights[0].color.Y * rel, TheSunClouds.InternalLights[0].color.Z * rel);
MainWorldView.DesaturationAmount = (1f - rel) * 0.75f;
MainWorldView.ambient = BaseAmbient * ((1f - rel) * 0.5f + 0.5f);
sl_min = 0.2f - (1f - rel) * (0.2f - 0.05f);
sl_max = 0.8f - (1f - rel) * (0.8f - 0.15f);
}
else if (SunAngle.Pitch >= 10)
{
TheSun.InternalLights[0].color = new OpenTK.Vector3(0, 0, 0);
TheSunClouds.InternalLights[0].color = new OpenTK.Vector3(0, 0, 0);
MainWorldView.DesaturationAmount = 0.75f;
MainWorldView.ambient = BaseAmbient * 0.5f;
sl_min = 0.05f;
sl_max = 0.15f;
}
else
{
sl_min = 0.2f;
sl_max = 0.8f;
MainWorldView.DesaturationAmount = 0f;
MainWorldView.ambient = BaseAmbient;
TheSun.InternalLights[0].color = ClientUtilities.Convert(SunLightDef);
TheSunClouds.InternalLights[0].color = ClientUtilities.Convert(CloudSunLightDef);
}
rTicks = 0;
shouldRedrawShadows = true;
}
TheRegion.TickWorld(delta);
}
示例11: SetGravity
/// <summary>
/// Sets the gravity value for this physics entity.
/// </summary>
/// <param name="gravity">The gravity value.</param>
public void SetGravity(Location gravity)
{
Gravity = gravity;
if (Body != null)
{
Body.Gravity = gravity.ToBVector();
}
}
示例12: ApplyForce
/// <summary>
/// Applies a force directly to the physics entity's body, at a specified relative origin point.
/// The origin is relevant to the body's centerpoint.
/// The further you get from the centerpoint, the more spin and less linear motion will be applied.
/// Note: this is a force, not a velocity. Mass is relevant.
/// This will activate the entity.
/// </summary>
/// <param name="force">The force to apply.</param>
public void ApplyForce(Location origin, Location force)
{
if (Body != null)
{
Vector3 ori = origin.ToBVector();
Vector3 vec = force.ToBVector();
Body.ApplyImpulse(ref ori, ref vec);
Body.ActivityInformation.Activate();
}
else
{
// TODO: Account for spin?
LVel += force / Mass;
}
}
示例13: RayTrace
/// <summary>
/// Returns information on what a line trace would collide with, if anything.
/// </summary>
/// <param name="start">The start of the line.</param>
/// <param name="end">The end of the line.</param>
/// <param name="filter">The collision filter, input a BEPU BroadPhaseEntry and output whether collision should be allowed.</param>
/// <returns>The collision details.</returns>
public CollisionResult RayTrace(Location start, Location end, Func<BroadPhaseEntry, bool> filter = null)
{
double len = (end - start).Length();
Ray ray = new Ray(start.ToBVector(), ((end - start) / len).ToBVector());
RayCastResult rcr;
bool hit;
if (filter == null)
{
hit = World.RayCast(ray, (double)len, out rcr);
}
else
{
hit = World.RayCast(ray, (double)len, filter, out rcr);
}
CollisionResult cr = new CollisionResult();
cr.Hit = hit;
if (hit)
{
cr.Normal = new Location(rcr.HitData.Normal);
cr.Position = new Location(rcr.HitData.Location);
if (rcr.HitObject is EntityCollidable)
{
cr.HitEnt = ((EntityCollidable)rcr.HitObject).Entity;
}
else
{
cr.HitEnt = null; // Impacted static world
}
}
else
{
cr.Normal = Location.Zero;
cr.Position = end;
cr.HitEnt = null;
}
return cr;
}
示例14: Render3D
public void Render3D(Location pos, float rot, Location size)
{
BEPUutilities.Matrix rot1 = BEPUutilities.Matrix.CreateFromAxisAngle(BEPUutilities.Vector3.UnitZ, rot)
* BEPUutilities.Matrix.CreateFromAxisAngle(BEPUutilities.Vector3.UnitX, (float)(Math.PI * 0.25));
if (RenderedBlock != null)
{
TheClient.isVox = false;
TheClient.SetVox();
TheClient.Rendering.SetMinimumLight(0.9f);
RenderedBlock.WorldTransform = BEPUutilities.Matrix.CreateScale(size.ToBVector() * 0.70f)
* rot1
* BEPUutilities.Matrix.CreateTranslation(pos.ToBVector());
RenderedBlock.Render();
TheClient.Rendering.SetMinimumLight(0f);
}
else if (RenderedModel != null)
{
TheClient.isVox = true;
TheClient.SetEnts();
TheClient.Rendering.SetMinimumLight(0.9f);
BEPUutilities.RigidTransform rt = BEPUutilities.RigidTransform.Identity;
BEPUutilities.BoundingBox bb;
RenderedModel.Shape.GetBoundingBox(ref rt, out bb);
BEPUutilities.Vector3 scale = BEPUutilities.Vector3.Max(bb.Max, -bb.Min);
float len = (float)scale.Length();
RenderedModel.WorldTransform = BEPUutilities.Matrix.CreateScale(size.ToBVector() * len)
* rot1
* BEPUutilities.Matrix.CreateTranslation(pos.ToBVector());
RenderedModel.RenderSimpler();
TheClient.Rendering.SetMinimumLight(0f);
}
}