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; }
public void AddPoint(float x, float y, float z) { //if is empty if (MinEdge == null || MaxEdge == null || (MinEdge[0] == 0 && MinEdge[1] == 0 && MinEdge[2] == 0 && MaxEdge[0] == 0 && MaxEdge[1] == 0 && MaxEdge[2] == 0)) { MinEdge = Vec3.FromValues(x, y, z); MaxEdge = Vec3.FromValues(x, y, z); } MinEdge[0] = MathCi.MinFloat(MinEdge[0], x); MinEdge[1] = MathCi.MinFloat(MinEdge[1], y); MinEdge[2] = MathCi.MinFloat(MinEdge[2], z); MaxEdge[0] = MathCi.MaxFloat(MaxEdge[0], x); MaxEdge[1] = MathCi.MaxFloat(MaxEdge[1], y); MaxEdge[2] = MathCi.MaxFloat(MaxEdge[2], z); }