mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-01-24 01:52:24 -05:00
minor code cleanup
This commit is contained in:
parent
6cdcbe9480
commit
7ca1e00fcd
4 changed files with 94 additions and 92 deletions
|
@ -182,14 +182,15 @@ namespace ClassicalSharp.Gui.Screens {
|
||||||
|
|
||||||
static FastColour backColour = new FastColour(0, 0, 0, 127);
|
static FastColour backColour = new FastColour(0, 0, 0, 127);
|
||||||
public void RenderBackground() {
|
public void RenderBackground() {
|
||||||
int usedHeight = normalChat.GetUsedHeight();
|
int chatHeight = normalChat.GetUsedHeight();
|
||||||
int y = normalChat.Y + normalChat.Height - usedHeight - 5;
|
int x = normalChat.X;
|
||||||
int x = normalChat.X - 5;
|
int y = normalChat.Y + normalChat.Height - chatHeight;
|
||||||
int width = Math.Max(clientStatus.Width, normalChat.Width) + 10;
|
|
||||||
|
|
||||||
int boxHeight = usedHeight + clientStatus.GetUsedHeight();
|
int width = Math.Max(clientStatus.Width, normalChat.Width) + 10;
|
||||||
if (boxHeight > 0) {
|
int height = chatHeight + clientStatus.GetUsedHeight();
|
||||||
game.Graphics.Draw2DQuad(x, y, width, boxHeight + 10, backColour);
|
|
||||||
|
if (height > 0) {
|
||||||
|
game.Graphics.Draw2DQuad(x - 5, y - 5, width + 10, height + 10, backColour);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,78 +1,78 @@
|
||||||
// Copyright 2014-2017 ClassicalSharp | Licensed under BSD-3
|
// Copyright 2014-2017 ClassicalSharp | Licensed under BSD-3
|
||||||
using System;
|
using System;
|
||||||
using ClassicalSharp.Entities;
|
using ClassicalSharp.Entities;
|
||||||
using OpenTK;
|
using OpenTK;
|
||||||
|
|
||||||
namespace ClassicalSharp.Physics {
|
namespace ClassicalSharp.Physics {
|
||||||
|
|
||||||
/// <summary> Contains various methods for intersecting geometry. </summary>
|
/// <summary> Contains various methods for intersecting geometry. </summary>
|
||||||
public static class Intersection {
|
public static class Intersection {
|
||||||
|
|
||||||
/// <summary> Calculates the intersection points of a ray and a rotated bounding box. </summary>
|
/// <summary> Calculates the intersection points of a ray and a rotated bounding box. </summary>
|
||||||
public static bool RayIntersectsRotatedBox(Vector3 origin, Vector3 dir, Entity target, out float tMin, out float tMax) {
|
public static bool RayIntersectsRotatedBox(Vector3 origin, Vector3 dir, Entity target, out float tMin, out float tMax) {
|
||||||
// This is the rotated AABB of the model we want to test for intersection
|
// This is the rotated AABB of the model we want to test for intersection
|
||||||
// *
|
// *
|
||||||
// / \ we then perform a counter *---* and we can then do
|
// / \ we then perform a counter *---* and we can then do
|
||||||
// ====>* x * rotation to the rotated AABB | x | a standard AABB test
|
// ====>* x * rotation to the rotated AABB | x | a standard AABB test
|
||||||
// \ / and ray origin and direction *---* with the rotated ray
|
// \ / and ray origin and direction *---* with the rotated ray
|
||||||
// * /
|
// * /
|
||||||
// /
|
// /
|
||||||
origin = InverseRotate(origin - target.Position, target) + target.Position;
|
origin = InverseRotate(origin - target.Position, target) + target.Position;
|
||||||
dir = InverseRotate(dir, target);
|
dir = InverseRotate(dir, target);
|
||||||
AABB bb = target.PickingBounds;
|
AABB bb = target.PickingBounds;
|
||||||
return RayIntersectsBox(origin, dir, bb.Min, bb.Max, out tMin, out tMax);
|
return RayIntersectsBox(origin, dir, bb.Min, bb.Max, out tMin, out tMax);
|
||||||
}
|
}
|
||||||
|
|
||||||
static Vector3 InverseRotate(Vector3 pos, Entity target) {
|
static Vector3 InverseRotate(Vector3 pos, Entity target) {
|
||||||
pos = Utils.RotateY(pos, -target.RotY * Utils.Deg2Rad);
|
pos = Utils.RotateY(pos, -target.RotY * Utils.Deg2Rad);
|
||||||
pos = Utils.RotateZ(pos, -target.RotZ * Utils.Deg2Rad);
|
pos = Utils.RotateZ(pos, -target.RotZ * Utils.Deg2Rad);
|
||||||
pos = Utils.RotateX(pos, -target.RotX * Utils.Deg2Rad);
|
pos = Utils.RotateX(pos, -target.RotX * Utils.Deg2Rad);
|
||||||
return pos;
|
return pos;
|
||||||
}
|
}
|
||||||
|
|
||||||
//http://www.cs.utah.edu/~awilliam/box/box.pdf
|
//http://www.cs.utah.edu/~awilliam/box/box.pdf
|
||||||
/// <summary> Calculates the intersection points of a ray and a bounding box. </summary>
|
/// <summary> Calculates the intersection points of a ray and a bounding box. </summary>
|
||||||
public static bool RayIntersectsBox(Vector3 origin, Vector3 dir, Vector3 min, Vector3 max,
|
public static bool RayIntersectsBox(Vector3 origin, Vector3 dir, Vector3 min, Vector3 max,
|
||||||
out float t0, out float t1) {
|
out float t0, out float t1) {
|
||||||
t0 = t1 = 0;
|
t0 = t1 = 0;
|
||||||
float tmin, tmax, tymin, tymax, tzmin, tzmax;
|
float tmin, tmax, tymin, tymax, tzmin, tzmax;
|
||||||
float invDirX = 1 / dir.X;
|
float invDirX = 1 / dir.X;
|
||||||
if (invDirX >= 0) {
|
if (invDirX >= 0) {
|
||||||
tmin = (min.X - origin.X) * invDirX;
|
tmin = (min.X - origin.X) * invDirX;
|
||||||
tmax = (max.X - origin.X) * invDirX;
|
tmax = (max.X - origin.X) * invDirX;
|
||||||
} else {
|
} else {
|
||||||
tmin = (max.X - origin.X) * invDirX;
|
tmin = (max.X - origin.X) * invDirX;
|
||||||
tmax = (min.X - origin.X) * invDirX;
|
tmax = (min.X - origin.X) * invDirX;
|
||||||
}
|
}
|
||||||
|
|
||||||
float invDirY = 1 / dir.Y;
|
float invDirY = 1 / dir.Y;
|
||||||
if (invDirY >= 0) {
|
if (invDirY >= 0) {
|
||||||
tymin = (min.Y - origin.Y) * invDirY;
|
tymin = (min.Y - origin.Y) * invDirY;
|
||||||
tymax = (max.Y - origin.Y) * invDirY;
|
tymax = (max.Y - origin.Y) * invDirY;
|
||||||
} else {
|
} else {
|
||||||
tymin = (max.Y - origin.Y) * invDirY;
|
tymin = (max.Y - origin.Y) * invDirY;
|
||||||
tymax = (min.Y - origin.Y) * invDirY;
|
tymax = (min.Y - origin.Y) * invDirY;
|
||||||
}
|
}
|
||||||
if (tmin > tymax || tymin > tmax) return false;
|
if (tmin > tymax || tymin > tmax) return false;
|
||||||
if (tymin > tmin) tmin = tymin;
|
if (tymin > tmin) tmin = tymin;
|
||||||
if (tymax < tmax) tmax = tymax;
|
if (tymax < tmax) tmax = tymax;
|
||||||
|
|
||||||
float invDirZ = 1 / dir.Z;
|
float invDirZ = 1 / dir.Z;
|
||||||
if (invDirZ >= 0) {
|
if (invDirZ >= 0) {
|
||||||
tzmin = (min.Z - origin.Z) * invDirZ;
|
tzmin = (min.Z - origin.Z) * invDirZ;
|
||||||
tzmax = (max.Z - origin.Z) * invDirZ;
|
tzmax = (max.Z - origin.Z) * invDirZ;
|
||||||
} else {
|
} else {
|
||||||
tzmin = (max.Z - origin.Z) * invDirZ;
|
tzmin = (max.Z - origin.Z) * invDirZ;
|
||||||
tzmax = (min.Z - origin.Z) * invDirZ;
|
tzmax = (min.Z - origin.Z) * invDirZ;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tmin > tzmax || tzmin > tmax) return false;
|
if (tmin > tzmax || tzmin > tmax) return false;
|
||||||
if (tzmin > tmin) tmin = tzmin;
|
if (tzmin > tmin) tmin = tzmin;
|
||||||
if (tzmax < tmax) tmax = tzmax;
|
if (tzmax < tmax) tmax = tzmax;
|
||||||
|
|
||||||
t0 = tmin;
|
t0 = tmin;
|
||||||
t1 = tmax;
|
t1 = tmax;
|
||||||
return t0 >= 0;
|
return tmin >= 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -120,7 +120,7 @@ bool Intersection_RayIntersectsBox(Vector3 origin, Vector3 dir, Vector3 min, Vec
|
||||||
if (tzmax < tmax) tmax = tzmax;
|
if (tzmax < tmax) tmax = tzmax;
|
||||||
|
|
||||||
*t0 = tmin; *t1 = tmax;
|
*t0 = tmin; *t1 = tmax;
|
||||||
return *t0 >= 0;
|
return tmin >= 0.0f;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -846,14 +846,15 @@ static void ChatScreen_CheckOtherStatuses(ChatScreen* screen) {
|
||||||
|
|
||||||
static void ChatScreen_RenderBackground(ChatScreen* screen) {
|
static void ChatScreen_RenderBackground(ChatScreen* screen) {
|
||||||
Int32 usedHeight = TextGroupWidget_UsedHeight(&screen->Chat);
|
Int32 usedHeight = TextGroupWidget_UsedHeight(&screen->Chat);
|
||||||
Int32 y = screen->Chat.Y + screen->Chat.Height - usedHeight - 5;
|
Int32 x = screen->Chat.X;
|
||||||
Int32 x = screen->Chat.X - 5;
|
Int32 y = screen->Chat.Y + screen->Chat.Height - usedHeight;
|
||||||
Int32 width = max(screen->ClientStatus.Width, screen->Chat.Width) + 10;
|
|
||||||
|
|
||||||
Int32 boxHeight = usedHeight + TextGroupWidget_UsedHeight(&screen->ClientStatus);
|
Int32 width = max(screen->ClientStatus.Width, screen->Chat.Width);
|
||||||
if (boxHeight > 0) {
|
Int32 height = usedHeight + TextGroupWidget_UsedHeight(&screen->ClientStatus);
|
||||||
|
|
||||||
|
if (height > 0) {
|
||||||
PackedCol backCol = PACKEDCOL_CONST(0, 0, 0, 127);
|
PackedCol backCol = PACKEDCOL_CONST(0, 0, 0, 127);
|
||||||
GfxCommon_Draw2DFlat(x, y, width, boxHeight + 10, backCol);
|
GfxCommon_Draw2DFlat(x - 5, y - 5, width + 10, height + 10, backCol);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue