public static PointFloatRef Create(float x_, float y_) { PointFloatRef p = new PointFloatRef(); p.X = x_; p.Y = y_; return(p); }
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; }
internal PointFloatRef GetAim(Game game) { if (game.CurrentAimRadius() <= 1) { return(PointFloatRef.Create(0, 0)); } float half = 0.5f; float x; float y; for (; ;) { x = (game.rnd.NextFloat() - half) * game.CurrentAimRadius() * 2; y = (game.rnd.NextFloat() - half) * game.CurrentAimRadius() * 2; float dist1 = game.platform.MathSqrt(x * x + y * y); if (dist1 <= game.CurrentAimRadius()) { break; } } return(PointFloatRef.Create(x, y)); }
public static PointFloatRef Create(float x_, float y_) { PointFloatRef p = new PointFloatRef(); p.X = x_; p.Y = y_; return p; }