2014-02-10 01:10:30 +00:00
|
|
|
/*************************************************************************/
|
|
|
|
/* test_math.cpp */
|
|
|
|
/*************************************************************************/
|
|
|
|
/* This file is part of: */
|
|
|
|
/* GODOT ENGINE */
|
2017-08-27 12:16:55 +00:00
|
|
|
/* https://godotengine.org */
|
2014-02-10 01:10:30 +00:00
|
|
|
/*************************************************************************/
|
2020-01-01 10:16:22 +00:00
|
|
|
/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */
|
|
|
|
/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */
|
2014-02-10 01:10:30 +00:00
|
|
|
/* */
|
|
|
|
/* Permission is hereby granted, free of charge, to any person obtaining */
|
|
|
|
/* a copy of this software and associated documentation files (the */
|
|
|
|
/* "Software"), to deal in the Software without restriction, including */
|
|
|
|
/* without limitation the rights to use, copy, modify, merge, publish, */
|
|
|
|
/* distribute, sublicense, and/or sell copies of the Software, and to */
|
|
|
|
/* permit persons to whom the Software is furnished to do so, subject to */
|
|
|
|
/* the following conditions: */
|
|
|
|
/* */
|
|
|
|
/* The above copyright notice and this permission notice shall be */
|
|
|
|
/* included in all copies or substantial portions of the Software. */
|
|
|
|
/* */
|
|
|
|
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
|
|
|
|
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
|
|
|
|
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
|
|
|
|
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
|
|
|
|
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
|
|
|
|
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
|
|
|
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
|
|
|
/*************************************************************************/
|
2018-01-04 23:50:27 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
#include "test_math.h"
|
2017-03-05 14:47:28 +00:00
|
|
|
|
2019-02-09 05:24:02 +00:00
|
|
|
#include "core/math/basis.h"
|
2018-09-11 16:13:45 +00:00
|
|
|
#include "core/math/camera_matrix.h"
|
2020-05-01 12:34:23 +00:00
|
|
|
#include "core/math/delaunay_3d.h"
|
2020-05-25 17:20:45 +00:00
|
|
|
#include "core/math/geometry_2d.h"
|
2018-09-11 16:13:45 +00:00
|
|
|
#include "core/math/math_funcs.h"
|
|
|
|
#include "core/math/transform.h"
|
|
|
|
#include "core/os/file_access.h"
|
|
|
|
#include "core/os/keyboard.h"
|
|
|
|
#include "core/os/os.h"
|
2020-11-07 22:33:38 +00:00
|
|
|
#include "core/string/print_string.h"
|
|
|
|
#include "core/string/ustring.h"
|
|
|
|
#include "core/templates/vmap.h"
|
|
|
|
#include "core/variant/method_ptrcall.h"
|
|
|
|
#include "core/variant/variant.h"
|
2017-03-05 15:44:50 +00:00
|
|
|
#include "scene/main/node.h"
|
2014-02-10 01:10:30 +00:00
|
|
|
#include "scene/resources/texture.h"
|
2020-03-27 18:21:27 +00:00
|
|
|
#include "servers/rendering/shader_language.h"
|
2016-06-23 02:12:20 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
namespace TestMath {
|
|
|
|
|
2016-09-15 13:13:28 +00:00
|
|
|
class GetClassAndNamespace {
|
|
|
|
String code;
|
|
|
|
int idx;
|
|
|
|
int line;
|
|
|
|
String error_str;
|
|
|
|
bool error;
|
|
|
|
Variant value;
|
|
|
|
|
|
|
|
String class_name;
|
|
|
|
|
|
|
|
enum Token {
|
|
|
|
TK_BRACKET_OPEN,
|
|
|
|
TK_BRACKET_CLOSE,
|
|
|
|
TK_CURLY_BRACKET_OPEN,
|
|
|
|
TK_CURLY_BRACKET_CLOSE,
|
|
|
|
TK_PERIOD,
|
|
|
|
TK_COLON,
|
|
|
|
TK_COMMA,
|
|
|
|
TK_SYMBOL,
|
|
|
|
TK_IDENTIFIER,
|
|
|
|
TK_STRING,
|
|
|
|
TK_NUMBER,
|
|
|
|
TK_EOF,
|
|
|
|
TK_ERROR
|
|
|
|
};
|
|
|
|
|
|
|
|
Token get_token() {
|
|
|
|
while (true) {
|
2017-03-05 15:44:50 +00:00
|
|
|
switch (code[idx]) {
|
2016-09-15 13:13:28 +00:00
|
|
|
case '\n': {
|
|
|
|
line++;
|
|
|
|
idx++;
|
|
|
|
break;
|
|
|
|
};
|
|
|
|
case 0: {
|
|
|
|
return TK_EOF;
|
|
|
|
|
|
|
|
} break;
|
|
|
|
case '{': {
|
|
|
|
idx++;
|
|
|
|
return TK_CURLY_BRACKET_OPEN;
|
|
|
|
};
|
|
|
|
case '}': {
|
|
|
|
idx++;
|
|
|
|
return TK_CURLY_BRACKET_CLOSE;
|
|
|
|
};
|
|
|
|
case '[': {
|
|
|
|
idx++;
|
|
|
|
return TK_BRACKET_OPEN;
|
|
|
|
};
|
|
|
|
case ']': {
|
|
|
|
idx++;
|
|
|
|
return TK_BRACKET_CLOSE;
|
|
|
|
};
|
|
|
|
case ':': {
|
|
|
|
idx++;
|
|
|
|
return TK_COLON;
|
|
|
|
};
|
|
|
|
case ',': {
|
|
|
|
idx++;
|
|
|
|
return TK_COMMA;
|
|
|
|
};
|
|
|
|
case '.': {
|
|
|
|
idx++;
|
|
|
|
return TK_PERIOD;
|
|
|
|
};
|
|
|
|
case '#': {
|
|
|
|
//compiler directive
|
2017-03-05 15:44:50 +00:00
|
|
|
while (code[idx] != '\n' && code[idx] != 0) {
|
2016-09-15 13:13:28 +00:00
|
|
|
idx++;
|
|
|
|
}
|
|
|
|
continue;
|
|
|
|
} break;
|
|
|
|
case '/': {
|
2017-03-05 15:44:50 +00:00
|
|
|
switch (code[idx + 1]) {
|
2016-09-15 13:13:28 +00:00
|
|
|
case '*': { // block comment
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
idx += 2;
|
|
|
|
while (true) {
|
|
|
|
if (code[idx] == 0) {
|
|
|
|
error_str = "Unterminated comment";
|
|
|
|
error = true;
|
2016-09-15 13:13:28 +00:00
|
|
|
return TK_ERROR;
|
2017-03-05 15:44:50 +00:00
|
|
|
} else if (code[idx] == '*' && code[idx + 1] == '/') {
|
|
|
|
idx += 2;
|
2016-09-15 13:13:28 +00:00
|
|
|
break;
|
2017-03-05 15:44:50 +00:00
|
|
|
} else if (code[idx] == '\n') {
|
2016-09-15 13:13:28 +00:00
|
|
|
line++;
|
|
|
|
}
|
|
|
|
|
|
|
|
idx++;
|
|
|
|
}
|
|
|
|
|
|
|
|
} break;
|
|
|
|
case '/': { // line comment skip
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
while (code[idx] != '\n' && code[idx] != 0) {
|
2016-09-15 13:13:28 +00:00
|
|
|
idx++;
|
|
|
|
}
|
|
|
|
|
|
|
|
} break;
|
|
|
|
default: {
|
2017-03-05 15:44:50 +00:00
|
|
|
value = "/";
|
2016-09-15 13:13:28 +00:00
|
|
|
idx++;
|
|
|
|
return TK_SYMBOL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
continue; // a comment
|
|
|
|
} break;
|
|
|
|
case '\'':
|
|
|
|
case '"': {
|
2020-07-27 10:43:20 +00:00
|
|
|
char32_t begin_str = code[idx];
|
2016-09-15 13:13:28 +00:00
|
|
|
idx++;
|
2017-03-05 15:44:50 +00:00
|
|
|
String tk_string = String();
|
|
|
|
while (true) {
|
|
|
|
if (code[idx] == 0) {
|
|
|
|
error_str = "Unterminated String";
|
|
|
|
error = true;
|
2016-09-15 13:13:28 +00:00
|
|
|
return TK_ERROR;
|
2017-03-05 15:44:50 +00:00
|
|
|
} else if (code[idx] == begin_str) {
|
2016-09-15 13:13:28 +00:00
|
|
|
idx++;
|
|
|
|
break;
|
2017-03-05 15:44:50 +00:00
|
|
|
} else if (code[idx] == '\\') {
|
2016-09-15 13:13:28 +00:00
|
|
|
//escaped characters...
|
|
|
|
idx++;
|
2020-07-27 10:43:20 +00:00
|
|
|
char32_t next = code[idx];
|
2017-03-05 15:44:50 +00:00
|
|
|
if (next == 0) {
|
|
|
|
error_str = "Unterminated String";
|
|
|
|
error = true;
|
2016-09-15 13:13:28 +00:00
|
|
|
return TK_ERROR;
|
|
|
|
}
|
2020-07-27 10:43:20 +00:00
|
|
|
char32_t res = 0;
|
2016-09-15 13:13:28 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
switch (next) {
|
2020-05-10 11:00:47 +00:00
|
|
|
case 'b':
|
|
|
|
res = 8;
|
|
|
|
break;
|
|
|
|
case 't':
|
|
|
|
res = 9;
|
|
|
|
break;
|
|
|
|
case 'n':
|
|
|
|
res = 10;
|
|
|
|
break;
|
|
|
|
case 'f':
|
|
|
|
res = 12;
|
|
|
|
break;
|
2017-03-05 15:44:50 +00:00
|
|
|
case 'r':
|
|
|
|
res = 13;
|
|
|
|
break;
|
2020-05-10 11:00:47 +00:00
|
|
|
case '\"':
|
|
|
|
res = '\"';
|
|
|
|
break;
|
2017-03-05 15:44:50 +00:00
|
|
|
case '\\':
|
|
|
|
res = '\\';
|
|
|
|
break;
|
2016-09-15 13:13:28 +00:00
|
|
|
default: {
|
|
|
|
res = next;
|
|
|
|
} break;
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
tk_string += res;
|
2016-09-15 13:13:28 +00:00
|
|
|
|
|
|
|
} else {
|
2020-05-14 14:41:43 +00:00
|
|
|
if (code[idx] == '\n') {
|
2016-09-15 13:13:28 +00:00
|
|
|
line++;
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2017-03-05 15:44:50 +00:00
|
|
|
tk_string += code[idx];
|
2016-09-15 13:13:28 +00:00
|
|
|
}
|
|
|
|
idx++;
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
value = tk_string;
|
2016-09-15 13:13:28 +00:00
|
|
|
|
|
|
|
return TK_STRING;
|
|
|
|
|
|
|
|
} break;
|
|
|
|
default: {
|
2017-03-05 15:44:50 +00:00
|
|
|
if (code[idx] <= 32) {
|
2016-09-15 13:13:28 +00:00
|
|
|
idx++;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if ((code[idx] >= 33 && code[idx] <= 47) || (code[idx] >= 58 && code[idx] <= 64) || (code[idx] >= 91 && code[idx] <= 96) || (code[idx] >= 123 && code[idx] <= 127)) {
|
|
|
|
value = String::chr(code[idx]);
|
2016-09-15 13:13:28 +00:00
|
|
|
idx++;
|
|
|
|
return TK_SYMBOL;
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if (code[idx] == '-' || (code[idx] >= '0' && code[idx] <= '9')) {
|
2016-09-15 13:13:28 +00:00
|
|
|
//a number
|
2020-07-27 10:43:20 +00:00
|
|
|
const char32_t *rptr;
|
2020-07-24 18:07:57 +00:00
|
|
|
double number = String::to_float(&code[idx], &rptr);
|
2017-03-05 15:44:50 +00:00
|
|
|
idx += (rptr - &code[idx]);
|
|
|
|
value = number;
|
2016-09-15 13:13:28 +00:00
|
|
|
return TK_NUMBER;
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
} else if ((code[idx] >= 'A' && code[idx] <= 'Z') || (code[idx] >= 'a' && code[idx] <= 'z') || code[idx] > 127) {
|
2016-09-15 13:13:28 +00:00
|
|
|
String id;
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
while ((code[idx] >= 'A' && code[idx] <= 'Z') || (code[idx] >= 'a' && code[idx] <= 'z') || code[idx] > 127) {
|
|
|
|
id += code[idx];
|
2016-09-15 13:13:28 +00:00
|
|
|
idx++;
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
value = id;
|
2016-09-15 13:13:28 +00:00
|
|
|
return TK_IDENTIFIER;
|
|
|
|
} else {
|
2017-03-05 15:44:50 +00:00
|
|
|
error_str = "Unexpected character.";
|
|
|
|
error = true;
|
2016-09-15 13:13:28 +00:00
|
|
|
return TK_ERROR;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public:
|
2017-03-05 15:44:50 +00:00
|
|
|
Error parse(const String &p_code, const String &p_known_class_name = String()) {
|
|
|
|
code = p_code;
|
|
|
|
idx = 0;
|
|
|
|
line = 0;
|
|
|
|
error_str = String();
|
|
|
|
error = false;
|
|
|
|
value = Variant();
|
|
|
|
class_name = String();
|
2016-09-15 13:13:28 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
bool use_next_class = false;
|
2016-09-15 13:13:28 +00:00
|
|
|
Token tk = get_token();
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
Map<int, String> namespace_stack;
|
|
|
|
int curly_stack = 0;
|
2016-09-15 13:13:28 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
while (!error || tk != TK_EOF) {
|
|
|
|
if (tk == TK_BRACKET_OPEN) {
|
2016-09-15 13:13:28 +00:00
|
|
|
tk = get_token();
|
2017-03-05 15:44:50 +00:00
|
|
|
if (tk == TK_IDENTIFIER && String(value) == "ScriptClass") {
|
|
|
|
if (get_token() == TK_BRACKET_CLOSE) {
|
|
|
|
use_next_class = true;
|
2016-09-15 13:13:28 +00:00
|
|
|
}
|
|
|
|
}
|
2017-03-05 15:44:50 +00:00
|
|
|
} else if (tk == TK_IDENTIFIER && String(value) == "class") {
|
2016-09-15 13:13:28 +00:00
|
|
|
tk = get_token();
|
2017-03-05 15:44:50 +00:00
|
|
|
if (tk == TK_IDENTIFIER) {
|
2016-09-15 13:13:28 +00:00
|
|
|
String name = value;
|
2017-03-05 15:44:50 +00:00
|
|
|
if (use_next_class || p_known_class_name == name) {
|
|
|
|
for (Map<int, String>::Element *E = namespace_stack.front(); E; E = E->next()) {
|
|
|
|
class_name += E->get() + ".";
|
2016-09-15 13:13:28 +00:00
|
|
|
}
|
2017-03-05 15:44:50 +00:00
|
|
|
class_name += String(value);
|
2016-09-15 13:13:28 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
} else if (tk == TK_IDENTIFIER && String(value) == "namespace") {
|
2016-09-15 13:13:28 +00:00
|
|
|
String name;
|
|
|
|
int at_level = curly_stack;
|
2017-03-05 15:44:50 +00:00
|
|
|
while (true) {
|
2016-09-15 13:13:28 +00:00
|
|
|
tk = get_token();
|
2017-03-05 15:44:50 +00:00
|
|
|
if (tk == TK_IDENTIFIER) {
|
|
|
|
name += String(value);
|
2016-09-15 13:13:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
tk = get_token();
|
2017-03-05 15:44:50 +00:00
|
|
|
if (tk == TK_PERIOD) {
|
|
|
|
name += ".";
|
|
|
|
} else if (tk == TK_CURLY_BRACKET_OPEN) {
|
2016-09-15 13:13:28 +00:00
|
|
|
curly_stack++;
|
|
|
|
break;
|
|
|
|
} else {
|
|
|
|
break; //whathever else
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if (name != String()) {
|
|
|
|
namespace_stack[at_level] = name;
|
2016-09-15 13:13:28 +00:00
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
} else if (tk == TK_CURLY_BRACKET_OPEN) {
|
2016-09-15 13:13:28 +00:00
|
|
|
curly_stack++;
|
2017-03-05 15:44:50 +00:00
|
|
|
} else if (tk == TK_CURLY_BRACKET_CLOSE) {
|
2016-09-15 13:13:28 +00:00
|
|
|
curly_stack--;
|
|
|
|
if (namespace_stack.has(curly_stack)) {
|
|
|
|
namespace_stack.erase(curly_stack);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
tk = get_token();
|
|
|
|
}
|
|
|
|
|
2020-05-14 14:41:43 +00:00
|
|
|
if (error) {
|
2016-09-15 13:13:28 +00:00
|
|
|
return ERR_PARSE_ERROR;
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2016-09-15 13:13:28 +00:00
|
|
|
|
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
String get_error() {
|
|
|
|
return error_str;
|
|
|
|
}
|
|
|
|
|
|
|
|
String get_class() {
|
|
|
|
return class_name;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
void test_vec(Plane p_vec) {
|
|
|
|
CameraMatrix cm;
|
2017-03-05 15:44:50 +00:00
|
|
|
cm.set_perspective(45, 1, 0, 100);
|
|
|
|
Plane v0 = cm.xform4(p_vec);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
print_line("out: " + v0);
|
2020-05-10 14:47:11 +00:00
|
|
|
v0.normal.z = (v0.d / 100.0 * 2.0 - 1.0) * v0.d;
|
2017-03-05 15:44:50 +00:00
|
|
|
print_line("out_F: " + v0);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
uint32_t ihash(uint32_t a) {
|
|
|
|
a = (a + 0x7ed55d16) + (a << 12);
|
|
|
|
a = (a ^ 0xc761c23c) ^ (a >> 19);
|
|
|
|
a = (a + 0x165667b1) + (a << 5);
|
|
|
|
a = (a + 0xd3a2646c) ^ (a << 9);
|
|
|
|
a = (a + 0xfd7046c5) + (a << 3);
|
|
|
|
a = (a ^ 0xb55a4f09) ^ (a >> 16);
|
|
|
|
return a;
|
2016-02-11 03:00:11 +00:00
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
uint32_t ihash2(uint32_t a) {
|
|
|
|
a = (a ^ 61) ^ (a >> 16);
|
|
|
|
a = a + (a << 3);
|
|
|
|
a = a ^ (a >> 4);
|
|
|
|
a = a * 0x27d4eb2d;
|
|
|
|
a = a ^ (a >> 15);
|
|
|
|
return a;
|
2016-02-11 03:00:11 +00:00
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
uint32_t ihash3(uint32_t a) {
|
|
|
|
a = (a + 0x479ab41d) + (a << 8);
|
|
|
|
a = (a ^ 0xe4aa10ce) ^ (a >> 5);
|
|
|
|
a = (a + 0x9942f0a6) - (a << 14);
|
|
|
|
a = (a ^ 0x5aedd67d) ^ (a >> 3);
|
|
|
|
a = (a + 0x17bea992) + (a << 7);
|
|
|
|
return a;
|
2016-02-11 03:00:11 +00:00
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
MainLoop *test() {
|
2020-05-01 12:34:23 +00:00
|
|
|
{
|
|
|
|
Vector<Vector3> points;
|
|
|
|
points.push_back(Vector3(0, 0, 0));
|
|
|
|
points.push_back(Vector3(0, 0, 1));
|
|
|
|
points.push_back(Vector3(0, 1, 0));
|
|
|
|
points.push_back(Vector3(0, 1, 1));
|
|
|
|
points.push_back(Vector3(1, 1, 0));
|
|
|
|
points.push_back(Vector3(1, 0, 0));
|
|
|
|
points.push_back(Vector3(1, 0, 1));
|
|
|
|
points.push_back(Vector3(1, 1, 1));
|
|
|
|
|
|
|
|
for (int i = 0; i < 800; i++) {
|
|
|
|
points.push_back(Vector3(Math::randf() * 2.0 - 1.0, Math::randf() * 2.0 - 1.0, Math::randf() * 2.0 - 1.0) * Vector3(25, 30, 33));
|
|
|
|
}
|
|
|
|
|
|
|
|
Vector<Delaunay3D::OutputSimplex> os = Delaunay3D::tetrahedralize(points);
|
|
|
|
print_line("simplices in the end: " + itos(os.size()));
|
|
|
|
for (int i = 0; i < os.size(); i++) {
|
|
|
|
print_line("Simplex " + itos(i) + ": ");
|
|
|
|
print_line(points[os[i].points[0]]);
|
|
|
|
print_line(points[os[i].points[1]]);
|
|
|
|
print_line(points[os[i].points[2]]);
|
|
|
|
print_line(points[os[i].points[3]]);
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
FileAccessRef f = FileAccess::open("res://bsp.obj", FileAccess::WRITE);
|
|
|
|
for (int i = 0; i < os.size(); i++) {
|
|
|
|
f->store_line("o Simplex" + itos(i));
|
|
|
|
for (int j = 0; j < 4; j++) {
|
|
|
|
f->store_line(vformat("v %f %f %f", points[os[i].points[j]].x, points[os[i].points[j]].y, points[os[i].points[j]].z));
|
|
|
|
}
|
|
|
|
static const int face_order[4][3] = {
|
|
|
|
{ 1, 2, 3 },
|
|
|
|
{ 1, 3, 4 },
|
|
|
|
{ 1, 2, 4 },
|
|
|
|
{ 2, 3, 4 }
|
|
|
|
};
|
|
|
|
|
|
|
|
for (int j = 0; j < 4; j++) {
|
|
|
|
f->store_line(vformat("f %d %d %d", 4 * i + face_order[j][0], 4 * i + face_order[j][1], 4 * i + face_order[j][2]));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
f->close();
|
|
|
|
}
|
|
|
|
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2017-05-29 00:46:48 +00:00
|
|
|
{
|
|
|
|
float r = 1;
|
|
|
|
float g = 0.5;
|
|
|
|
float b = 0.1;
|
|
|
|
|
|
|
|
const float pow2to9 = 512.0f;
|
|
|
|
const float B = 15.0f;
|
|
|
|
const float N = 9.0f;
|
|
|
|
|
2017-08-27 19:07:15 +00:00
|
|
|
float sharedexp = 65408.000f;
|
2017-05-29 00:46:48 +00:00
|
|
|
|
|
|
|
float cRed = MAX(0.0f, MIN(sharedexp, r));
|
|
|
|
float cGreen = MAX(0.0f, MIN(sharedexp, g));
|
|
|
|
float cBlue = MAX(0.0f, MIN(sharedexp, b));
|
|
|
|
|
|
|
|
float cMax = MAX(cRed, MAX(cGreen, cBlue));
|
|
|
|
|
|
|
|
float expp = MAX(-B - 1.0f, floor(Math::log(cMax) / Math_LN2)) + 1.0f + B;
|
|
|
|
|
|
|
|
float sMax = (float)floor((cMax / Math::pow(2.0f, expp - B - N)) + 0.5f);
|
|
|
|
|
|
|
|
float exps = expp + 1.0f;
|
|
|
|
|
|
|
|
if (0.0 <= sMax && sMax < pow2to9) {
|
|
|
|
exps = expp;
|
|
|
|
}
|
|
|
|
|
|
|
|
float sRed = Math::floor((cRed / pow(2.0f, exps - B - N)) + 0.5f);
|
|
|
|
float sGreen = Math::floor((cGreen / pow(2.0f, exps - B - N)) + 0.5f);
|
|
|
|
float sBlue = Math::floor((cBlue / pow(2.0f, exps - B - N)) + 0.5f);
|
|
|
|
|
|
|
|
print_line("R: " + rtos(sRed) + " G: " + rtos(sGreen) + " B: " + rtos(sBlue) + " EXP: " + rtos(exps));
|
|
|
|
|
|
|
|
uint32_t rgbe = (Math::fast_ftoi(sRed) & 0x1FF) | ((Math::fast_ftoi(sGreen) & 0x1FF) << 9) | ((Math::fast_ftoi(sBlue) & 0x1FF) << 18) | ((Math::fast_ftoi(exps) & 0x1F) << 27);
|
|
|
|
|
|
|
|
float rb = rgbe & 0x1ff;
|
|
|
|
float gb = (rgbe >> 9) & 0x1ff;
|
|
|
|
float bb = (rgbe >> 18) & 0x1ff;
|
|
|
|
float eb = (rgbe >> 27);
|
2019-04-21 10:15:45 +00:00
|
|
|
float mb = Math::pow(2.0, eb - 15.0 - 9.0);
|
2017-05-29 00:46:48 +00:00
|
|
|
float rd = rb * mb;
|
|
|
|
float gd = gb * mb;
|
|
|
|
float bd = bb * mb;
|
|
|
|
|
|
|
|
print_line("RGBE: " + Color(rd, gd, bd));
|
|
|
|
}
|
|
|
|
|
2020-02-17 21:06:54 +00:00
|
|
|
Vector<int> ints;
|
2017-01-07 21:25:37 +00:00
|
|
|
ints.resize(20);
|
2017-01-05 22:41:36 +00:00
|
|
|
|
2017-01-07 21:25:37 +00:00
|
|
|
{
|
2020-02-17 21:06:54 +00:00
|
|
|
int *w;
|
|
|
|
w = ints.ptrw();
|
2017-03-05 15:44:50 +00:00
|
|
|
for (int i = 0; i < ints.size(); i++) {
|
|
|
|
w[i] = i;
|
2017-01-07 21:25:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-17 21:06:54 +00:00
|
|
|
Vector<int> posho = ints;
|
2017-01-05 22:41:36 +00:00
|
|
|
|
2017-01-07 21:25:37 +00:00
|
|
|
{
|
2020-02-17 21:06:54 +00:00
|
|
|
const int *r = posho.ptr();
|
2017-03-05 15:44:50 +00:00
|
|
|
for (int i = 0; i < posho.size(); i++) {
|
|
|
|
print_line(itos(i) + " : " + itos(r[i]));
|
2017-01-07 21:25:37 +00:00
|
|
|
}
|
|
|
|
}
|
2017-01-05 22:41:36 +00:00
|
|
|
|
2016-09-15 13:13:28 +00:00
|
|
|
List<String> cmdlargs = OS::get_singleton()->get_cmdline_args();
|
|
|
|
|
|
|
|
if (cmdlargs.empty()) {
|
|
|
|
//try editor!
|
2020-04-01 23:20:12 +00:00
|
|
|
return nullptr;
|
2016-09-15 13:13:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
String test = cmdlargs.back()->get();
|
2019-01-16 09:59:45 +00:00
|
|
|
if (test == "math") {
|
|
|
|
// Not a file name but the test name, abort.
|
|
|
|
// FIXME: This test is ugly as heck, needs fixing :)
|
2020-04-01 23:20:12 +00:00
|
|
|
return nullptr;
|
2019-01-16 09:59:45 +00:00
|
|
|
}
|
2016-09-15 13:13:28 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
FileAccess *fa = FileAccess::open(test, FileAccess::READ);
|
2020-04-01 23:20:12 +00:00
|
|
|
ERR_FAIL_COND_V_MSG(!fa, nullptr, "Could not open file: " + test);
|
2016-09-15 13:13:28 +00:00
|
|
|
|
|
|
|
Vector<uint8_t> buf;
|
|
|
|
int flen = fa->get_len();
|
2017-03-05 15:44:50 +00:00
|
|
|
buf.resize(fa->get_len() + 1);
|
2018-07-25 01:11:03 +00:00
|
|
|
fa->get_buffer(buf.ptrw(), flen);
|
|
|
|
buf.write[flen] = 0;
|
2016-09-15 13:13:28 +00:00
|
|
|
|
|
|
|
String code;
|
2017-03-05 15:44:50 +00:00
|
|
|
code.parse_utf8((const char *)&buf[0]);
|
2016-09-15 13:13:28 +00:00
|
|
|
|
|
|
|
GetClassAndNamespace getclass;
|
|
|
|
if (getclass.parse(code)) {
|
2017-03-05 15:44:50 +00:00
|
|
|
print_line("Parse error: " + getclass.get_error());
|
2016-09-15 13:13:28 +00:00
|
|
|
} else {
|
2017-03-05 15:44:50 +00:00
|
|
|
print_line("Found class: " + getclass.get_class());
|
2016-09-15 13:13:28 +00:00
|
|
|
}
|
|
|
|
|
2016-02-11 03:00:11 +00:00
|
|
|
{
|
2016-10-06 20:36:05 +00:00
|
|
|
Vector<int> hashes;
|
2016-02-11 03:00:11 +00:00
|
|
|
List<StringName> tl;
|
2017-01-03 02:03:46 +00:00
|
|
|
ClassDB::get_class_list(&tl);
|
2016-02-11 03:00:11 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
for (List<StringName>::Element *E = tl.front(); E; E = E->next()) {
|
2016-02-11 03:00:11 +00:00
|
|
|
Vector<uint8_t> m5b = E->get().operator String().md5_buffer();
|
|
|
|
hashes.push_back(hashes.size());
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
for (int i = nearest_shift(hashes.size()); i < 20; i++) {
|
|
|
|
bool success = true;
|
|
|
|
for (int s = 0; s < 10000; s++) {
|
2016-02-11 03:00:11 +00:00
|
|
|
Set<uint32_t> existing;
|
2017-03-05 15:44:50 +00:00
|
|
|
success = true;
|
2016-02-11 03:00:11 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
for (int j = 0; j < hashes.size(); j++) {
|
|
|
|
uint32_t eh = ihash2(ihash3(hashes[j] + ihash(s) + s)) & ((1 << i) - 1);
|
2016-02-11 03:00:11 +00:00
|
|
|
if (existing.has(eh)) {
|
2017-03-05 15:44:50 +00:00
|
|
|
success = false;
|
2016-02-11 03:00:11 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
existing.insert(eh);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (success) {
|
2017-03-05 15:44:50 +00:00
|
|
|
print_line("success at " + itos(i) + "/" + itos(nearest_shift(hashes.size())) + " shift " + itos(s));
|
2016-02-11 03:00:11 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2020-05-14 14:41:43 +00:00
|
|
|
if (success) {
|
2016-02-11 03:00:11 +00:00
|
|
|
break;
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2016-02-11 03:00:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
print_line("DONE");
|
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2019-01-16 09:59:45 +00:00
|
|
|
{
|
2017-03-05 15:44:50 +00:00
|
|
|
print_line("NUM: " + itos(-128));
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
{
|
2017-03-05 15:44:50 +00:00
|
|
|
Vector3 v(1, 2, 3);
|
2014-02-10 01:10:30 +00:00
|
|
|
v.normalize();
|
2017-03-05 15:44:50 +00:00
|
|
|
float a = 0.3;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
Basis m(v, a);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
Vector3 v2(7, 3, 1);
|
2014-02-10 01:10:30 +00:00
|
|
|
v2.normalize();
|
2017-03-05 15:44:50 +00:00
|
|
|
float a2 = 0.8;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
Basis m2(v2, a2);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
Quat q = m;
|
|
|
|
Quat q2 = m2;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-01-11 03:52:51 +00:00
|
|
|
Basis m3 = m.inverse() * m2;
|
2017-03-05 15:44:50 +00:00
|
|
|
Quat q3 = (q.inverse() * q2); //.normalized();
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
print_line(Quat(m3));
|
|
|
|
print_line(q3);
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
print_line("before v: " + v + " a: " + rtos(a));
|
2017-04-05 22:47:13 +00:00
|
|
|
q.get_axis_angle(v, a);
|
2017-03-05 15:44:50 +00:00
|
|
|
print_line("after v: " + v + " a: " + rtos(a));
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
String ret;
|
|
|
|
|
|
|
|
List<String> args;
|
|
|
|
args.push_back("-l");
|
2020-04-01 23:20:12 +00:00
|
|
|
Error err = OS::get_singleton()->execute("/bin/ls", args, true, nullptr, &ret);
|
2017-03-05 15:44:50 +00:00
|
|
|
print_line("error: " + itos(err));
|
2014-02-10 01:10:30 +00:00
|
|
|
print_line(ret);
|
|
|
|
|
2017-01-11 03:52:51 +00:00
|
|
|
Basis m3;
|
2017-03-05 15:44:50 +00:00
|
|
|
m3.rotate(Vector3(1, 0, 0), 0.2);
|
|
|
|
m3.rotate(Vector3(0, 1, 0), 1.77);
|
|
|
|
m3.rotate(Vector3(0, 0, 1), 212);
|
2017-01-11 03:52:51 +00:00
|
|
|
Basis m32;
|
2014-02-10 01:10:30 +00:00
|
|
|
m32.set_euler(m3.get_euler());
|
2017-03-05 15:44:50 +00:00
|
|
|
print_line("ELEULEEEEEEEEEEEEEEEEEER: " + m3.get_euler() + " vs " + m32.get_euler());
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
{
|
|
|
|
Dictionary d;
|
2017-03-05 15:44:50 +00:00
|
|
|
d["momo"] = 1;
|
|
|
|
Dictionary b = d;
|
|
|
|
b["44"] = 4;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2020-05-25 17:20:45 +00:00
|
|
|
print_line("inters: " + rtos(Geometry2D::segment_intersects_circle(Vector2(-5, 0), Vector2(-2, 0), Vector2(), 1.0)));
|
2017-03-05 15:44:50 +00:00
|
|
|
|
|
|
|
print_line("cross: " + Vector3(1, 2, 3).cross(Vector3(4, 5, 7)));
|
|
|
|
print_line("dot: " + rtos(Vector3(1, 2, 3).dot(Vector3(4, 5, 7))));
|
|
|
|
print_line("abs: " + Vector3(-1, 2, -3).abs());
|
|
|
|
print_line("distance_to: " + rtos(Vector3(1, 2, 3).distance_to(Vector3(4, 5, 7))));
|
|
|
|
print_line("distance_squared_to: " + rtos(Vector3(1, 2, 3).distance_squared_to(Vector3(4, 5, 7))));
|
|
|
|
print_line("plus: " + (Vector3(1, 2, 3) + Vector3(Vector3(4, 5, 7))));
|
|
|
|
print_line("minus: " + (Vector3(1, 2, 3) - Vector3(Vector3(4, 5, 7))));
|
|
|
|
print_line("mul: " + (Vector3(1, 2, 3) * Vector3(Vector3(4, 5, 7))));
|
|
|
|
print_line("div: " + (Vector3(1, 2, 3) / Vector3(Vector3(4, 5, 7))));
|
2019-10-05 07:30:13 +00:00
|
|
|
print_line("mul scalar: " + (Vector3(1, 2, 3) * 2.0));
|
|
|
|
print_line("premul scalar: " + (2.0 * Vector3(1, 2, 3)));
|
2017-03-05 15:44:50 +00:00
|
|
|
print_line("div scalar: " + (Vector3(1, 2, 3) / 3.0));
|
|
|
|
print_line("length: " + rtos(Vector3(1, 2, 3).length()));
|
|
|
|
print_line("length squared: " + rtos(Vector3(1, 2, 3).length_squared()));
|
|
|
|
print_line("normalized: " + Vector3(1, 2, 3).normalized());
|
|
|
|
print_line("inverse: " + Vector3(1, 2, 3).inverse());
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
{
|
2017-03-05 15:44:50 +00:00
|
|
|
Vector3 v(4, 5, 7);
|
2014-02-10 01:10:30 +00:00
|
|
|
v.normalize();
|
2017-03-05 15:44:50 +00:00
|
|
|
print_line("normalize: " + v);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
{
|
2017-03-05 15:44:50 +00:00
|
|
|
Vector3 v(4, 5, 7);
|
|
|
|
v += Vector3(1, 2, 3);
|
|
|
|
print_line("+=: " + v);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
{
|
2017-03-05 15:44:50 +00:00
|
|
|
Vector3 v(4, 5, 7);
|
|
|
|
v -= Vector3(1, 2, 3);
|
|
|
|
print_line("-=: " + v);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
{
|
2017-03-05 15:44:50 +00:00
|
|
|
Vector3 v(4, 5, 7);
|
|
|
|
v *= Vector3(1, 2, 3);
|
|
|
|
print_line("*=: " + v);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
{
|
2017-03-05 15:44:50 +00:00
|
|
|
Vector3 v(4, 5, 7);
|
|
|
|
v /= Vector3(1, 2, 3);
|
|
|
|
print_line("/=: " + v);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
{
|
2017-03-05 15:44:50 +00:00
|
|
|
Vector3 v(4, 5, 7);
|
|
|
|
v *= 2.0;
|
|
|
|
print_line("scalar *=: " + v);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
{
|
2017-03-05 15:44:50 +00:00
|
|
|
Vector3 v(4, 5, 7);
|
|
|
|
v /= 2.0;
|
|
|
|
print_line("scalar /=: " + v);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2020-04-01 23:20:12 +00:00
|
|
|
return nullptr;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
2020-05-14 12:29:06 +00:00
|
|
|
|
2017-12-06 20:36:34 +00:00
|
|
|
} // namespace TestMath
|