本文整理汇总了C#中Game.Length方法的典型用法代码示例。如果您正苦于以下问题:C# Game.Length方法的具体用法?C# Game.Length怎么用?C# Game.Length使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Game
的用法示例。
在下文中一共展示了Game.Length方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: LimitThirdPersonCameraToWalls
internal void LimitThirdPersonCameraToWalls(Game game, Vector3Ref eye, Vector3Ref target, FloatRef curtppcameradistance)
{
float one = 1;
Vector3Ref ray_start_point = target;
Vector3Ref raytarget = eye;
Line3D pick = new Line3D();
float raydirX = (raytarget.X - ray_start_point.X);
float raydirY = (raytarget.Y - ray_start_point.Y);
float raydirZ = (raytarget.Z - ray_start_point.Z);
float raydirLength1 = game.Length(raydirX, raydirY, raydirZ);
raydirX /= raydirLength1;
raydirY /= raydirLength1;
raydirZ /= raydirLength1;
raydirX = raydirX * (game.tppcameradistance + 1);
raydirY = raydirY * (game.tppcameradistance + 1);
raydirZ = raydirZ * (game.tppcameradistance + 1);
pick.Start = Vec3.FromValues(ray_start_point.X, ray_start_point.Y, ray_start_point.Z);
pick.End = new float[3];
pick.End[0] = ray_start_point.X + raydirX;
pick.End[1] = ray_start_point.Y + raydirY;
pick.End[2] = ray_start_point.Z + raydirZ;
//pick terrain
IntRef pick2Count = new IntRef();
BlockPosSide[] pick2 = game.Pick(game.s, pick, pick2Count);
if (pick2Count.value > 0)
{
BlockPosSide pick2nearest = game.Nearest(pick2, pick2Count.value, ray_start_point.X, ray_start_point.Y, ray_start_point.Z);
//pick2.Sort((a, b) => { return (FloatArrayToVector3(a.blockPos) - ray_start_point).Length.CompareTo((FloatArrayToVector3(b.blockPos) - ray_start_point).Length); });
float pickX = pick2nearest.blockPos[0] - target.X;
float pickY = pick2nearest.blockPos[1] - target.Y;
float pickZ = pick2nearest.blockPos[2] - target.Z;
float pickdistance = game.Length(pickX, pickY, pickZ);
curtppcameradistance.value = MathCi.MinFloat(pickdistance - 1, curtppcameradistance.value);
if (curtppcameradistance.value < one * 3 / 10) { curtppcameradistance.value = one * 3 / 10; }
}
float cameraDirectionX = target.X - eye.X;
float cameraDirectionY = target.Y - eye.Y;
float cameraDirectionZ = target.Z - eye.Z;
float raydirLength = game.Length(raydirX, raydirY, raydirZ);
raydirX /= raydirLength;
raydirY /= raydirLength;
raydirZ /= raydirLength;
eye.X = target.X + raydirX * curtppcameradistance.value;
eye.Y = target.Y + raydirY * curtppcameradistance.value;
eye.Z = target.Z + raydirZ * curtppcameradistance.value;
}
示例2: GetPickingLine
public void GetPickingLine(Game game, Line3D retPick, bool ispistolshoot)
{
int mouseX;
int mouseY;
if (game.cameratype == CameraType.Fpp || game.cameratype == CameraType.Tpp)
{
mouseX = game.Width() / 2;
mouseY = game.Height() / 2;
}
else
{
mouseX = game.mouseCurrentX;
mouseY = game.mouseCurrentY;
}
PointFloatRef aim = GetAim(game);
if (ispistolshoot && (aim.X != 0 || aim.Y != 0))
{
mouseX += game.platform.FloatToInt(aim.X);
mouseY += game.platform.FloatToInt(aim.Y);
}
tempViewport[0] = 0;
tempViewport[1] = 0;
tempViewport[2] = game.Width();
tempViewport[3] = game.Height();
unproject.UnProject(mouseX, game.Height() - mouseY, 1, game.mvMatrix.Peek(), game.pMatrix.Peek(), tempViewport, tempRay);
unproject.UnProject(mouseX, game.Height() - mouseY, 0, game.mvMatrix.Peek(), game.pMatrix.Peek(), tempViewport, tempRayStartPoint);
float raydirX = (tempRay[0] - tempRayStartPoint[0]);
float raydirY = (tempRay[1] - tempRayStartPoint[1]);
float raydirZ = (tempRay[2] - tempRayStartPoint[2]);
float raydirLength = game.Length(raydirX, raydirY, raydirZ);
raydirX /= raydirLength;
raydirY /= raydirLength;
raydirZ /= raydirLength;
retPick.Start = new float[3];
retPick.Start[0] = tempRayStartPoint[0];// +raydirX; //do not pick behind
retPick.Start[1] = tempRayStartPoint[1];// +raydirY;
retPick.Start[2] = tempRayStartPoint[2];// +raydirZ;
float pickDistance1 = CurrentPickDistance(game) * ((ispistolshoot) ? 100 : 1);
pickDistance1 += 1;
retPick.End = new float[3];
retPick.End[0] = tempRayStartPoint[0] + raydirX * pickDistance1;
retPick.End[1] = tempRayStartPoint[1] + raydirY * pickDistance1;
retPick.End[2] = tempRayStartPoint[2] + raydirZ * pickDistance1;
}
示例3: DrawPlayers
internal void DrawPlayers(Game game, float dt)
{
game.totaltimeMilliseconds = game.platform.TimeMillisecondsFromStart();
for (int i = 0; i < game.entitiesCount; i++)
{
if (game.entities[i] == null)
{
continue;
}
if (game.entities[i].drawModel == null)
{
continue;
}
Entity p_ = game.entities[i];
if (i == game.LocalPlayerId && (!game.ENABLE_TPP_VIEW))
{
continue;
}
if ((p_.networkPosition != null) && (!p_.networkPosition.PositionLoaded))
{
continue;
}
if (!game.d_FrustumCulling.SphereInFrustum(p_.position.x, p_.position.y, p_.position.z, 3))
{
continue;
}
if (p_.drawModel.CurrentTexture == -1)
{
continue;
}
int cx = game.platform.FloatToInt(p_.position.x) / Game.chunksize;
int cy = game.platform.FloatToInt(p_.position.z) / Game.chunksize;
int cz = game.platform.FloatToInt(p_.position.y) / Game.chunksize;
if (game.map.IsValidChunkPos(cx, cy, cz))
{
if (!game.map.IsChunkRendered(cx, cy, cz))
{
continue;
}
}
float shadow = (one * game.GetLight(game.platform.FloatToInt(p_.position.x), game.platform.FloatToInt(p_.position.z), game.platform.FloatToInt(p_.position.y))) / Game.maxlight;
if (p_.playerDrawInfo == null)
{
p_.playerDrawInfo = new PlayerDrawInfo();
}
p_.playerDrawInfo.anim.light = shadow;
float FeetPosX = p_.position.x;
float FeetPosY = p_.position.y;
float FeetPosZ = p_.position.z;
AnimationHint animHint = game.entities[i].playerDrawInfo.AnimationHint_;
float playerspeed_;
if (i == game.LocalPlayerId)
{
if (game.player.playerDrawInfo == null)
{
game.player.playerDrawInfo = new PlayerDrawInfo();
}
Vector3Ref playerspeed = Vector3Ref.Create(game.playervelocity.X / 60, game.playervelocity.Y / 60, game.playervelocity.Z / 60);
float playerspeedf = playerspeed.Length() * (one * 15 / 10);
game.player.playerDrawInfo.moves = playerspeedf != 0;
playerspeed_ = playerspeedf;
}
else
{
playerspeed_ = (game.Length(p_.playerDrawInfo.velocityX, p_.playerDrawInfo.velocityY, p_.playerDrawInfo.velocityZ) / dt) * (one * 4 / 100);
}
{
if (p_.drawModel.renderer == null)
{
p_.drawModel.renderer = new AnimatedModelRenderer();
byte[] data = game.GetFile(p_.drawModel.Model_);
int dataLength = game.GetFileLength(p_.drawModel.Model_);
if (data != null)
{
string dataString = game.platform.StringFromUtf8ByteArray(data, dataLength);
AnimatedModel model = AnimatedModelSerializer.Deserialize(game.platform, dataString);
p_.drawModel.renderer.Start(game, model);
}
}
game.GLPushMatrix();
game.GLTranslate(FeetPosX, FeetPosY, FeetPosZ);
//game.GLRotate(PlayerInterpolate.RadToDeg(p_.position.rotx), 1, 0, 0);
game.GLRotate(PlayerInterpolate.RadToDeg(-p_.position.roty + Game.GetPi()), 0, 1, 0);
//game.GLRotate(PlayerInterpolate.RadToDeg(p_.position.rotz), 0, 0, 1);
game.platform.BindTexture2d(game.entities[i].drawModel.CurrentTexture);
p_.drawModel.renderer.Render(dt, PlayerInterpolate.RadToDeg(p_.position.rotx + Game.GetPi()), true, p_.playerDrawInfo.moves, shadow);
game.GLPopMatrix();
}
}
}
示例4: NextBullet
//.........这里部分代码省略.........
Sprite sprite = new Sprite();
sprite.positionX = p[0];
sprite.positionY = p[1];
sprite.positionZ = p[2];
sprite.image = "blood.png";
entity.sprite = sprite;
entity.expires = Expires.Create(one * 2 / 10);
game.EntityAddLocal(entity);
}
shot.HitPlayer = i;
shot.IsHitHead = 0;
}
}
}
}
shot.WeaponBlock = item.BlockId;
game.LoadedAmmo[item.BlockId] = game.LoadedAmmo[item.BlockId] - 1;
game.TotalAmmo[item.BlockId] = game.TotalAmmo[item.BlockId] - 1;
float projectilespeed = game.DeserializeFloat(game.blocktypes[item.BlockId].ProjectileSpeedFloat);
if (projectilespeed == 0)
{
{
Entity entity = game.CreateBulletEntity(
pick.Start[0], pick.Start[1], pick.Start[2],
toX, toY, toZ, 150);
game.EntityAddLocal(entity);
}
}
else
{
float vX = toX - pick.Start[0];
float vY = toY - pick.Start[1];
float vZ = toZ - pick.Start[2];
float vLength = game.Length(vX, vY, vZ);
vX /= vLength;
vY /= vLength;
vZ /= vLength;
vX *= projectilespeed;
vY *= projectilespeed;
vZ *= projectilespeed;
shot.ExplodesAfter = game.SerializeFloat(game.grenadetime - wait);
{
Entity grenadeEntity = new Entity();
Sprite sprite = new Sprite();
sprite.image = "ChemicalGreen.png";
sprite.size = 14;
sprite.animationcount = 0;
sprite.positionX = pick.Start[0];
sprite.positionY = pick.Start[1];
sprite.positionZ = pick.Start[2];
grenadeEntity.sprite = sprite;
Grenade_ projectile = new Grenade_();
projectile.velocityX = vX;
projectile.velocityY = vY;
projectile.velocityZ = vZ;
projectile.block = item.BlockId;
projectile.sourcePlayer = game.LocalPlayerId;
grenadeEntity.expires = Expires.Create(game.grenadetime - wait);
grenadeEntity.grenade = projectile;
game.EntityAddLocal(grenadeEntity);
}
示例5: OnTouchMove
public override void OnTouchMove(Game game, TouchEventArgs e)
{
float one = 1;
if (e.GetId() == touchIdMove)
{
float range = game.Width() * one / 20;
game.touchMoveDx = e.GetX() - touchMoveStartX;
game.touchMoveDy = -((e.GetY() - 1) - touchMoveStartY);
float length = game.Length(game.touchMoveDx, game.touchMoveDy, 0);
if (e.GetY() < game.Height() * 50 / 100)
{
game.touchMoveDx = 0;
game.touchMoveDy = 1;
}
else
{
if (length > 0)
{
game.touchMoveDx /= length;
game.touchMoveDy /= length;
}
}
}
if (e.GetId() == touchIdRotate)
{
game.touchOrientationDx += (e.GetX() - touchRotateStartX) / (game.Width() * one / 40);
game.touchOrientationDy += (e.GetY() - touchRotateStartY) / (game.Width() * one / 40);
touchRotateStartX = e.GetX();
touchRotateStartY = e.GetY();
}
}