Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/4.0/update core types #465

Merged
merged 18 commits into from
Jul 7, 2023
Merged
Show file tree
Hide file tree
Changes from 17 commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
eaf54bb
feat(4.0): Update AABB api according to 4.0 documentation
piiertho May 21, 2023
d52f0e9
feat(4.0): Update Basis api according to godot 4.0 documentation
piiertho May 22, 2023
9964d7f
feat(4.0): Add missing api in Callable
piiertho May 22, 2023
799f81e
feat(4.0): Update color core type according to 4.0 api documentation
piiertho May 22, 2023
daa0881
feat(4.0): Update documentation core type according to 4.0 api docume…
piiertho May 23, 2023
dc9b01c
feat(4.0): update Plane core type according to godot 4.0 api document…
piiertho May 23, 2023
b4dc0e7
feat(4.0): update Quaternion core type according to godot 4.0 api doc…
piiertho May 23, 2023
dd402ba
feat(4.0): update Rect2 core type according to godot 4.0 api document…
piiertho May 23, 2023
b6085f4
feat(4.0): update Rect2i core type according to godot 4.0 api documen…
piiertho May 23, 2023
3dce1f6
feat(4.0): update Vector4i core type according to godot 4.0 api docum…
piiertho May 23, 2023
3ec6494
feat(4.0): update Vector4 core type according to godot 4.0 api docume…
piiertho May 23, 2023
8e6ba61
feat(4.0): update Vector3i core type according to godot 4.0 api docum…
piiertho May 23, 2023
0c06a3d
feat(4.0): update Vector3 core type according to godot 4.0 api docume…
piiertho May 23, 2023
a833396
feat(4.0): update Vector2i core type according to godot 4.0 api docum…
piiertho May 23, 2023
599dcfa
feat(4.0): update Vector2 core type according to godot 4.0 api docume…
piiertho May 23, 2023
30e337c
feat(4.0): update transforms core types according to godot 4.0 api do…
piiertho May 23, 2023
499a0cb
feat(4.0): Add invoke operator method on StringName to use kotlin str…
piiertho May 24, 2023
91d6a6c
fix: remove duplicates command, duplicates colors and fix documentati…
piiertho Jun 2, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions harness/tests/scripts/godot/tests/Invocation.gdj
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,20 @@ registeredName = Invocation
fqName = godot.tests.Invocation
baseType = Node3D
supertypes = [
godot.Node3D,
godot.Node3D,
godot.Node,
godot.Object,
godot.core.KtObject,
kotlin.Any
]
signals = [
no_param,
no_param,
one_param,
two_param,
signal_with_multiple_targets
]
properties = [
button,
button,
enum_list,
vector_list,
enum_list_mutable,
Expand Down Expand Up @@ -76,7 +76,7 @@ properties = [
array
]
functions = [
target_function_one,
target_function_one,
target_function_two,
int_value,
long_value,
Expand Down Expand Up @@ -169,4 +169,4 @@ functions = [
nullable_string_is_null,
nullable_return_type,
create_variant_array_of_user_type
]
]
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class BasisTest : Node() {

@RegisterFunction
fun getRotationQuat(basis: Basis): Quaternion {
return basis.getRotationQuat()
return basis.getRotationQuaternion()
}

@RegisterFunction
Expand Down
104 changes: 86 additions & 18 deletions kt/godot-library/src/main/kotlin/godot/core/AABB.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package godot.core
import godot.annotation.CoreTypeHelper
import godot.util.CMP_EPSILON
import godot.util.RealT
import kotlin.math.min


class AABB(
p_position: Vector3,
Expand Down Expand Up @@ -73,6 +75,19 @@ class AABB(
this(other._position, other._size)

//API
/**
* Returns an AABB with equivalent position and size, modified so that the most-negative corner is the origin and
* the size is positive.
*/
fun abs() = AABB(
Vector3(
position.x + min(size.x, 0.0),
position.y + min(size.y, 0.0),
position.z + min(size.z, 0.0)
),
size.abs()
)

/**
* Returns true if this AABB completely encloses another one.
*/
Expand Down Expand Up @@ -127,11 +142,9 @@ class AABB(
}

/**
* Returns the volume of the AABB.
* Returns the center of the [AABB], which is equal to [position] + ([size] / 2).
*/
fun getArea(): RealT {
return _size.x * _size.y * _size.z
}
fun getCenter() = position + (size * 0.5)

/**
* Gets the position of the 8 endpoints of the AABB in space.
Expand Down Expand Up @@ -271,6 +284,13 @@ class AABB(
) + ofs
}

/**
* Returns the volume of the AABB.
*/
fun getVolume(): RealT {
return _size.x * _size.y * _size.z
}

/**
* Returns a copy of the AABB grown a given amount of units towards all the sides.
*/
Expand All @@ -289,20 +309,6 @@ class AABB(
_size.z += 2.0 * amount
}

/**
* Returns true if the AABB is flat or empty.
*/
fun hasNoArea(): Boolean {
return (_size.x <= CMP_EPSILON || _size.y <= CMP_EPSILON || _size.z <= CMP_EPSILON)
}

/**
* Returns true if the AABB is empty.
*/
fun hasNoSurface(): Boolean {
return (_size.x <= CMP_EPSILON && _size.y <= CMP_EPSILON && _size.z <= CMP_EPSILON)
}

/**
* Returns true if the AABB contains a point.
*/
Expand All @@ -318,6 +324,20 @@ class AABB(
}
}

/**
* Returns true if the AABB is empty.
*/
fun hasSurface(): Boolean {
Copy link
Member

@CedNaru CedNaru Jun 1, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment is incorrect, it returns false if empty

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Former comment that I did not checked. Will change it.

return (_size.x > CMP_EPSILON && _size.y > CMP_EPSILON && _size.z > CMP_EPSILON)
}

/**
* Returns true if the AABB is flat or empty.
*/
fun hasVolume(): Boolean {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here

return (_size.x > CMP_EPSILON || _size.y > CMP_EPSILON || _size.z > CMP_EPSILON)
}

/**
* Returns the intersection between two AABB. An empty AABB (size 0,0,0) is returned on failure.
*/
Expand Down Expand Up @@ -396,6 +416,49 @@ class AABB(
return under && over
}

/**
* Returns `true` if the given ray intersects with this [AABB]. Ray length is infinite.
*/
fun intersectsRay(from: Vector3, dir: Vector3): Boolean {
require(size.x >= 0 && size.y >= 0 && size.z >= 0) {
"AABB size is negative, this is not supported. Use AABB.abs() to get an AABB with a positive size."
}
Comment on lines +424 to +426
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it a good idea to crash here? Shouldn't we log an error and return false instead?
I know godot "crashes" in such cases but don't we then have issues if such a call originated from the cpp side?

Same for other usages of require and the likes.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should better explain to jetbrains they have a vision regarding preprocessors that is not compatible with game industry.
Here I would expect a debug version of engine to have this require call and crash, to spot problems asap, and a release version without this call.
Anyway, this should not be modified in this PR IMO, as we have a lot of already existing require in core types.


var c1 = Vector3()
var c2 = Vector3()
val end = position + size
var near = -1e20
var far = 1e20
var axis = 0

for (i in 0..2) {
if (dir[i] == 0.0) {
if (from[i] < position[i] || from[i] > end[i]) {
return false
}
} else { // ray not parallel to planes in this direction
c1[i] = (position[i] - from[i]) / dir[i]
c2[i] = (end[i] - from[i]) / dir[i]
if (c1[i] > c2[i]) {
val aux = c1
c1 = c2
c2 = aux
}
if (c1[i] > near) {
near = c1[i]
}
if (c2[i] < far) {
far = c2[i]
}
if (near > far || far < 0) {
return false
}
}
}

return true
}

/**
* Returns true if the AABB intersects the line segment between from and to.
*/
Expand Down Expand Up @@ -445,6 +508,11 @@ class AABB(
return this._position.isEqualApprox(other._position) && this._size.isEqualApprox(other._size)
}

/**
* Returns `true` if this [AABB] is finite, by calling [Vector3.isFinite] on each component.
*/
fun isFinite() = position.isFinite() && size.isFinite()

/**
* Returns a larger AABB that contains both this AABB and with.
*/
Expand Down
Loading