Compare commits

..

62 Commits

Author SHA1 Message Date
Rémi Verschelde
5c28d4675e headers: Track tag godot-3.3.4-stable 2021-10-01 08:29:05 +02:00
Rémi Verschelde
402e33a7dc headers: Track tag godot-3.3.3-stable 2021-09-26 13:20:50 +02:00
Rémi Verschelde
e96e49e63b Merge pull request #618 from akien-mga/ci-tests-godot-3.3.3 2021-09-26 13:16:24 +02:00
Rémi Verschelde
d9477fd0aa CI: Run tests with Godot 3.3.3 2021-09-26 12:43:41 +02:00
Rémi Verschelde
6e013e415d Merge pull request #617 from akien-mga/ci-linux-ubuntu-18.04 2021-09-26 12:40:46 +02:00
Rémi Verschelde
4b6ab10c5d CI: Update Linux runner to Ubuntu 18.04
Also cleanup needlessly specific dependencies.
2021-09-26 12:15:19 +02:00
Bastiaan Olij
1bb06e8507 Merge pull request #616 from raulsntos/fix-enum-params
Escape parameters named `enum`.
2021-09-23 09:54:33 +10:00
Raul Santos
54c2d23572 Escape parameters named enum.
Prefix parameters named `enum` with an underscore like all the other
reserved keywords.
2021-09-22 16:07:23 +02:00
Fabio Alessandrelli
466f2cdebf Merge pull request #590 from Faless/generator/fix_byte_array_default
Fix binding when default parameter is a PoolByteArray.
2021-09-07 20:08:56 +02:00
Bastiaan Olij
6e1af3bedb Merge pull request #594 from Calinou/error-list-remove-extraneous-values
Remove extraneous Error enum values that were removed in Godot 3.0
2021-09-04 23:31:38 +10:00
BoomerDev
8efe619e3a Fix typo in README.md (#608) 2021-09-03 16:43:01 +02:00
Hugo Locurcio
abab0715a0 Remove extraneous Error enum values that were removed in Godot 3.0 2021-08-02 18:23:41 +02:00
Hugo Locurcio
b56df8f6da Merge pull request #593 from maiself/fix-crash-cond
Fix typo in CRASH_COND leading to unexpected continuation after fail
2021-08-02 18:07:23 +02:00
Mai Lavelle
2f534ddd88 Fix typo in CRASH_COND leading to unexpected continuation after fail 2021-08-01 17:20:39 -04:00
Fabio Alessandrelli
024ffef50f Fix binding when default parameter is a PoolByteArray.
Like done for the other pool array types.
2021-07-17 18:06:50 +02:00
Fabio Alessandrelli
e08ecdc28c Merge pull request #584 from Faless/build/osx_arm64
Add OSX arm64 build target.
2021-07-09 16:03:49 +02:00
Fabio Alessandrelli
784103f676 Merge pull request #581 from Faless/build/optimization_flags
Add optimization flags for android and javascript.
2021-07-09 16:01:47 +02:00
Fabio Alessandrelli
98124aafe8 Merge pull request #580 from Faless/js/fix_suffix
Fix JavaScript library suffix.
2021-07-09 15:51:51 +02:00
Fabio Alessandrelli
5b8bcb7164 Add OSX arm64 build target.
New "macos_arch" to specify the desired arch, and "macos_sdk_path" to
override the default SDK path.
2021-07-07 11:08:33 +02:00
Fabio Alessandrelli
e5279d3d0f Add optimization flags for android and javascript. 2021-07-05 15:53:52 +02:00
Fabio Alessandrelli
26d4df4e17 Fix JavaScript library suffix.
Also add `.bc` files to `.gitignore`
2021-07-05 15:47:49 +02:00
dependabot[bot]
dbf3a13d0f Bump actions/upload-artifact from 2.2.3 to 2.2.4 (#571)
Bumps [actions/upload-artifact](https://github.com/actions/upload-artifact) from 2.2.3 to 2.2.4.
- [Release notes](https://github.com/actions/upload-artifact/releases)
- [Commits](https://github.com/actions/upload-artifact/compare/v2.2.3...v2.2.4)

---
updated-dependencies:
- dependency-name: actions/upload-artifact
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2021-06-16 21:41:21 +02:00
Marc
fda7ddd158 Merge pull request #567 from DhruvMaroo/string
added String's move constructor and move assignment operator
2021-06-01 23:35:46 +01:00
DhruvMaroo
7a1890345b edited according to clang-format 2021-06-01 23:16:09 +05:30
Marc
59959b1a5b Merge pull request #566 from DhruvMaroo/master
added inverse trigonometric functions in Math.hpp
2021-06-01 18:08:59 +01:00
DhruvMaroo
67e2c6145c used godot_string_new_copy to copy 2021-05-31 09:31:11 +05:30
DhruvMaroo
b44b98a94c removed _deleted class member 2021-05-31 09:10:59 +05:30
DhruvMaroo
cd05371ce8 added class member, safety check in the destructor 2021-05-31 00:52:36 +05:30
DhruvMaroo
492285f681 changed spaces to tabs 2021-05-30 22:29:41 +05:30
DhruvMaroo
6e662223aa changed spaces to tabs 2021-05-30 22:15:37 +05:30
DhruvMaroo
bdc5674ace added move assignment operator 2021-05-30 12:33:40 +05:30
DhruvMaroo
689b5fb98b added mover constructor 2021-05-30 12:30:11 +05:30
DhruvMaroo
c296e9210b Revert "Revert "added inverse trigonometric functions in Math.hpp""
This reverts commit 8ef2e4f139.
2021-05-30 12:23:39 +05:30
DhruvMaroo
8ef2e4f139 Revert "added inverse trigonometric functions in Math.hpp"
This reverts commit 5128858b1e.
2021-05-30 12:22:45 +05:30
DhruvMaroo
5128858b1e added inverse trigonometric functions in Math.hpp 2021-05-30 11:45:47 +05:30
Rémi Verschelde
dfee6f0ca4 headers: Track tag godot-3.3.2-stable 2021-05-25 15:01:57 +02:00
Rémi Verschelde
f298d36c86 Merge pull request #557 from godotengine/dependabot/github_actions/actions/upload-artifact-2.2.3
Bump actions/upload-artifact from 2.2.2 to 2.2.3
2021-05-25 15:00:35 +02:00
Hristo Stamenov
c629200b93 Update string(TOLOWER ...) to take string versions of CMake variables (#561)
On some generators (MSVC) there is the issue that this line produces cause by the variable being expanded and not being surrounded by quotes.
2021-05-20 14:47:20 +02:00
Hristo Stamenov
476a870d6c Fix CMake generation on Windows (#536) 2021-05-15 22:57:05 +02:00
dependabot[bot]
eb8ae9dd51 Bump actions/upload-artifact from 2.2.2 to 2.2.3
Bumps [actions/upload-artifact](https://github.com/actions/upload-artifact) from 2.2.2 to 2.2.3.
- [Release notes](https://github.com/actions/upload-artifact/releases)
- [Commits](https://github.com/actions/upload-artifact/compare/v2.2.2...v2.2.3)

Signed-off-by: dependabot[bot] <support@github.com>
2021-05-12 05:48:34 +00:00
Rémi Verschelde
d68e629a7c Merge pull request #552 from BastiaanOlij/update_33
Move godot-headers forward to 3.3-stable
2021-05-04 08:43:17 +02:00
Bastiaan Olij
87e97cb85e Move godot-headers forward to 3.3-stable 2021-05-04 12:18:34 +10:00
Marc
1637975a0b Merge pull request #550 from abaire/master
Populates incorrect constants for Vector2 and 3 types.
2021-05-03 15:26:54 +01:00
Erik Abair
2ccc5e08f2 Populates incorrect constants for Vector2 and 3 types. 2021-05-02 15:35:21 -07:00
George Marques
d7c55b1ab2 Merge pull request #530 from Faless/js/scons_and_readme
Add JavaScript platform support (emcc, wasm).
2021-03-22 09:57:45 -03:00
George Marques
6e4a13beec Merge pull request #400 from portaloffreedom/cmake-gen-fix
Fixed cmake source file generation
2021-03-12 12:58:49 -03:00
Fabio Alessandrelli
f6899e190f Add JavaScript platform support (emcc, wasm).
Includes update to `README.md` with instructions on how to build a
GDNative library for webassembly.
2021-03-11 05:11:13 +01:00
Matteo De Carlo
0c8dd096c4 Fix cmake source file generation 2021-03-03 19:40:54 +01:00
Rémi Verschelde
55c0a2ea03 Merge pull request #525 from vnen/update-clang-format
Update clang-format to version 11
2021-03-01 16:28:58 +01:00
George Marques
cee79bb7a6 Merge pull request #517 from SeleDreams/master
Added freebsd specific configuration to SConstruct
2021-03-01 11:56:37 -03:00
George Marques
87f7e061a0 Merge pull request #492 from o01eg/fix-python-detect
Search correct python interpeter in case missing default "python"
2021-03-01 11:47:07 -03:00
George Marques
6c56bfdc8f Merge pull request #497 from godotengine/dependabot/github_actions/actions/upload-artifact-v2.2.2
Bump actions/upload-artifact from v2.2.1 to v2.2.2
2021-03-01 11:10:40 -03:00
George Marques
a65a340329 Merge pull request #507 from Zylann/bindings_auto_gen
Generate bindings if they are not found
2021-03-01 09:47:45 -03:00
dependabot[bot]
ba526df7bd Bump actions/upload-artifact from v2.2.1 to v2.2.2
Bumps [actions/upload-artifact](https://github.com/actions/upload-artifact) from v2.2.1 to v2.2.2.
- [Release notes](https://github.com/actions/upload-artifact/releases)
- [Commits](https://github.com/actions/upload-artifact/compare/v2.2.1...e448a9b857ee2131e752b06002bf0e093c65e571)

Signed-off-by: dependabot[bot] <support@github.com>
2021-03-01 12:46:57 +00:00
oleg
52f786b923 Search correct python interpeter in case missing default "python" 2021-03-01 15:46:11 +03:00
George Marques
aa2792528e Merge pull request #456 from API-Beast/master
Fix compiling using CMake and GCC
2021-03-01 09:37:54 -03:00
George Marques
cba90d6301 Update clang-format to version 11
This is taken from the Godot repository, so formatting is similar. This
updates the style rules as well.

Also fix style in files to conform with this version.
2021-02-28 16:57:34 -03:00
SeleDreams
45fef69aca Added freebsd specific configuration to fix issues of detection on freebsd 2021-02-21 00:23:06 +01:00
Marc Gilleron
f669380811 Generate bindings if they are not found 2021-02-03 22:48:58 +00:00
Manuel Riecke
2989a385d7 GENERATE_TEMPLATE_GET_NODE option for CMake 2020-09-20 12:18:42 +02:00
Manuel Riecke
73f1f90bf7 Fix godot-cpp not compiling because of -Wlong-long 2020-09-19 13:42:00 +02:00
Manuel Riecke
2007e6f81e Fix CMake failing to generate the bindings.
A new parameter was added to the binding_generator python file,
but the CMake file was not adjusted.
2020-09-19 13:42:00 +02:00
35 changed files with 345 additions and 358 deletions

View File

@@ -13,9 +13,9 @@ AlignAfterOpenBracket: DontAlign
AlignTrailingComments: false
AllowAllParametersOfDeclarationOnNextLine: false
# AllowShortBlocksOnASingleLine: false
AllowShortCaseLabelsOnASingleLine: true
# AllowShortCaseLabelsOnASingleLine: false
AllowShortFunctionsOnASingleLine: Inline
AllowShortIfStatementsOnASingleLine: true
# AllowShortIfStatementsOnASingleLine: false
# AllowShortLoopsOnASingleLine: false
# AlwaysBreakAfterDefinitionReturnType: None
# AlwaysBreakAfterReturnType: None
@@ -76,7 +76,7 @@ IndentWidth: 4
# IndentWrappedFunctionNames: false
# JavaScriptQuotes: Leave
# JavaScriptWrapImports: true
# KeepEmptyLinesAtTheStartOfBlocks: true
KeepEmptyLinesAtTheStartOfBlocks: false
# MacroBlockBegin: ''
# MacroBlockEnd: ''
# MaxEmptyLinesToKeep: 1
@@ -112,10 +112,11 @@ UseTab: Always
---
### C++ specific config ###
Language: Cpp
Standard: Cpp03
Standard: Cpp11
---
### ObjC specific config ###
Language: ObjC
Standard: Cpp11
ObjCBlockIndentWidth: 4
# ObjCSpaceAfterProperty: false
# ObjCSpaceBeforeProtocolList: true
@@ -123,4 +124,5 @@ ObjCBlockIndentWidth: 4
### Java specific config ###
Language: Java
# BreakAfterJavaFieldAnnotations: false
JavaImportGroups: ['org.godotengine', 'android', 'androidx', 'com.android', 'com.google', 'java', 'javax']
...

View File

@@ -4,34 +4,34 @@ on: [push, pull_request]
jobs:
linux:
name: Build (Linux, GCC)
runs-on: ubuntu-16.04
runs-on: ubuntu-18.04
steps:
- name: Checkout
uses: actions/checkout@v2.3.4
uses: actions/checkout@v2
with:
submodules: recursive
- name: Set up Python (for SCons)
uses: actions/setup-python@v2
with:
python-version: '3.9.1'
python-version: '3.x'
- name: Install dependencies
run: |
sudo apt-get update -qq
sudo apt-get install -qqq build-essential pkg-config
python -m pip install scons
curl -LO https://downloads.tuxfamily.org/godotengine/3.2.3/Godot_v3.2.3-stable_linux_server.64.zip
unzip Godot_v3.2.3-stable_linux_server.64.zip
curl -LO https://downloads.tuxfamily.org/godotengine/3.3.3/Godot_v3.3.3-stable_linux_server.64.zip
unzip Godot_v3.3.3-stable_linux_server.64.zip
- name: Build godot-cpp
run: |
scons target=release generate_bindings=yes -j $(nproc)
- name: Upload artifact
uses: actions/upload-artifact@v2.2.1
uses: actions/upload-artifact@v2
with:
name: godot-cpp-linux-glibc2.23-x86_64-release
name: godot-cpp-linux-glibc2.27-x86_64-release
path: bin/libgodot-cpp.linux.release.64.a
if-no-files-found: error
@@ -41,21 +41,21 @@ jobs:
- name: Run test GDNative library
run: |
./Godot_v3.2.3-stable_linux_server.64 --path test -s script.gd
./Godot_v3.3.3-stable_linux_server.64 --path test -s script.gd
windows-msvc:
name: Build (Windows, MSVC)
runs-on: windows-2019
steps:
- name: Checkout
uses: actions/checkout@v2.3.4
uses: actions/checkout@v2
with:
submodules: recursive
- name: Set up Python (for SCons)
uses: actions/setup-python@v2
with:
python-version: '3.9.1'
python-version: '3.x'
- name: Install dependencies
run: |
@@ -66,7 +66,7 @@ jobs:
scons target=release generate_bindings=yes -j $env:NUMBER_OF_PROCESSORS
- name: Upload artifact
uses: actions/upload-artifact@v2.2.1
uses: actions/upload-artifact@v2
with:
name: godot-cpp-windows-msvc2019-x86_64-release
path: bin/libgodot-cpp.windows.release.64.lib
@@ -77,14 +77,14 @@ jobs:
runs-on: windows-2019
steps:
- name: Checkout
uses: actions/checkout@v2.3.4
uses: actions/checkout@v2
with:
submodules: recursive
- name: Set up Python (for SCons)
uses: actions/setup-python@v2
with:
python-version: '3.9.1'
python-version: '3.x'
- name: Install dependencies
run: |
@@ -100,7 +100,7 @@ jobs:
scons target=release generate_bindings=yes use_mingw=yes -j $env:NUMBER_OF_PROCESSORS
- name: Upload artifact
uses: actions/upload-artifact@v2.2.1
uses: actions/upload-artifact@v2
with:
name: godot-cpp-linux-mingw-x86_64-release
path: bin/libgodot-cpp.windows.release.64.a
@@ -111,27 +111,27 @@ jobs:
runs-on: macos-10.15
steps:
- name: Checkout
uses: actions/checkout@v2.3.4
uses: actions/checkout@v2
with:
submodules: recursive
- name: Set up Python (for SCons)
uses: actions/setup-python@v2
with:
python-version: '3.9.1'
python-version: '3.x'
- name: Install dependencies
run: |
python -m pip install scons
curl -LO https://downloads.tuxfamily.org/godotengine/3.2.3/Godot_v3.2.3-stable_osx.64.zip
unzip Godot_v3.2.3-stable_osx.64.zip
curl -LO https://downloads.tuxfamily.org/godotengine/3.3.3/Godot_v3.3.3-stable_osx.universal.zip
unzip Godot_v3.3.3-stable_osx.universal.zip
- name: Build godot-cpp
run: |
scons target=release generate_bindings=yes -j $(sysctl -n hw.logicalcpu)
- name: Upload artifact
uses: actions/upload-artifact@v2.2.1
uses: actions/upload-artifact@v2
with:
name: godot-cpp-macos-x86_64-release
path: bin/libgodot-cpp.osx.release.64.a
@@ -145,16 +145,51 @@ jobs:
run: |
./Godot.app/Contents/MacOS/Godot --path test -s script.gd
static-checks:
name: Static Checks (clang-format)
runs-on: ubuntu-16.04
macos-arm64:
name: Build (macOS, Clang, cross-compile arm64)
runs-on: macos-latest
steps:
- name: Checkout
uses: actions/checkout@v2.3.4
uses: actions/checkout@v2
with:
submodules: recursive
- name: Set up Python (for SCons)
uses: actions/setup-python@v2
with:
python-version: '3.x'
- name: Install dependencies
run: |
sudo apt-get install clang-format-8
python -m pip install scons
- name: Build godot-cpp
run: |
# The default SDK in github the actions environemnt seems to have problems compiling for arm64.
# Use the latest 11.x SDK.
SDK_BASE=/Library/Developer/CommandLineTools/SDKs
SDK_VER=$(ls $SDK_BASE | grep "MacOSX11." | sort -r | head -n1)
echo $SDK_BASE/$SDK_VER/
scons target=release generate_bindings=yes macos_arch=arm64 macos_deployment_target=10.15 macos_sdk_path="$SDK_BASE/$SDK_VER/" -j $(sysctl -n hw.logicalcpu)
static-checks:
name: Static Checks (clang-format)
runs-on: ubuntu-20.04
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Make apt sources.list use the default Ubuntu repositories
run: |
sudo rm -f /etc/apt/sources.list.d/*
sudo cp -f misc/ci/sources.list /etc/apt/sources.list
sudo apt-get update
- name: Install dependencies
run: |
sudo apt-get install -qq dos2unix recode clang-format-11
sudo update-alternatives --remove-all clang-format
sudo update-alternatives --install /usr/bin/clang-format clang-format /usr/bin/clang-format-11 100
- name: Style checks via clang-format
run: |

1
.gitignore vendored
View File

@@ -6,6 +6,7 @@ logs/*
*.os
*.so
*.obj
*.bc
*.pyc
*.dblite
*.pdb

View File

@@ -37,6 +37,8 @@
project(godot-cpp)
cmake_minimum_required(VERSION 3.6)
option(GENERATE_TEMPLATE_GET_NODE "Generate a template version of the Node class's get_node." ON)
# Change the output directory to the bin directory
set(BUILD_PATH ${CMAKE_SOURCE_DIR}/bin)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${BUILD_PATH}")
@@ -109,7 +111,7 @@ else()
set(GODOT_COMPILE_FLAGS "${GODOT_COMPILE_FLAGS} -Wchar-subscripts -Wcomment -Wdisabled-optimization")
set(GODOT_COMPILE_FLAGS "${GODOT_COMPILE_FLAGS} -Wformat -Wformat=2 -Wformat-security -Wformat-y2k")
set(GODOT_COMPILE_FLAGS "${GODOT_COMPILE_FLAGS} -Wimport -Winit-self -Winline -Winvalid-pch -Werror")
set(GODOT_COMPILE_FLAGS "${GODOT_COMPILE_FLAGS} -Wlong-long -Wmissing-braces -Wmissing-format-attribute")
set(GODOT_COMPILE_FLAGS "${GODOT_COMPILE_FLAGS} -Wmissing-braces -Wmissing-format-attribute")
set(GODOT_COMPILE_FLAGS "${GODOT_COMPILE_FLAGS} -Wmissing-include-dirs -Wmissing-noreturn -Wpacked -Wpointer-arith")
set(GODOT_COMPILE_FLAGS "${GODOT_COMPILE_FLAGS} -Wredundant-decls -Wreturn-type -Wsequence-point")
set(GODOT_COMPILE_FLAGS "${GODOT_COMPILE_FLAGS} -Wswitch -Wswitch-enum -Wtrigraphs")
@@ -131,24 +133,53 @@ else()
endif()
# Generate source from the bindings file
find_package(PythonInterp REQUIRED)
if(GENERATE_TEMPLATE_GET_NODE)
set(GENERATE_BINDING_PARAMETERS "True")
else()
set(GENERATE_BINDING_PARAMETERS "False")
endif()
message(STATUS "Generating Bindings")
execute_process(COMMAND "python" "-c" "import binding_generator; binding_generator.generate_bindings(\"${GODOT_CUSTOM_API_FILE}\")"
execute_process(COMMAND "${PYTHON_EXECUTABLE}" "-c" "import binding_generator; binding_generator.print_file_list(\"${GODOT_CUSTOM_API_FILE}\", \"${CMAKE_CURRENT_BINARY_DIR}\", headers=True)"
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
RESULT_VARIABLE GENERATION_RESULT
OUTPUT_VARIABLE GENERATION_OUTPUT)
message(STATUS ${GENERATION_RESULT} ${GENERATION_OUTPUT})
RESULT_VARIABLE HEADERS_FILE_LIST_RESULT
OUTPUT_VARIABLE HEADERS_FILE_LIST
)
set(HEADERS_FILE_LIST ${HEADERS_FILE_LIST})
execute_process(COMMAND "${PYTHON_EXECUTABLE}" "-c" "import binding_generator; binding_generator.print_file_list(\"${GODOT_CUSTOM_API_FILE}\", \"${CMAKE_CURRENT_BINARY_DIR}\", sources=True)"
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
RESULT_VARIABLE SOURCES_FILE_LIST_RESULT
OUTPUT_VARIABLE SOURCES_FILE_LIST
)
set(SOURCES_FILE_LIST ${SOURCES_FILE_LIST})
add_custom_command(OUTPUT ${HEADERS_FILE_LIST} ${SOURCES_FILE_LIST}
COMMAND "${PYTHON_EXECUTABLE}" "-c" "import binding_generator; binding_generator.generate_bindings(\"${GODOT_CUSTOM_API_FILE}\", \"${GENERATE_BINDING_PARAMETERS}\", \"${CMAKE_CURRENT_BINARY_DIR}\")"
VERBATIM
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
MAIN_DEPENDENCY ${GODOT_CUSTOM_API_FILE}
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/binding_generator.py
COMMENT Generating Bindings
)
# Get Sources
file(GLOB_RECURSE SOURCES src/*.c**)
file(GLOB_RECURSE HEADERS include/*.h**)
# Define our godot-cpp library
add_library(${PROJECT_NAME} ${SOURCES} ${HEADERS})
add_library(${PROJECT_NAME}
${SOURCES}
${SOURCES_FILE_LIST}
${HEADERS}
${HEADERS_FILE_LIST}
)
target_include_directories(${PROJECT_NAME}
PUBLIC
include
include/core
include/gen
${CMAKE_CURRENT_BINARY_DIR}/include/gen/
)
# Put godot headers as SYSTEM PUBLIC to exclude warnings from irrelevant headers
@@ -168,8 +199,8 @@ if(CMAKE_SIZEOF_VOID_P EQUAL 8)
set(BITS 64)
endif(CMAKE_SIZEOF_VOID_P EQUAL 8)
string(TOLOWER ${CMAKE_SYSTEM_NAME} SYSTEM_NAME)
string(TOLOWER ${CMAKE_BUILD_TYPE} BUILD_TYPE)
string(TOLOWER "${CMAKE_SYSTEM_NAME}" SYSTEM_NAME)
string(TOLOWER "${CMAKE_BUILD_TYPE}" BUILD_TYPE)
if(ANDROID)
# Added the android abi after system name

View File

@@ -275,9 +275,18 @@ Godot headers repository for more information.
#### HTML5
GDNative isn't supported on the HTML5 platform yet. Support is being tracked on
[issue #12243](https://github.com/godotengine/godot/issues/12243) in the main
Godot repository.
GDNative is supported on [specific exports](https://docs.godotengine.org/en/latest/tutorials/export/exporting_for_web.html#export-options) for the HTML5 platform since Godot `3.2.4`. Linking webassembly modules is currently underspecified in the standard, but [emscripten](https://emscripten.org/), which Godot uses to build the HTML5 version, implements its own linking system.
To build GDNative libraries, you will need a recent version of [Emscripten](https://emscripten.org/).
```bash
cd SimpleLibrary
emcc -o bin/libtest.wasm -g -O3 -s SIDE_MODULE=1 src/init.cpp godot-cpp/bin/<name of the godot-cpp> -Igodot-cpp/include -Igodot-cpp/include/core -Igodot-cpp/include/gen -Igodot-cpp/godot-headers
```
You'll need to replace `<name of the godot-cpp>` with the file that was created in [**Compiling the cpp bindings library**](#compiling-the-cpp-bindings-library).
This creates the file `libtest.so` in your `SimpleLibrary/bin` directory.
### Creating `.gdnlib` and `.gdns` files

View File

@@ -58,6 +58,8 @@ def add_sources(sources, dir, extension):
# This is used if no `platform` argument is passed
if sys.platform.startswith('linux'):
host_platform = 'linux'
elif sys.platform.startswith('freebsd'):
host_platform = 'freebsd'
elif sys.platform == 'darwin':
host_platform = 'osx'
elif sys.platform == 'win32' or sys.platform == 'msys':
@@ -84,7 +86,7 @@ opts.Add(EnumVariable(
'platform',
'Target platform',
host_platform,
allowed_values=('linux', 'osx', 'windows', 'android', 'ios'),
allowed_values=('linux', 'freebsd', 'osx', 'windows', 'android', 'ios', 'javascript'),
ignorecase=2
))
opts.Add(EnumVariable(
@@ -95,7 +97,7 @@ opts.Add(EnumVariable(
))
opts.Add(BoolVariable(
'use_llvm',
'Use the LLVM compiler - only effective when targeting Linux',
'Use the LLVM compiler - only effective when targeting Linux or FreeBSD',
False
))
opts.Add(BoolVariable(
@@ -123,10 +125,12 @@ opts.Add(PathVariable(
None,
PathVariable.PathIsFile
))
opts.Add(BoolVariable(
opts.Add(EnumVariable(
'generate_bindings',
'Generate GDNative API bindings',
False
'auto',
allowed_values = ['yes', 'no', 'auto', 'true'],
ignorecase = 2
))
opts.Add(EnumVariable(
'android_arch',
@@ -139,6 +143,17 @@ opts.Add(
'macOS deployment target',
'default'
)
opts.Add(
'macos_sdk_path',
'macOS SDK path',
''
)
opts.Add(EnumVariable(
'macos_arch',
'Target macOS architecture',
'x86_64',
['x86_64', 'arm64']
))
opts.Add(EnumVariable(
'ios_arch',
'Target iOS architecture',
@@ -185,7 +200,7 @@ if host_platform == 'windows' and env['platform'] != 'android':
opts.Update(env)
if env['platform'] == 'linux':
if env['platform'] == 'linux' or env['platform'] == 'freebsd':
if env['use_llvm']:
env['CXX'] = 'clang++'
@@ -213,14 +228,19 @@ elif env['platform'] == 'osx':
'Only 64-bit builds are supported for the macOS target.'
)
env.Append(CCFLAGS=['-std=c++14', '-arch', 'x86_64'])
env.Append(CCFLAGS=['-std=c++14', '-arch', env['macos_arch']])
if env['macos_deployment_target'] != 'default':
env.Append(CCFLAGS=['-mmacosx-version-min=' + env['macos_deployment_target']])
env.Append(LINKFLAGS=['-mmacosx-version-min=' + env['macos_deployment_target']])
if env['macos_sdk_path']:
env.Append(CCFLAGS=['-isysroot', env['macos_sdk_path']])
env.Append(LINKFLAGS=['-isysroot', env['macos_sdk_path']])
env.Append(LINKFLAGS=[
'-arch',
'x86_64',
env['macos_arch'],
'-framework',
'Cocoa',
'-Wl,-undefined,dynamic_lookup',
@@ -278,7 +298,7 @@ elif env['platform'] == 'windows':
elif env['target'] == 'release':
env.Append(CCFLAGS=['/O2', '/EHsc', '/DNDEBUG', '/MD'])
elif host_platform == 'linux' or host_platform == 'osx':
elif host_platform == 'linux' or host_platform == 'freebsd' or host_platform == 'osx':
# Cross-compilation using MinGW
if env['bits'] == '64':
env['CXX'] = 'x86_64-w64-mingw32-g++'
@@ -300,7 +320,7 @@ elif env['platform'] == 'windows':
env["SPAWN"] = mySpawn
# Native or cross-compilation using MinGW
if host_platform == 'linux' or host_platform == 'osx' or env['use_mingw']:
if host_platform == 'linux' or host_platform == 'freebsd' or host_platform == 'osx' or env['use_mingw']:
# These options are for a release build even using target=debug
env.Append(CCFLAGS=['-O3', '-std=c++14', '-Wwrite-strings'])
env.Append(LINKFLAGS=[
@@ -371,6 +391,44 @@ elif env['platform'] == 'android':
env.Append(CCFLAGS=['--target=' + arch_info['target'] + env['android_api_level'], '-march=' + arch_info['march'], '-fPIC'])#, '-fPIE', '-fno-addrsig', '-Oz'])
env.Append(CCFLAGS=arch_info['ccflags'])
if env['target'] == 'debug':
env.Append(CCFLAGS=['-Og', '-g'])
elif env['target'] == 'release':
env.Append(CCFLAGS=['-O3'])
elif env["platform"] == "javascript":
env["ENV"] = os.environ
env["CC"] = "emcc"
env["CXX"] = "em++"
env["AR"] = "emar"
env["RANLIB"] = "emranlib"
env.Append(CPPFLAGS=["-s", "SIDE_MODULE=1"])
env.Append(LINKFLAGS=["-s", "SIDE_MODULE=1"])
env["SHOBJSUFFIX"] = ".bc"
env["SHLIBSUFFIX"] = ".wasm"
# Use TempFileMunge since some AR invocations are too long for cmd.exe.
# Use POSIX-style paths, required with TempFileMunge.
env["ARCOM_POSIX"] = env["ARCOM"].replace("$TARGET", "$TARGET.posix").replace("$SOURCES", "$SOURCES.posix")
env["ARCOM"] = "${TEMPFILE(ARCOM_POSIX)}"
# All intermediate files are just LLVM bitcode.
env["OBJPREFIX"] = ""
env["OBJSUFFIX"] = ".bc"
env["PROGPREFIX"] = ""
# Program() output consists of multiple files, so specify suffixes manually at builder.
env["PROGSUFFIX"] = ""
env["LIBPREFIX"] = "lib"
env["LIBSUFFIX"] = ".a"
env["LIBPREFIXES"] = ["$LIBPREFIX"]
env["LIBSUFFIXES"] = ["$LIBSUFFIX"]
env.Replace(SHLINKFLAGS='$LINKFLAGS')
env.Replace(SHLINKFLAGS='$LINKFLAGS')
if env['target'] == 'debug':
env.Append(CCFLAGS=['-O0', '-g'])
elif env['target'] == 'release':
env.Append(CCFLAGS=['-O3'])
env.Append(CPPPATH=[
'.',
env['headers_dir'],
@@ -387,7 +445,13 @@ if 'custom_api_file' in env:
else:
json_api_file = os.path.join(os.getcwd(), env['headers_dir'], 'api.json')
if env['generate_bindings']:
if env['generate_bindings'] == 'auto':
# Check if generated files exist
should_generate_bindings = not os.path.isfile(os.path.join(os.getcwd(), 'src', 'gen', 'Object.cpp'))
else:
should_generate_bindings = env['generate_bindings'] in ['yes', 'true']
if should_generate_bindings:
# Actually create the bindings here
import binding_generator
@@ -403,6 +467,8 @@ if env['platform'] == 'android':
arch_suffix = env['android_arch']
if env['platform'] == 'ios':
arch_suffix = env['ios_arch']
if env['platform'] == 'javascript':
arch_suffix = 'wasm'
library = env.StaticLibrary(
target='bin/' + 'libgodot-cpp.{}.{}.{}{}'.format(

View File

@@ -1,8 +1,9 @@
#!/usr/bin/env python
from __future__ import print_function
import json
# comment.
import os
import errno
from pathlib import Path
# Convenience function for using template get_node
def correct_method_name(method_list):
@@ -13,15 +14,58 @@ def correct_method_name(method_list):
classes = []
def generate_bindings(path, use_template_get_node):
def print_file_list(api_filepath, output_dir, headers=False, sources=False):
global classes
classes = json.load(open(path))
end = ';'
with open(api_filepath) as api_file:
classes = json.load(api_file)
include_gen_folder = Path(output_dir) / 'include' / 'gen'
source_gen_folder = Path(output_dir) / 'src' / 'gen'
for _class in classes:
header_filename = include_gen_folder / (strip_name(_class["name"]) + ".hpp")
source_filename = source_gen_folder / (strip_name(_class["name"]) + ".cpp")
if headers:
print(str(header_filename.as_posix()), end=end)
if sources:
print(str(source_filename.as_posix()), end=end)
icall_header_filename = include_gen_folder / '__icalls.hpp'
register_types_filename = source_gen_folder / '__register_types.cpp'
init_method_bindings_filename = source_gen_folder / '__init_method_bindings.cpp'
if headers:
print(str(icall_header_filename.as_posix()), end=end)
if sources:
print(str(register_types_filename.as_posix()), end=end)
print(str(init_method_bindings_filename.as_posix()), end=end)
def generate_bindings(api_filepath, use_template_get_node, output_dir="."):
global classes
with open(api_filepath) as api_file:
classes = json.load(api_file)
icalls = set()
include_gen_folder = Path(output_dir) / 'include' / 'gen'
source_gen_folder = Path(output_dir) / 'src' / 'gen'
try:
include_gen_folder.mkdir(parents=True)
except os.error as e:
if e.errno == errno.EEXIST:
print(str(source_gen_folder) + ": " + os.strerror(e.errno))
else:
exit(1)
try:
source_gen_folder.mkdir(parents=True)
except os.error as e:
if e.errno == errno.EEXIST:
print(str(source_gen_folder) + ": " + os.strerror(e.errno))
else:
exit(1)
for c in classes:
# print c['name']
# print(c['name'])
used_classes = get_used_classes(c)
if use_template_get_node and c["name"] == "Node":
correct_method_name(c["methods"])
@@ -30,21 +74,25 @@ def generate_bindings(path, use_template_get_node):
impl = generate_class_implementation(icalls, used_classes, c, use_template_get_node)
header_file = open("include/gen/" + strip_name(c["name"]) + ".hpp", "w+")
header_file.write(header)
header_filename = include_gen_folder / (strip_name(c["name"]) + ".hpp")
with header_filename.open("w+") as header_file:
header_file.write(header)
source_file = open("src/gen/" + strip_name(c["name"]) + ".cpp", "w+")
source_file.write(impl)
source_filename = source_gen_folder / (strip_name(c["name"]) + ".cpp")
with source_filename.open("w+") as source_file:
source_file.write(impl)
icall_header_filename = include_gen_folder / '__icalls.hpp'
with icall_header_filename.open("w+") as icall_header_file:
icall_header_file.write(generate_icall_header(icalls))
icall_header_file = open("include/gen/__icalls.hpp", "w+")
icall_header_file.write(generate_icall_header(icalls))
register_types_filename = source_gen_folder / '__register_types.cpp'
with register_types_filename.open("w+") as register_types_file:
register_types_file.write(generate_type_registry(classes))
register_types_file = open("src/gen/__register_types.cpp", "w+")
register_types_file.write(generate_type_registry(classes))
init_method_bindings_file = open("src/gen/__init_method_bindings.cpp", "w+")
init_method_bindings_file.write(generate_init_method_bindings(classes))
init_method_bindings_filename = source_gen_folder / '__init_method_bindings.cpp'
with init_method_bindings_filename.open("w+") as init_method_bindings_file:
init_method_bindings_file.write(generate_init_method_bindings(classes))
def is_reference_type(t):
@@ -80,7 +128,7 @@ def generate_class_header(used_classes, c, use_template_get_node):
source.append("")
source.append("#include <gdnative_api_struct.gen.h>")
source.append("#include <stdint.h>")
source.append("#include <cstdint>")
source.append("")
@@ -246,7 +294,7 @@ def generate_class_header(used_classes, c, use_template_get_node):
return default_value.lower()
if _type == "Array":
return "Array()"
if _type in ["PoolVector2Array", "PoolStringArray", "PoolVector3Array", "PoolColorArray", "PoolIntArray", "PoolRealArray"]:
if _type in ["PoolVector2Array", "PoolStringArray", "PoolVector3Array", "PoolColorArray", "PoolIntArray", "PoolRealArray", "PoolByteArray"]:
return _type + "()"
if _type == "Vector2":
return "Vector2" + default_value
@@ -833,6 +881,7 @@ def is_primitive(name):
def escape_cpp(name):
escapes = {
"class": "_class",
"enum": "_enum",
"char": "_char",
"short": "_short",
"bool": "_bool",

View File

@@ -16,12 +16,10 @@ public:
real_t get_area() const; /// get area
inline bool has_no_area() const {
return (size.x <= CMP_EPSILON || size.y <= CMP_EPSILON || size.z <= CMP_EPSILON);
}
inline bool has_no_surface() const {
return (size.x <= CMP_EPSILON && size.y <= CMP_EPSILON && size.z <= CMP_EPSILON);
}

View File

@@ -14,7 +14,6 @@ using namespace godot;
} // namespace
struct CameraMatrix {
enum Planes {
PLANE_NEAR,
PLANE_FAR,
@@ -84,7 +83,6 @@ struct CameraMatrix {
};
Vector3 CameraMatrix::xform(const Vector3 &p_vec3) const {
Vector3 ret;
ret.x = matrix[0][0] * p_vec3.x + matrix[1][0] * p_vec3.y + matrix[2][0] * p_vec3.z + matrix[3][0];
ret.y = matrix[0][1] * p_vec3.x + matrix[1][1] * p_vec3.y + matrix[2][1] * p_vec3.z + matrix[3][1];

View File

@@ -11,12 +11,10 @@
namespace godot {
struct Color {
private:
// static float _parse_col(const String& p_str, int p_ofs);
public:
union {
struct {
float r;
float g;

View File

@@ -53,8 +53,6 @@ enum class Error {
ERR_HELP, ///< user requested help!!
ERR_BUG, ///< a bug in the software certainly happened, due to a double check failing or unexpected behavior.
ERR_PRINTER_ON_FIRE, /// the parallel port printer is engulfed in flames
ERR_OMFG_THIS_IS_VERY_VERY_BAD, ///< shit happens, has never been used, though
ERR_WTF = ERR_OMFG_THIS_IS_VERY_VERY_BAD ///< short version of the above
};
} // namespace godot
@@ -208,7 +206,7 @@ typedef float real_t;
do { \
if (unlikely(cond)) { \
FATAL_PRINT(ERR_MSG_COND(cond)); \
return; \
GENERATE_TRAP; \
} \
} while (0)
#endif

View File

@@ -321,7 +321,6 @@ void register_method(const char *name, M method_ptr, godot_method_rpc_mode rpc_t
template <class D, class B, class R, class... As>
void register_method_explicit(const char *name, R (B::*method_ptr)(As...),
godot_method_rpc_mode rpc_type = GODOT_METHOD_RPC_MODE_DISABLED) {
static_assert(std::is_base_of<B, D>::value, "Explicit class must derive from method class");
register_method(name, static_cast<R (D::*)(As...)>(method_ptr), rpc_type);
}
@@ -394,7 +393,6 @@ void register_property(const char *name, P(T::*var), P default_value,
godot_method_rpc_mode rpc_mode = GODOT_METHOD_RPC_MODE_DISABLED,
godot_property_usage_flags usage = GODOT_PROPERTY_USAGE_DEFAULT,
godot_property_hint hint = GODOT_PROPERTY_HINT_NONE, String hint_string = "") {
static_assert(T::___CLASS_IS_SCRIPT, "This function must only be used on custom classes");
Variant def_val = default_value;
@@ -451,7 +449,6 @@ void register_property(const char *name, void (T::*setter)(P), P (T::*getter)(),
godot_method_rpc_mode rpc_mode = GODOT_METHOD_RPC_MODE_DISABLED,
godot_property_usage_flags usage = GODOT_PROPERTY_USAGE_DEFAULT,
godot_property_hint hint = GODOT_PROPERTY_HINT_NONE, String hint_string = "") {
static_assert(T::___CLASS_IS_SCRIPT, "This function must only be used on custom classes");
Variant def_val = default_value;
@@ -495,7 +492,6 @@ void register_property(const char *name, void (T::*setter)(P), P (T::*getter)()
godot_method_rpc_mode rpc_mode = GODOT_METHOD_RPC_MODE_DISABLED,
godot_property_usage_flags usage = GODOT_PROPERTY_USAGE_DEFAULT,
godot_property_hint hint = GODOT_PROPERTY_HINT_NONE, String hint_string = "") {
register_property(name, setter, (P(T::*)())getter, default_value, rpc_mode, usage, hint, hint_string);
}

View File

@@ -23,7 +23,6 @@ extern "C" const godot_gdnative_ext_net_3_2_api_struct *net_3_2_api;
extern "C" const void *gdnlib;
class Godot {
public:
static void print(const String &message);
static void print_warning(const String &description, const String &function, const String &file, int line);

View File

@@ -52,6 +52,27 @@ inline float tan(float p_x) {
return ::tanf(p_x);
}
inline double asin(double p_x) {
return ::asin(p_x);
}
inline float asin(float p_x) {
return ::asinf(p_x);
}
inline double acos(double p_x) {
return ::acos(p_x);
}
inline float acos(float p_x) {
return ::acosf(p_x);
}
inline double atan(double p_x) {
return ::atan(p_x);
}
inline float atan(float p_x) {
return ::atanf(p_x);
}
inline double atan2(double p_y, double p_x) {
return ::atan2(p_y, p_x);
}
@@ -232,7 +253,6 @@ inline double stepify(double p_value, double p_step) {
}
inline unsigned int next_power_of_2(unsigned int x) {
if (x == 0)
return 0;

View File

@@ -26,7 +26,6 @@ class PoolByteArray {
public:
class Read {
friend class PoolByteArray;
godot_pool_byte_array_read_access *_read_access;

View File

@@ -17,7 +17,6 @@ typedef Vector2 Point2;
struct Transform2D;
struct Rect2 {
Point2 position;
Size2 size;
@@ -48,14 +47,12 @@ struct Rect2 {
bool intersects_segment(const Point2 &p_from, const Point2 &p_to, Point2 *r_position = nullptr, Point2 *r_normal = nullptr) const;
inline bool encloses(const Rect2 &p_rect) const {
return (p_rect.position.x >= position.x) && (p_rect.position.y >= position.y) &&
((p_rect.position.x + p_rect.size.x) < (position.x + size.x)) &&
((p_rect.position.y + p_rect.size.y) < (position.y + size.y));
}
inline bool has_no_area() const {
return (size.x <= 0 || size.y <= 0);
}
Rect2 clip(const Rect2 &p_rect) const;
@@ -82,7 +79,6 @@ struct Rect2 {
inline bool operator!=(const Rect2 &p_rect) const { return position != p_rect.position || size != p_rect.size; }
inline Rect2 grow(real_t p_by) const {
Rect2 g = *this;
g.position.x -= p_by;
g.position.y -= p_by;
@@ -92,7 +88,6 @@ struct Rect2 {
}
inline Rect2 expand(const Vector2 &p_vector) const {
Rect2 r = *this;
r.expand_to(p_vector);
return r;

View File

@@ -19,7 +19,6 @@ class Ref {
T *reference = nullptr;
void ref(const Ref &p_from) {
if (p_from.reference == reference)
return;
@@ -31,7 +30,6 @@ class Ref {
}
void ref_pointer(T *p_ref) {
ERR_FAIL_COND(p_ref == nullptr);
if (p_ref->init_ref())
@@ -40,44 +38,35 @@ class Ref {
public:
inline bool operator<(const Ref<T> &p_r) const {
return reference < p_r.reference;
}
inline bool operator==(const Ref<T> &p_r) const {
return reference == p_r.reference;
}
inline bool operator!=(const Ref<T> &p_r) const {
return reference != p_r.reference;
}
inline T *operator->() {
return reference;
}
inline T *operator*() {
return reference;
}
inline const T *operator->() const {
return reference;
}
inline const T *ptr() const {
return reference;
}
inline T *ptr() {
return reference;
}
inline const T *operator*() const {
return reference;
}
@@ -88,7 +77,6 @@ public:
}
void operator=(const Ref &p_from) {
ref(p_from);
}
@@ -118,7 +106,6 @@ public:
}
Ref(const Ref &p_from) {
reference = nullptr;
ref(p_from);
}
@@ -138,7 +125,6 @@ public:
}
Ref(T *p_reference) {
if (p_reference)
ref_pointer(p_reference);
else
@@ -146,7 +132,6 @@ public:
}
Ref(const Variant &p_variant) {
reference = nullptr;
Object *refb = T::___get_from_variant(p_variant);
if (refb == nullptr) {
@@ -168,7 +153,6 @@ public:
// mutexes will avoid more crashes?
if (reference && reference->unreference()) {
//memdelete(reference);
reference->free();
}
@@ -181,12 +165,10 @@ public:
}
Ref() {
reference = nullptr;
}
~Ref() {
unref();
}

View File

@@ -14,7 +14,6 @@ class PoolStringArray;
class String;
class CharString {
friend class String;
godot_char_string _char_string;
@@ -41,6 +40,7 @@ public:
String(const wchar_t *contents);
String(const wchar_t c);
String(const String &other);
String(String &&other);
~String();
@@ -56,6 +56,7 @@ public:
wchar_t operator[](const int idx) const;
void operator=(const String &s);
void operator=(String &&s);
bool operator==(const String &s) const;
bool operator!=(const String &s) const;
String operator+(const String &s) const;

View File

@@ -14,7 +14,6 @@ namespace godot {
class Basis;
struct Vector3 {
enum Axis {
AXIS_X,
AXIS_Y,
@@ -305,7 +304,6 @@ inline Vector3 operator*(real_t p_scalar, const Vector3 &p_vec) {
}
inline Vector3 vec3_cross(const Vector3 &p_a, const Vector3 &p_b) {
return p_a.cross(p_b);
}

4
misc/ci/sources.list Normal file
View File

@@ -0,0 +1,4 @@
deb http://archive.ubuntu.com/ubuntu/ focal main restricted universe multiverse
deb http://archive.ubuntu.com/ubuntu/ focal-updates main restricted universe multiverse
deb http://archive.ubuntu.com/ubuntu/ focal-security main restricted universe multiverse
deb http://archive.ubuntu.com/ubuntu/ focal-backports main restricted universe multiverse

View File

@@ -7,7 +7,6 @@
namespace godot {
bool AABB::intersects(const AABB &p_aabb) const {
if (position.x >= (p_aabb.position.x + p_aabb.size.x))
return false;
if ((position.x + size.x) <= p_aabb.position.x)
@@ -25,7 +24,6 @@ bool AABB::intersects(const AABB &p_aabb) const {
}
bool AABB::intersects_inclusive(const AABB &p_aabb) const {
if (position.x > (p_aabb.position.x + p_aabb.size.x))
return false;
if ((position.x + size.x) < p_aabb.position.x)
@@ -43,7 +41,6 @@ bool AABB::intersects_inclusive(const AABB &p_aabb) const {
}
bool AABB::encloses(const AABB &p_aabb) const {
Vector3 src_min = position;
Vector3 src_max = position + size;
Vector3 dst_min = p_aabb.position;
@@ -59,7 +56,6 @@ bool AABB::encloses(const AABB &p_aabb) const {
}
Vector3 AABB::get_support(const Vector3 &p_normal) const {
Vector3 half_extents = size * 0.5;
Vector3 ofs = position + half_extents;
@@ -71,23 +67,29 @@ Vector3 AABB::get_support(const Vector3 &p_normal) const {
}
Vector3 AABB::get_endpoint(int p_point) const {
switch (p_point) {
case 0: return Vector3(position.x, position.y, position.z);
case 1: return Vector3(position.x, position.y, position.z + size.z);
case 2: return Vector3(position.x, position.y + size.y, position.z);
case 3: return Vector3(position.x, position.y + size.y, position.z + size.z);
case 4: return Vector3(position.x + size.x, position.y, position.z);
case 5: return Vector3(position.x + size.x, position.y, position.z + size.z);
case 6: return Vector3(position.x + size.x, position.y + size.y, position.z);
case 7: return Vector3(position.x + size.x, position.y + size.y, position.z + size.z);
case 0:
return Vector3(position.x, position.y, position.z);
case 1:
return Vector3(position.x, position.y, position.z + size.z);
case 2:
return Vector3(position.x, position.y + size.y, position.z);
case 3:
return Vector3(position.x, position.y + size.y, position.z + size.z);
case 4:
return Vector3(position.x + size.x, position.y, position.z);
case 5:
return Vector3(position.x + size.x, position.y, position.z + size.z);
case 6:
return Vector3(position.x + size.x, position.y + size.y, position.z);
case 7:
return Vector3(position.x + size.x, position.y + size.y, position.z + size.z);
};
ERR_FAIL_V(Vector3());
}
bool AABB::intersects_convex_shape(const Plane *p_planes, int p_plane_count) const {
Vector3 half_extents = size * 0.5;
Vector3 ofs = position + half_extents;
@@ -106,7 +108,6 @@ bool AABB::intersects_convex_shape(const Plane *p_planes, int p_plane_count) con
}
bool AABB::has_point(const Vector3 &p_point) const {
if (p_point.x < position.x)
return false;
if (p_point.y < position.y)
@@ -124,7 +125,6 @@ bool AABB::has_point(const Vector3 &p_point) const {
}
void AABB::expand_to(const Vector3 &p_vector) {
Vector3 begin = position;
Vector3 end = position + size;
@@ -147,7 +147,6 @@ void AABB::expand_to(const Vector3 &p_vector) {
}
void AABB::project_range_in_plane(const Plane &p_plane, real_t &r_min, real_t &r_max) const {
Vector3 half_extents(size.x * 0.5, size.y * 0.5, size.z * 0.5);
Vector3 center(position.x + half_extents.x, position.y + half_extents.y, position.z + half_extents.z);
@@ -158,7 +157,6 @@ void AABB::project_range_in_plane(const Plane &p_plane, real_t &r_min, real_t &r
}
real_t AABB::get_longest_axis_size() const {
real_t max_size = size.x;
if (size.y > max_size) {
@@ -173,7 +171,6 @@ real_t AABB::get_longest_axis_size() const {
}
real_t AABB::get_shortest_axis_size() const {
real_t max_size = size.x;
if (size.y < max_size) {
@@ -188,7 +185,6 @@ real_t AABB::get_shortest_axis_size() const {
}
bool AABB::smits_intersect_ray(const Vector3 &from, const Vector3 &dir, real_t t0, real_t t1) const {
real_t divx = 1.0 / dir.x;
real_t divy = 1.0 / dir.y;
real_t divz = 1.0 / dir.z;
@@ -232,7 +228,6 @@ bool AABB::smits_intersect_ray(const Vector3 &from, const Vector3 &dir, real_t t
}
void AABB::grow_by(real_t p_amount) {
position.x -= p_amount;
position.y -= p_amount;
position.z -= p_amount;
@@ -242,21 +237,17 @@ void AABB::grow_by(real_t p_amount) {
}
real_t AABB::get_area() const {
return size.x * size.y * size.z;
}
bool AABB::operator==(const AABB &p_rval) const {
return ((position == p_rval.position) && (size == p_rval.size));
}
bool AABB::operator!=(const AABB &p_rval) const {
return ((position != p_rval.position) || (size != p_rval.size));
}
void AABB::merge_with(const AABB &p_aabb) {
Vector3 beg_1, beg_2;
Vector3 end_1, end_2;
Vector3 min, max;
@@ -279,7 +270,6 @@ void AABB::merge_with(const AABB &p_aabb) {
}
AABB AABB::intersection(const AABB &p_aabb) const {
Vector3 src_min = position;
Vector3 src_max = position + size;
Vector3 dst_min = p_aabb.position;
@@ -290,7 +280,6 @@ AABB AABB::intersection(const AABB &p_aabb) const {
if (src_min.x > dst_max.x || src_max.x < dst_min.x)
return AABB();
else {
min.x = (src_min.x > dst_min.x) ? src_min.x : dst_min.x;
max.x = (src_max.x < dst_max.x) ? src_max.x : dst_max.x;
}
@@ -298,7 +287,6 @@ AABB AABB::intersection(const AABB &p_aabb) const {
if (src_min.y > dst_max.y || src_max.y < dst_min.y)
return AABB();
else {
min.y = (src_min.y > dst_min.y) ? src_min.y : dst_min.y;
max.y = (src_max.y < dst_max.y) ? src_max.y : dst_max.y;
}
@@ -306,7 +294,6 @@ AABB AABB::intersection(const AABB &p_aabb) const {
if (src_min.z > dst_max.z || src_max.z < dst_min.z)
return AABB();
else {
min.z = (src_min.z > dst_min.z) ? src_min.z : dst_min.z;
max.z = (src_max.z < dst_max.z) ? src_max.z : dst_max.z;
}
@@ -315,7 +302,6 @@ AABB AABB::intersection(const AABB &p_aabb) const {
}
bool AABB::intersects_ray(const Vector3 &p_from, const Vector3 &p_dir, Vector3 *r_clip, Vector3 *r_normal) const {
Vector3 c1, c2;
Vector3 end = position + size;
real_t near = -1e20;
@@ -358,7 +344,6 @@ bool AABB::intersects_ray(const Vector3 &p_from, const Vector3 &p_dir, Vector3 *
}
bool AABB::intersects_segment(const Vector3 &p_from, const Vector3 &p_to, Vector3 *r_clip, Vector3 *r_normal) const {
real_t min = 0, max = 1;
int axis = 0;
real_t sign = 0;
@@ -372,7 +357,6 @@ bool AABB::intersects_segment(const Vector3 &p_from, const Vector3 &p_to, Vector
real_t csign;
if (seg_from < seg_to) {
if (seg_from > box_end || seg_to < box_begin)
return false;
real_t length = seg_to - seg_from;
@@ -381,7 +365,6 @@ bool AABB::intersects_segment(const Vector3 &p_from, const Vector3 &p_to, Vector
csign = -1.0;
} else {
if (seg_to > box_end || seg_from < box_begin)
return false;
real_t length = seg_to - seg_from;
@@ -416,7 +399,6 @@ bool AABB::intersects_segment(const Vector3 &p_from, const Vector3 &p_to, Vector
}
bool AABB::intersects_plane(const Plane &p_plane) const {
Vector3 points[8] = {
Vector3(position.x, position.y, position.z),
Vector3(position.x, position.y, position.z + size.z),
@@ -432,7 +414,6 @@ bool AABB::intersects_plane(const Plane &p_plane) const {
bool under = false;
for (int i = 0; i < 8; i++) {
if (p_plane.distance_to(points[i]) > 0)
over = true;
else
@@ -443,7 +424,6 @@ bool AABB::intersects_plane(const Plane &p_plane) const {
}
Vector3 AABB::get_longest_axis() const {
Vector3 axis(1, 0, 0);
real_t max_size = size.x;
@@ -460,7 +440,6 @@ Vector3 AABB::get_longest_axis() const {
return axis;
}
int AABB::get_longest_axis_index() const {
int axis = 0;
real_t max_size = size.x;
@@ -478,7 +457,6 @@ int AABB::get_longest_axis_index() const {
}
Vector3 AABB::get_shortest_axis() const {
Vector3 axis(1, 0, 0);
real_t max_size = size.x;
@@ -495,7 +473,6 @@ Vector3 AABB::get_shortest_axis() const {
return axis;
}
int AABB::get_shortest_axis_index() const {
int axis = 0;
real_t max_size = size.x;
@@ -513,7 +490,6 @@ int AABB::get_shortest_axis_index() const {
}
AABB AABB::merge(const AABB &p_with) const {
AABB aabb = *this;
aabb.merge_with(p_with);
return aabb;
@@ -524,24 +500,19 @@ AABB AABB::expand(const Vector3 &p_vector) const {
return aabb;
}
AABB AABB::grow(real_t p_by) const {
AABB aabb = *this;
aabb.grow_by(p_by);
return aabb;
}
void AABB::get_edge(int p_edge, Vector3 &r_from, Vector3 &r_to) const {
ERR_FAIL_INDEX(p_edge, 12);
switch (p_edge) {
case 0: {
r_from = Vector3(position.x + size.x, position.y, position.z);
r_to = Vector3(position.x, position.y, position.z);
} break;
case 1: {
r_from = Vector3(position.x + size.x, position.y, position.z + size.z);
r_to = Vector3(position.x + size.x, position.y, position.z);
} break;
@@ -551,18 +522,15 @@ void AABB::get_edge(int p_edge, Vector3 &r_from, Vector3 &r_to) const {
} break;
case 3: {
r_from = Vector3(position.x, position.y, position.z);
r_to = Vector3(position.x, position.y, position.z + size.z);
} break;
case 4: {
r_from = Vector3(position.x, position.y + size.y, position.z);
r_to = Vector3(position.x + size.x, position.y + size.y, position.z);
} break;
case 5: {
r_from = Vector3(position.x + size.x, position.y + size.y, position.z);
r_to = Vector3(position.x + size.x, position.y + size.y, position.z + size.z);
} break;
@@ -572,31 +540,26 @@ void AABB::get_edge(int p_edge, Vector3 &r_from, Vector3 &r_to) const {
} break;
case 7: {
r_from = Vector3(position.x, position.y + size.y, position.z + size.z);
r_to = Vector3(position.x, position.y + size.y, position.z);
} break;
case 8: {
r_from = Vector3(position.x, position.y, position.z + size.z);
r_to = Vector3(position.x, position.y + size.y, position.z + size.z);
} break;
case 9: {
r_from = Vector3(position.x, position.y, position.z);
r_to = Vector3(position.x, position.y + size.y, position.z);
} break;
case 10: {
r_from = Vector3(position.x + size.x, position.y, position.z);
r_to = Vector3(position.x + size.x, position.y + size.y, position.z);
} break;
case 11: {
r_from = Vector3(position.x + size.x, position.y, position.z + size.z);
r_to = Vector3(position.x + size.x, position.y + size.y, position.z + size.z);
@@ -605,7 +568,6 @@ void AABB::get_edge(int p_edge, Vector3 &r_from, Vector3 &r_to) const {
}
AABB::operator String() const {
return String() + position + " - " + size;
}

View File

@@ -19,12 +19,10 @@ Basis::Basis(const Vector3 &row0, const Vector3 &row1, const Vector3 &row2) {
}
Basis::Basis(real_t xx, real_t xy, real_t xz, real_t yx, real_t yy, real_t yz, real_t zx, real_t zy, real_t zz) {
set(xx, xy, xz, yx, yy, yz, zx, zy, zz);
}
Basis::Basis() {
elements[0][0] = 1;
elements[0][1] = 0;
elements[0][2] = 0;
@@ -58,7 +56,6 @@ void Basis::invert() {
#undef cofac
bool Basis::isequal_approx(const Basis &a, const Basis &b) const {
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
if ((::fabs(a.elements[i][j] - b.elements[i][j]) < CMP_EPSILON) == false)
@@ -174,7 +171,6 @@ Basis Basis::slerp(Basis b, float t) const {
// the angles in the decomposition R = X(a1).Y(a2).Z(a3) where Z(a) rotates
// around the z-axis by a and so on.
Vector3 Basis::get_euler_xyz() const {
// Euler angles in XYZ convention.
// See https://en.wikipedia.org/wiki/Euler_angles#Rotation_matrix
//
@@ -218,7 +214,6 @@ Vector3 Basis::get_euler_xyz() const {
// and similar for other axes.
// The current implementation uses XYZ convention (Z is the first rotation).
void Basis::set_euler_xyz(const Vector3 &p_euler) {
real_t c, s;
c = ::cos(p_euler.x);
@@ -241,7 +236,6 @@ void Basis::set_euler_xyz(const Vector3 &p_euler) {
// as in first-Z, then-X, last-Y. The angles for X, Y, and Z rotations are returned
// as the x, y, and z components of a Vector3 respectively.
Vector3 Basis::get_euler_yxz() const {
// Euler angles in YXZ convention.
// See https://en.wikipedia.org/wiki/Euler_angles#Rotation_matrix
//
@@ -287,7 +281,6 @@ Vector3 Basis::get_euler_yxz() const {
// and similar for other axes.
// The current implementation uses YXZ convention (Z is the first rotation).
void Basis::set_euler_yxz(const Vector3 &p_euler) {
real_t c, s;
c = ::cos(p_euler.x);
@@ -333,7 +326,6 @@ bool Basis::operator!=(const Basis &p_matrix) const {
}
Vector3 Basis::xform(const Vector3 &p_vector) const {
return Vector3(
elements[0].dot(p_vector),
elements[1].dot(p_vector),
@@ -341,7 +333,6 @@ Vector3 Basis::xform(const Vector3 &p_vector) const {
}
Vector3 Basis::xform_inv(const Vector3 &p_vector) const {
return Vector3(
(elements[0][0] * p_vector.x) + (elements[1][0] * p_vector.y) + (elements[2][0] * p_vector.z),
(elements[0][1] * p_vector.x) + (elements[1][1] * p_vector.y) + (elements[2][1] * p_vector.z),
@@ -362,42 +353,36 @@ Basis Basis::operator*(const Basis &p_matrix) const {
}
void Basis::operator+=(const Basis &p_matrix) {
elements[0] += p_matrix.elements[0];
elements[1] += p_matrix.elements[1];
elements[2] += p_matrix.elements[2];
}
Basis Basis::operator+(const Basis &p_matrix) const {
Basis ret(*this);
ret += p_matrix;
return ret;
}
void Basis::operator-=(const Basis &p_matrix) {
elements[0] -= p_matrix.elements[0];
elements[1] -= p_matrix.elements[1];
elements[2] -= p_matrix.elements[2];
}
Basis Basis::operator-(const Basis &p_matrix) const {
Basis ret(*this);
ret -= p_matrix;
return ret;
}
void Basis::operator*=(real_t p_val) {
elements[0] *= p_val;
elements[1] *= p_val;
elements[2] *= p_val;
}
Basis Basis::operator*(real_t p_val) const {
Basis ret(*this);
ret *= p_val;
return ret;
@@ -406,9 +391,7 @@ Basis Basis::operator*(real_t p_val) const {
Basis::operator String() const {
String s;
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
if (i != 0 || j != 0)
s += ", ";
@@ -421,7 +404,6 @@ Basis::operator String() const {
/* create / set */
void Basis::set(real_t xx, real_t xy, real_t xz, real_t yx, real_t yy, real_t yz, real_t zx, real_t zy, real_t zz) {
elements[0][0] = xx;
elements[0][1] = xy;
elements[0][2] = xz;
@@ -433,12 +415,10 @@ void Basis::set(real_t xx, real_t xy, real_t xz, real_t yx, real_t yy, real_t yz
elements[2][2] = zz;
}
Vector3 Basis::get_column(int i) const {
return Vector3(elements[0][i], elements[1][i], elements[2][i]);
}
Vector3 Basis::get_row(int i) const {
return Vector3(elements[i][0], elements[i][1], elements[i][2]);
}
Vector3 Basis::get_main_diagonal() const {
@@ -593,7 +573,6 @@ int Basis::get_orthogonal_index() const {
Basis orth = *this;
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
real_t v = orth[i][j];
if (v > 0.5)
v = 1.0;
@@ -607,7 +586,6 @@ int Basis::get_orthogonal_index() const {
}
for (int i = 0; i < 24; i++) {
if (_ortho_bases[i] == orth)
return i;
}
@@ -616,7 +594,6 @@ int Basis::get_orthogonal_index() const {
}
void Basis::set_orthogonal_index(int p_index) {
//there only exist 24 orthogonal bases in r3
ERR_FAIL_COND(p_index >= 24);
@@ -624,7 +601,6 @@ void Basis::set_orthogonal_index(int p_index) {
}
Basis::Basis(const Vector3 &p_euler) {
set_euler(p_euler);
}
@@ -635,7 +611,6 @@ Basis::Basis(const Vector3 &p_euler) {
namespace godot {
Basis::Basis(const Quat &p_quat) {
real_t d = p_quat.length_squared();
real_t s = 2.0 / d;
real_t xs = p_quat.x * s, ys = p_quat.y * s, zs = p_quat.z * s;
@@ -685,8 +660,8 @@ Basis::operator Quat() const {
temp[2] = ((elements[1][0] - elements[0][1]) * s);
} else {
int i = elements[0][0] < elements[1][1] ?
(elements[1][1] < elements[2][2] ? 2 : 1) :
(elements[0][0] < elements[2][2] ? 2 : 0);
(elements[1][1] < elements[2][2] ? 2 : 1) :
(elements[0][0] < elements[2][2] ? 2 : 0);
int j = (i + 1) % 3;
int k = (i + 2) % 3;

View File

@@ -31,29 +31,22 @@
#include "CameraMatrix.hpp"
void CameraMatrix::set_identity() {
for (int i = 0; i < 4; i++) {
for (int j = 0; j < 4; j++) {
matrix[i][j] = (i == j) ? 1 : 0;
}
}
}
void CameraMatrix::set_zero() {
for (int i = 0; i < 4; i++) {
for (int j = 0; j < 4; j++) {
matrix[i][j] = 0;
}
}
}
Plane CameraMatrix::xform4(const Plane &p_vec4) const {
Plane ret;
ret.normal.x = matrix[0][0] * p_vec4.normal.x + matrix[1][0] * p_vec4.normal.y + matrix[2][0] * p_vec4.normal.z + matrix[3][0] * p_vec4.d;
@@ -64,7 +57,6 @@ Plane CameraMatrix::xform4(const Plane &p_vec4) const {
}
void CameraMatrix::set_perspective(real_t p_fovy_degrees, real_t p_aspect, real_t p_z_near, real_t p_z_far, bool p_flip_fov) {
if (p_flip_fov) {
p_fovy_degrees = get_fovy(p_fovy_degrees, 1.0 / p_aspect);
}
@@ -157,7 +149,6 @@ void CameraMatrix::set_for_hmd(int p_eye, real_t p_aspect, real_t p_intraocular_
};
void CameraMatrix::set_orthogonal(real_t p_left, real_t p_right, real_t p_bottom, real_t p_top, real_t p_znear, real_t p_zfar) {
set_identity();
matrix[0][0] = 2.0 / (p_right - p_left);
@@ -170,7 +161,6 @@ void CameraMatrix::set_orthogonal(real_t p_left, real_t p_right, real_t p_bottom
}
void CameraMatrix::set_orthogonal(real_t p_size, real_t p_aspect, real_t p_znear, real_t p_zfar, bool p_flip_fov) {
if (!p_flip_fov) {
p_size *= p_aspect;
}
@@ -179,7 +169,6 @@ void CameraMatrix::set_orthogonal(real_t p_size, real_t p_aspect, real_t p_znear
}
void CameraMatrix::set_frustum(real_t p_left, real_t p_right, real_t p_bottom, real_t p_top, real_t p_near, real_t p_far) {
ERR_FAIL_COND(p_right <= p_left);
ERR_FAIL_COND(p_top <= p_bottom);
ERR_FAIL_COND(p_far <= p_near);
@@ -220,7 +209,6 @@ void CameraMatrix::set_frustum(real_t p_size, real_t p_aspect, Vector2 p_offset,
}
real_t CameraMatrix::get_z_far() const {
const real_t *matrix = (const real_t *)this->matrix;
Plane new_plane = Plane(matrix[3] - matrix[2],
matrix[7] - matrix[6],
@@ -233,7 +221,6 @@ real_t CameraMatrix::get_z_far() const {
return new_plane.d;
}
real_t CameraMatrix::get_z_near() const {
const real_t *matrix = (const real_t *)this->matrix;
Plane new_plane = Plane(matrix[3] + matrix[2],
matrix[7] + matrix[6],
@@ -245,7 +232,6 @@ real_t CameraMatrix::get_z_near() const {
}
Vector2 CameraMatrix::get_viewport_half_extents() const {
const real_t *matrix = (const real_t *)this->matrix;
///////--- Near Plane ---///////
Plane near_plane = Plane(matrix[3] + matrix[2],
@@ -274,7 +260,6 @@ Vector2 CameraMatrix::get_viewport_half_extents() const {
}
bool CameraMatrix::get_endpoints(const Transform &p_transform, Vector3 *p_8points) const {
std::vector<Plane> planes = get_projection_planes(Transform());
const Planes intersections[8][3] = {
{ PLANE_FAR, PLANE_LEFT, PLANE_TOP },
@@ -288,7 +273,6 @@ bool CameraMatrix::get_endpoints(const Transform &p_transform, Vector3 *p_8point
};
for (int i = 0; i < 8; i++) {
Vector3 point;
bool res = planes[intersections[i][0]].intersect_3(planes[intersections[i][1]], planes[intersections[i][2]], &point);
ERR_FAIL_COND_V(!res, false);
@@ -299,7 +283,6 @@ bool CameraMatrix::get_endpoints(const Transform &p_transform, Vector3 *p_8point
}
std::vector<Plane> CameraMatrix::get_projection_planes(const Transform &p_transform) const {
/** Fast Plane Extraction from combined modelview/projection matrices.
* References:
* https://web.archive.org/web/20011221205252/http://www.markmorley.com/opengl/frustumculling.html
@@ -382,14 +365,12 @@ std::vector<Plane> CameraMatrix::get_projection_planes(const Transform &p_transf
}
CameraMatrix CameraMatrix::inverse() const {
CameraMatrix cm = *this;
cm.invert();
return cm;
}
void CameraMatrix::invert() {
int i, j, k;
int pvt_i[4], pvt_j[4]; /* Locations of pivot matrix */
real_t pvt_val; /* Value of current pivot element */
@@ -440,20 +421,23 @@ void CameraMatrix::invert() {
/** Divide column by minus pivot value **/
for (i = 0; i < 4; i++) {
if (i != k) matrix[i][k] /= (-pvt_val);
if (i != k)
matrix[i][k] /= (-pvt_val);
}
/** Reduce the matrix **/
for (i = 0; i < 4; i++) {
hold = matrix[i][k];
for (j = 0; j < 4; j++) {
if (i != k && j != k) matrix[i][j] += hold * matrix[k][j];
if (i != k && j != k)
matrix[i][j] += hold * matrix[k][j];
}
}
/** Divide row by pivot **/
for (j = 0; j < 4; j++) {
if (j != k) matrix[k][j] /= pvt_val;
if (j != k)
matrix[k][j] /= pvt_val;
}
/** Replace pivot by reciprocal (at last we can touch it). **/
@@ -483,12 +467,10 @@ void CameraMatrix::invert() {
}
CameraMatrix::CameraMatrix() {
set_identity();
}
CameraMatrix CameraMatrix::operator*(const CameraMatrix &p_matrix) const {
CameraMatrix new_matrix;
for (int j = 0; j < 4; j++) {
@@ -504,7 +486,6 @@ CameraMatrix CameraMatrix::operator*(const CameraMatrix &p_matrix) const {
}
void CameraMatrix::set_light_bias() {
real_t *m = &matrix[0][0];
m[0] = 0.5;
@@ -526,7 +507,6 @@ void CameraMatrix::set_light_bias() {
}
void CameraMatrix::set_light_atlas_rect(const Rect2 &p_rect) {
real_t *m = &matrix[0][0];
m[0] = p_rect.size.width;
@@ -548,7 +528,6 @@ void CameraMatrix::set_light_atlas_rect(const Rect2 &p_rect) {
}
CameraMatrix::operator String() const {
String str;
for (int i = 0; i < 4; i++)
for (int j = 0; j < 4; j++)
@@ -558,20 +537,17 @@ CameraMatrix::operator String() const {
}
real_t CameraMatrix::get_aspect() const {
Vector2 vp_he = get_viewport_half_extents();
return vp_he.x / vp_he.y;
}
int CameraMatrix::get_pixels_per_meter(int p_for_pixel_width) const {
Vector3 result = xform(Vector3(1, 0, -1));
return int((result.x * 0.5 + 0.5) * p_for_pixel_width);
}
bool CameraMatrix::is_orthogonal() const {
return matrix[3][3] == 1.0;
}
@@ -599,7 +575,6 @@ real_t CameraMatrix::get_fov() const {
}
void CameraMatrix::make_scale(const Vector3 &p_scale) {
set_identity();
matrix[0][0] = p_scale.x;
matrix[1][1] = p_scale.y;
@@ -607,7 +582,6 @@ void CameraMatrix::make_scale(const Vector3 &p_scale) {
}
void CameraMatrix::scale_translate_to_fit(const AABB &p_aabb) {
Vector3 min = p_aabb.position;
Vector3 max = p_aabb.position + p_aabb.size;
@@ -633,7 +607,6 @@ void CameraMatrix::scale_translate_to_fit(const AABB &p_aabb) {
}
CameraMatrix::operator Transform() const {
Transform tr;
const real_t *m = &matrix[0][0];
@@ -657,7 +630,6 @@ CameraMatrix::operator Transform() const {
}
CameraMatrix::CameraMatrix(const Transform &p_transform) {
const Transform &tr = p_transform;
real_t *m = &matrix[0][0];

View File

@@ -13,11 +13,9 @@ namespace godot {
static String _to_hex(float p_val);
static float _parse_col(const String &p_str, int p_ofs) {
int ig = 0;
for (int i = 0; i < 2; i++) {
int c = (int)(wchar_t)p_str[i + p_ofs];
int v = 0;
@@ -43,7 +41,6 @@ static float _parse_col(const String &p_str, int p_ofs) {
}
uint32_t Color::to_32() const {
uint32_t c = (uint8_t)(a * 255);
c <<= 8;
c |= (uint8_t)(r * 255);
@@ -148,7 +145,6 @@ uint8_t Color::get_a8() const {
}
float Color::get_h() const {
float min = MIN(r, g);
min = MIN(min, b);
float max = MAX(r, g);
@@ -334,7 +330,6 @@ Color Color::contrasted() const {
}
Color Color::linear_interpolate(const Color &p_b, float p_t) const {
Color res = *this;
res.r += (p_t * (p_b.r - r));
@@ -346,7 +341,6 @@ Color Color::linear_interpolate(const Color &p_b, float p_t) const {
}
Color Color::blend(const Color &p_over) const {
Color res;
float sa = 1.0 - p_over.a;
res.a = a * sa + p_over.a;
@@ -361,7 +355,6 @@ Color Color::blend(const Color &p_over) const {
}
Color Color::to_linear() const {
return Color(
r < 0.04045 ? r * (1.0 / 12.92) : ::pow((r + 0.055) * (1.0 / (1 + 0.055)), 2.4),
g < 0.04045 ? g * (1.0 / 12.92) : ::pow((g + 0.055) * (1.0 / (1 + 0.055)), 2.4),
@@ -477,13 +470,11 @@ bool Color::html_is_valid(const String &p_color) {
#define CLAMP(m_a, m_min, m_max) (((m_a) < (m_min)) ? (m_min) : (((m_a) > (m_max)) ? m_max : m_a))
#endif
static String _to_hex(float p_val) {
int v = p_val * 255;
v = CLAMP(v, 0, 255);
String ret;
for (int i = 0; i < 2; i++) {
wchar_t c[2] = { 0, 0 };
int lv = v & 0xF;
if (lv < 10)
@@ -514,7 +505,6 @@ Color::operator String() const {
}
bool Color::operator<(const Color &p_color) const {
if (r == p_color.r) {
if (g == p_color.g) {
if (b == p_color.b) {
@@ -528,7 +518,6 @@ bool Color::operator<(const Color &p_color) const {
}
Color Color::operator+(const Color &p_color) const {
return Color(
r + p_color.r,
g + p_color.g,
@@ -537,7 +526,6 @@ Color Color::operator+(const Color &p_color) const {
}
void Color::operator+=(const Color &p_color) {
r = r + p_color.r;
g = g + p_color.g;
b = b + p_color.b;
@@ -545,7 +533,6 @@ void Color::operator+=(const Color &p_color) {
}
Color Color::operator-(const Color &p_color) const {
return Color(
r - p_color.r,
g - p_color.g,
@@ -554,7 +541,6 @@ Color Color::operator-(const Color &p_color) const {
}
void Color::operator-=(const Color &p_color) {
r = r - p_color.r;
g = g - p_color.g;
b = b - p_color.b;
@@ -562,7 +548,6 @@ void Color::operator-=(const Color &p_color) {
}
Color Color::operator*(const Color &p_color) const {
return Color(
r * p_color.r,
g * p_color.g,
@@ -571,7 +556,6 @@ Color Color::operator*(const Color &p_color) const {
}
Color Color::operator*(const real_t &rvalue) const {
return Color(
r * rvalue,
g * rvalue,
@@ -580,7 +564,6 @@ Color Color::operator*(const real_t &rvalue) const {
}
void Color::operator*=(const Color &p_color) {
r = r * p_color.r;
g = g * p_color.g;
b = b * p_color.b;
@@ -588,7 +571,6 @@ void Color::operator*=(const Color &p_color) {
}
void Color::operator*=(const real_t &rvalue) {
r = r * rvalue;
g = g * rvalue;
b = b * rvalue;
@@ -596,7 +578,6 @@ void Color::operator*=(const real_t &rvalue) {
}
Color Color::operator/(const Color &p_color) const {
return Color(
r / p_color.r,
g / p_color.g,
@@ -605,7 +586,6 @@ Color Color::operator/(const Color &p_color) const {
}
Color Color::operator/(const real_t &rvalue) const {
return Color(
r / rvalue,
g / rvalue,
@@ -614,7 +594,6 @@ Color Color::operator/(const real_t &rvalue) const {
}
void Color::operator/=(const Color &p_color) {
r = r / p_color.r;
g = g / p_color.g;
b = b / p_color.b;
@@ -622,7 +601,6 @@ void Color::operator/=(const Color &p_color) {
}
void Color::operator/=(const real_t &rvalue) {
if (rvalue == 0) {
r = 1.0;
g = 1.0;
@@ -637,7 +615,6 @@ void Color::operator/=(const real_t &rvalue) {
}
Color Color::operator-() const {
return Color(
1.0 - r,
1.0 - g,

View File

@@ -55,9 +55,12 @@ void Godot::print_warning(const String &description, const String &function, con
godot::api->godot_print_warning(c_desc, c_func, c_file, line);
};
if (c_desc != nullptr) godot::api->godot_free(c_desc);
if (c_func != nullptr) godot::api->godot_free(c_func);
if (c_file != nullptr) godot::api->godot_free(c_file);
if (c_desc != nullptr)
godot::api->godot_free(c_desc);
if (c_func != nullptr)
godot::api->godot_free(c_func);
if (c_file != nullptr)
godot::api->godot_free(c_file);
}
void Godot::print_error(const String &description, const String &function, const String &file, int line) {
@@ -71,9 +74,12 @@ void Godot::print_error(const String &description, const String &function, const
godot::api->godot_print_error(c_desc, c_func, c_file, line);
};
if (c_desc != nullptr) godot::api->godot_free(c_desc);
if (c_func != nullptr) godot::api->godot_free(c_func);
if (c_file != nullptr) godot::api->godot_free(c_file);
if (c_desc != nullptr)
godot::api->godot_free(c_desc);
if (c_func != nullptr)
godot::api->godot_free(c_func);
if (c_file != nullptr)
godot::api->godot_free(c_file);
}
void ___register_types();
@@ -136,7 +142,8 @@ void Godot::gdnative_init(godot_gdnative_init_options *options) {
}
} break;
default: break;
default:
break;
}
}

View File

@@ -10,12 +10,10 @@ void Plane::set_normal(const Vector3 &p_normal) {
}
Vector3 Plane::project(const Vector3 &p_point) const {
return p_point - normal * distance_to(p_point);
}
void Plane::normalize() {
real_t l = normal.length();
if (l == 0) {
*this = Plane(0, 0, 0, 0);
@@ -26,19 +24,16 @@ void Plane::normalize() {
}
Plane Plane::normalized() const {
Plane p = *this;
p.normalize();
return p;
}
Vector3 Plane::get_any_point() const {
return get_normal() * d;
}
Vector3 Plane::get_any_perpendicular_normal() const {
static const Vector3 p1 = Vector3(1, 0, 0);
static const Vector3 p2 = Vector3(0, 1, 0);
Vector3 p;
@@ -57,7 +52,6 @@ Vector3 Plane::get_any_perpendicular_normal() const {
/* intersections */
bool Plane::intersect_3(const Plane &p_plane1, const Plane &p_plane2, Vector3 *r_result) const {
const Plane &p_plane0 = *this;
Vector3 normal0 = p_plane0.normal;
Vector3 normal1 = p_plane1.normal;
@@ -79,13 +73,11 @@ bool Plane::intersect_3(const Plane &p_plane1, const Plane &p_plane2, Vector3 *r
}
bool Plane::intersects_ray(Vector3 p_from, Vector3 p_dir, Vector3 *p_intersection) const {
Vector3 segment = p_dir;
real_t den = normal.dot(segment);
//printf("den is %i\n",den);
if (::fabs(den) <= CMP_EPSILON) {
return false;
}
@@ -104,13 +96,11 @@ bool Plane::intersects_ray(Vector3 p_from, Vector3 p_dir, Vector3 *p_intersectio
}
bool Plane::intersects_segment(Vector3 p_begin, Vector3 p_end, Vector3 *p_intersection) const {
Vector3 segment = p_begin - p_end;
real_t den = normal.dot(segment);
//printf("den is %i\n",den);
if (::fabs(den) <= CMP_EPSILON) {
return false;
}
@@ -118,7 +108,6 @@ bool Plane::intersects_segment(Vector3 p_begin, Vector3 p_end, Vector3 *p_inters
//printf("dist is %i\n",dist);
if (dist < -CMP_EPSILON || dist > (1.0 + CMP_EPSILON)) {
return false;
}
@@ -131,47 +120,39 @@ bool Plane::intersects_segment(Vector3 p_begin, Vector3 p_end, Vector3 *p_inters
/* misc */
bool Plane::is_almost_like(const Plane &p_plane) const {
return (normal.dot(p_plane.normal) > _PLANE_EQ_DOT_EPSILON && ::fabs(d - p_plane.d) < _PLANE_EQ_D_EPSILON);
}
Plane::operator String() const {
// return normal.operator String() + ", " + rtos(d);
return String(); // @Todo
}
bool Plane::is_point_over(const Vector3 &p_point) const {
return (normal.dot(p_point) > d);
}
real_t Plane::distance_to(const Vector3 &p_point) const {
return (normal.dot(p_point) - d);
}
bool Plane::has_point(const Vector3 &p_point, real_t _epsilon) const {
real_t dist = normal.dot(p_point) - d;
dist = ::fabs(dist);
return (dist <= _epsilon);
}
Plane::Plane(const Vector3 &p_normal, real_t p_d) {
normal = p_normal;
d = p_d;
}
Plane::Plane(const Vector3 &p_point, const Vector3 &p_normal) {
normal = p_normal;
d = p_normal.dot(p_point);
}
Plane::Plane(const Vector3 &p_point1, const Vector3 &p_point2, const Vector3 &p_point3, ClockDirection p_dir) {
if (p_dir == CLOCKWISE)
normal = (p_point1 - p_point3).cross(p_point1 - p_point2);
else
@@ -182,12 +163,10 @@ Plane::Plane(const Vector3 &p_point1, const Vector3 &p_point2, const Vector3 &p_
}
bool Plane::operator==(const Plane &p_plane) const {
return normal == p_plane.normal && d == p_plane.d;
}
bool Plane::operator!=(const Plane &p_plane) const {
return normal != p_plane.normal || d != p_plane.d;
}

View File

@@ -100,7 +100,6 @@ Quat Quat::inverse() const {
}
Quat Quat::slerp(const Quat &q, const real_t &t) const {
Quat to1;
real_t omega, cosom, sinom, scale0, scale1;
@@ -144,12 +143,12 @@ Quat Quat::slerp(const Quat &q, const real_t &t) const {
}
Quat Quat::slerpni(const Quat &q, const real_t &t) const {
const Quat &from = *this;
real_t dot = from.dot(q);
if (::fabs(dot) > 0.9999) return from;
if (::fabs(dot) > 0.9999)
return from;
real_t theta = ::acos(dot),
sinT = 1.0 / ::sin(theta),
@@ -200,7 +199,6 @@ Quat Quat::operator*(const Vector3 &v) const {
}
Vector3 Quat::xform(const Vector3 &v) const {
Quat q = *this * v;
q *= this->inverse();
return Vector3(q.x, q.y, q.z);
@@ -234,7 +232,6 @@ Quat::Quat(const Vector3 &v0, const Vector3 &v1) // shortest arc
z = 0;
w = 0;
} else {
real_t s = ::sqrt((1.0 + d) * 2.0);
real_t rs = 1.0 / s;
@@ -282,7 +279,6 @@ void Quat::operator*=(const real_t &s) {
}
void Quat::operator/=(const real_t &s) {
*this *= 1.0 / s;
}

View File

@@ -16,7 +16,6 @@ namespace godot {
#endif
real_t Rect2::distance_to(const Vector2 &p_point) const {
real_t dist = 1e20;
if (p_point.x < position.x) {
@@ -77,7 +76,6 @@ Rect2::operator String() const {
}
bool Rect2::intersects_segment(const Point2 &p_from, const Point2 &p_to, Point2 *r_position, Point2 *r_normal) const {
real_t min = 0, max = 1;
int axis = 0;
real_t sign = 0;
@@ -91,7 +89,6 @@ bool Rect2::intersects_segment(const Point2 &p_from, const Point2 &p_to, Point2
real_t csign;
if (seg_from < seg_to) {
if (seg_from > box_end || seg_to < box_begin)
return false;
real_t length = seg_to - seg_from;
@@ -100,7 +97,6 @@ bool Rect2::intersects_segment(const Point2 &p_from, const Point2 &p_to, Point2
csign = -1.0;
} else {
if (seg_to > box_end || seg_from < box_begin)
return false;
real_t length = seg_to - seg_from;
@@ -135,7 +131,6 @@ bool Rect2::intersects_segment(const Point2 &p_from, const Point2 &p_to, Point2
}
bool Rect2::intersects_transformed(const Transform2D &p_xform, const Rect2 &p_rect) const {
//SAT intersection between local and transformed rect2
Vector2 xf_points[4] = {

View File

@@ -73,6 +73,10 @@ String::String(const String &other) {
godot::api->godot_string_new_copy(&_godot_string, &other._godot_string);
}
String::String(String &&other) {
godot::api->godot_string_new_copy(&_godot_string, &other._godot_string);
}
String::~String() {
godot::api->godot_string_destroy(&_godot_string);
}
@@ -94,6 +98,11 @@ void String::operator=(const String &s) {
godot::api->godot_string_new_copy(&_godot_string, &s._godot_string);
}
void String::operator=(String &&s) {
godot::api->godot_string_destroy(&_godot_string);
godot::api->godot_string_new_copy(&_godot_string, &s._godot_string);
}
bool String::operator==(const String &s) const {
return godot::api->godot_string_operator_equal(&_godot_string, &s._godot_string);
}
@@ -141,7 +150,6 @@ const wchar_t *String::unicode_str() const {
}
char *String::alloc_c_string() const {
godot_char_string contents = godot::api->godot_string_utf8(&_godot_string);
int length = godot::api->godot_char_string_length(&contents);
@@ -166,7 +174,6 @@ CharString String::utf8() const {
}
CharString String::ascii(bool p_extended) const {
CharString ret;
if (p_extended)

View File

@@ -22,14 +22,12 @@ bool is_type_known(size_t type_tag) {
}
void register_global_type(const char *name, size_t type_tag, size_t base_type_tag) {
godot::nativescript_1_1_api->godot_nativescript_set_global_type_tag(godot::_RegisterState::language_index, name, (const void *)type_tag);
register_type(type_tag, base_type_tag);
}
bool is_type_compatible(size_t ask_tag, size_t have_tag) {
if (have_tag == 0)
return false;

View File

@@ -15,14 +15,12 @@ const Transform Transform::FLIP_Y = Transform(1, 0, 0, 0, -1, 0, 0, 0, 1, 0, 0,
const Transform Transform::FLIP_Z = Transform(1, 0, 0, 0, 1, 0, 0, 0, -1, 0, 0, 0);
Transform Transform::inverse_xform(const Transform &t) const {
Vector3 v = t.origin - origin;
return Transform(basis.transpose_xform(t.basis),
basis.xform(v));
}
void Transform::set(real_t xx, real_t xy, real_t xz, real_t yx, real_t yy, real_t yz, real_t zx, real_t zy, real_t zz, real_t tx, real_t ty, real_t tz) {
basis.elements[0][0] = xx;
basis.elements[0][1] = xy;
basis.elements[0][2] = xz;
@@ -38,14 +36,12 @@ void Transform::set(real_t xx, real_t xy, real_t xz, real_t yx, real_t yy, real_
}
Vector3 Transform::xform(const Vector3 &p_vector) const {
return Vector3(
basis.elements[0].dot(p_vector) + origin.x,
basis.elements[1].dot(p_vector) + origin.y,
basis.elements[2].dot(p_vector) + origin.z);
}
Vector3 Transform::xform_inv(const Vector3 &p_vector) const {
Vector3 v = p_vector - origin;
return Vector3(
@@ -55,7 +51,6 @@ Vector3 Transform::xform_inv(const Vector3 &p_vector) const {
}
Plane Transform::xform(const Plane &p_plane) const {
Vector3 point = p_plane.normal * p_plane.d;
Vector3 point_dir = point + p_plane.normal;
point = xform(point);
@@ -68,7 +63,6 @@ Plane Transform::xform(const Plane &p_plane) const {
return Plane(normal, d);
}
Plane Transform::xform_inv(const Plane &p_plane) const {
Vector3 point = p_plane.normal * p_plane.d;
Vector3 point_dir = point + p_plane.normal;
point = xform_inv(point);
@@ -100,7 +94,6 @@ AABB Transform::xform(const AABB &p_aabb) const {
return new_aabb;
}
AABB Transform::xform_inv(const AABB &p_aabb) const {
/* define vertices */
Vector3 vertices[8] = {
Vector3(p_aabb.position.x + p_aabb.size.x, p_aabb.position.y + p_aabb.size.y, p_aabb.position.z + p_aabb.size.z),
@@ -118,7 +111,6 @@ AABB Transform::xform_inv(const AABB &p_aabb) const {
ret.position = xform_inv(vertices[0]);
for (int i = 1; i < 8; i++) {
ret.expand_to(xform_inv(vertices[i]));
}
@@ -126,20 +118,17 @@ AABB Transform::xform_inv(const AABB &p_aabb) const {
}
void Transform::affine_invert() {
basis.invert();
origin = basis.xform(-origin);
}
Transform Transform::affine_inverse() const {
Transform ret = *this;
ret.affine_invert();
return ret;
}
void Transform::invert() {
basis.transpose();
origin = basis.xform(-origin);
}
@@ -153,29 +142,24 @@ Transform Transform::inverse() const {
}
void Transform::rotate(const Vector3 &p_axis, real_t p_phi) {
*this = rotated(p_axis, p_phi);
}
Transform Transform::rotated(const Vector3 &p_axis, real_t p_phi) const {
return Transform(Basis(p_axis, p_phi), Vector3()) * (*this);
}
void Transform::rotate_basis(const Vector3 &p_axis, real_t p_phi) {
basis.rotate(p_axis, p_phi);
}
Transform Transform::looking_at(const Vector3 &p_target, const Vector3 &p_up) const {
Transform t = *this;
t.set_look_at(origin, p_target, p_up);
return t;
}
void Transform::set_look_at(const Vector3 &p_eye, const Vector3 &p_target, const Vector3 &p_up) {
// Reference: MESA source code
Vector3 v_x, v_y, v_z;
@@ -203,7 +187,6 @@ void Transform::set_look_at(const Vector3 &p_eye, const Vector3 &p_target, const
}
Transform Transform::interpolate_with(const Transform &p_transform, real_t p_c) const {
/* not sure if very "efficient" but good enough? */
Vector3 src_scale = basis.get_scale();
@@ -223,20 +206,17 @@ Transform Transform::interpolate_with(const Transform &p_transform, real_t p_c)
}
void Transform::scale(const Vector3 &p_scale) {
basis.scale(p_scale);
origin *= p_scale;
}
Transform Transform::scaled(const Vector3 &p_scale) const {
Transform t = *this;
t.scale(p_scale);
return t;
}
void Transform::scale_basis(const Vector3 &p_scale) {
basis.scale(p_scale);
}
@@ -244,60 +224,50 @@ void Transform::translate(real_t p_tx, real_t p_ty, real_t p_tz) {
translate(Vector3(p_tx, p_ty, p_tz));
}
void Transform::translate(const Vector3 &p_translation) {
for (int i = 0; i < 3; i++) {
origin[i] += basis.elements[i].dot(p_translation);
}
}
Transform Transform::translated(const Vector3 &p_translation) const {
Transform t = *this;
t.translate(p_translation);
return t;
}
void Transform::orthonormalize() {
basis.orthonormalize();
}
Transform Transform::orthonormalized() const {
Transform _copy = *this;
_copy.orthonormalize();
return _copy;
}
bool Transform::operator==(const Transform &p_transform) const {
return (basis == p_transform.basis && origin == p_transform.origin);
}
bool Transform::operator!=(const Transform &p_transform) const {
return (basis != p_transform.basis || origin != p_transform.origin);
}
void Transform::operator*=(const Transform &p_transform) {
origin = xform(p_transform.origin);
basis *= p_transform.basis;
}
Transform Transform::operator*(const Transform &p_transform) const {
Transform t = *this;
t *= p_transform;
return t;
}
Transform::operator String() const {
return basis.operator String() + " - " + origin.operator String();
}
Transform::Transform(const Basis &p_basis, const Vector3 &p_origin) {
basis = p_basis;
origin = p_origin;
}

View File

@@ -12,7 +12,6 @@ const Transform2D Transform2D::FLIP_X = Transform2D(-1, 0, 0, 1, 0, 0);
const Transform2D Transform2D::FLIP_Y = Transform2D(1, 0, 0, -1, 0, 0);
Transform2D::Transform2D(real_t xx, real_t xy, real_t yx, real_t yy, real_t ox, real_t oy) {
elements[0][0] = xx;
elements[0][1] = xy;
elements[1][0] = yx;
@@ -22,28 +21,24 @@ Transform2D::Transform2D(real_t xx, real_t xy, real_t yx, real_t yy, real_t ox,
}
Vector2 Transform2D::basis_xform(const Vector2 &v) const {
return Vector2(
tdotx(v),
tdoty(v));
}
Vector2 Transform2D::basis_xform_inv(const Vector2 &v) const {
return Vector2(
elements[0].dot(v),
elements[1].dot(v));
}
Vector2 Transform2D::xform(const Vector2 &v) const {
return Vector2(
tdotx(v),
tdoty(v)) +
elements[2];
}
Vector2 Transform2D::xform_inv(const Vector2 &p_vec) const {
Vector2 v = p_vec - elements[2];
return Vector2(
@@ -51,7 +46,6 @@ Vector2 Transform2D::xform_inv(const Vector2 &p_vec) const {
elements[1].dot(v));
}
Rect2 Transform2D::xform(const Rect2 &p_rect) const {
Vector2 x = elements[0] * p_rect.size.x;
Vector2 y = elements[1] * p_rect.size.y;
Vector2 position = xform(p_rect.position);
@@ -65,7 +59,6 @@ Rect2 Transform2D::xform(const Rect2 &p_rect) const {
}
void Transform2D::set_rotation_and_scale(real_t p_rot, const Size2 &p_scale) {
elements[0][0] = ::cos(p_rot) * p_scale.x;
elements[1][1] = ::cos(p_rot) * p_scale.y;
elements[1][0] = -::sin(p_rot) * p_scale.y;
@@ -73,7 +66,6 @@ void Transform2D::set_rotation_and_scale(real_t p_rot, const Size2 &p_scale) {
}
Rect2 Transform2D::xform_inv(const Rect2 &p_rect) const {
Vector2 ends[4] = {
xform_inv(p_rect.position),
xform_inv(Vector2(p_rect.position.x, p_rect.position.y + p_rect.size.y)),
@@ -98,14 +90,12 @@ void Transform2D::invert() {
}
Transform2D Transform2D::inverse() const {
Transform2D inv = *this;
inv.invert();
return inv;
}
void Transform2D::affine_invert() {
real_t det = basis_determinant();
ERR_FAIL_COND(det == 0);
real_t idet = 1.0 / det;
@@ -118,7 +108,6 @@ void Transform2D::affine_invert() {
}
Transform2D Transform2D::affine_inverse() const {
Transform2D inv = *this;
inv.affine_invert();
return inv;
@@ -138,7 +127,6 @@ real_t Transform2D::get_rotation() const {
}
void Transform2D::set_rotation(real_t p_rot) {
real_t cr = ::cos(p_rot);
real_t sr = ::sin(p_rot);
elements[0][0] = cr;
@@ -148,7 +136,6 @@ void Transform2D::set_rotation(real_t p_rot) {
}
Transform2D::Transform2D(real_t p_rot, const Vector2 &p_position) {
real_t cr = ::cos(p_rot);
real_t sr = ::sin(p_rot);
elements[0][0] = cr;
@@ -168,23 +155,19 @@ void Transform2D::scale(const Size2 &p_scale) {
elements[2] *= p_scale;
}
void Transform2D::scale_basis(const Size2 &p_scale) {
elements[0][0] *= p_scale.x;
elements[0][1] *= p_scale.y;
elements[1][0] *= p_scale.x;
elements[1][1] *= p_scale.y;
}
void Transform2D::translate(real_t p_tx, real_t p_ty) {
translate(Vector2(p_tx, p_ty));
}
void Transform2D::translate(const Vector2 &p_translation) {
elements[2] += basis_xform(p_translation);
}
void Transform2D::orthonormalize() {
// Gram-Schmidt Process
Vector2 x = elements[0];
@@ -198,14 +181,12 @@ void Transform2D::orthonormalize() {
elements[1] = y;
}
Transform2D Transform2D::orthonormalized() const {
Transform2D on = *this;
on.orthonormalize();
return on;
}
bool Transform2D::operator==(const Transform2D &p_transform) const {
for (int i = 0; i < 3; i++) {
if (elements[i] != p_transform.elements[i])
return false;
@@ -215,7 +196,6 @@ bool Transform2D::operator==(const Transform2D &p_transform) const {
}
bool Transform2D::operator!=(const Transform2D &p_transform) const {
for (int i = 0; i < 3; i++) {
if (elements[i] != p_transform.elements[i])
return true;
@@ -225,7 +205,6 @@ bool Transform2D::operator!=(const Transform2D &p_transform) const {
}
void Transform2D::operator*=(const Transform2D &p_transform) {
elements[2] = xform(p_transform.elements[2]);
real_t x0, x1, y0, y1;
@@ -242,54 +221,46 @@ void Transform2D::operator*=(const Transform2D &p_transform) {
}
Transform2D Transform2D::operator*(const Transform2D &p_transform) const {
Transform2D t = *this;
t *= p_transform;
return t;
}
Transform2D Transform2D::scaled(const Size2 &p_scale) const {
Transform2D copy = *this;
copy.scale(p_scale);
return copy;
}
Transform2D Transform2D::basis_scaled(const Size2 &p_scale) const {
Transform2D copy = *this;
copy.scale_basis(p_scale);
return copy;
}
Transform2D Transform2D::untranslated() const {
Transform2D copy = *this;
copy.elements[2] = Vector2();
return copy;
}
Transform2D Transform2D::translated(const Vector2 &p_offset) const {
Transform2D copy = *this;
copy.translate(p_offset);
return copy;
}
Transform2D Transform2D::rotated(real_t p_phi) const {
Transform2D copy = *this;
copy.rotate(p_phi);
return copy;
}
real_t Transform2D::basis_determinant() const {
return elements[0].x * elements[1].y - elements[0].y * elements[1].x;
}
Transform2D Transform2D::interpolate_with(const Transform2D &p_transform, real_t p_c) const {
//extract parameters
Vector2 p1 = get_origin();
Vector2 p2 = p_transform.get_origin();
@@ -325,7 +296,6 @@ Transform2D Transform2D::interpolate_with(const Transform2D &p_transform, real_t
}
Transform2D::operator String() const {
return String(String() + elements[0] + ", " + elements[1] + ", " + elements[2]);
}

View File

@@ -6,9 +6,9 @@
namespace godot {
const Vector2 Vector2::ZERO;
const Vector2 Vector2::ONE;
const Vector2 Vector2::INF;
const Vector2 Vector2::ZERO = Vector2();
const Vector2 Vector2::ONE = Vector2(1, 1);
const Vector2 Vector2::INF = Vector2(INFINITY, INFINITY);
const Vector2 Vector2::LEFT = Vector2(-1, 0);
const Vector2 Vector2::RIGHT = Vector2(1, 0);

View File

@@ -9,7 +9,7 @@
namespace godot {
const Vector3 Vector3::ZERO = Vector3();
const Vector3 Vector3::ONE = Vector3();
const Vector3 Vector3::ONE = Vector3(1, 1, 1);
const Vector3 Vector3::INF = Vector3(INFINITY, INFINITY, INFINITY);
const Vector3 Vector3::LEFT = Vector3(-1, 0, 0);