2014-02-10 02:10:30 +01:00
|
|
|
/*************************************************************************/
|
|
|
|
/* test_misc.cpp */
|
|
|
|
/*************************************************************************/
|
|
|
|
/* This file is part of: */
|
|
|
|
/* GODOT ENGINE */
|
|
|
|
/* http://www.godotengine.org */
|
|
|
|
/*************************************************************************/
|
2016-01-11 21:34:22 +01:00
|
|
|
/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
|
2014-02-10 02:10:30 +01: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. */
|
|
|
|
/*************************************************************************/
|
|
|
|
#include "test_misc.h"
|
|
|
|
#include "math_funcs.h"
|
2017-03-19 00:36:26 +01:00
|
|
|
#include "os/main_loop.h"
|
2014-02-10 02:10:30 +01:00
|
|
|
#include "print_string.h"
|
2017-03-19 00:36:26 +01:00
|
|
|
#include "servers/visual_server.h"
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
namespace TestMisc {
|
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
struct ConvexTestResult {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
Vector3 edgeA[2];
|
|
|
|
Vector3 edgeB[2];
|
|
|
|
bool valid;
|
|
|
|
Vector3 contactA;
|
|
|
|
Vector3 contactB;
|
|
|
|
Vector3 contactNormal;
|
|
|
|
float depth;
|
|
|
|
|
|
|
|
/*
|
|
|
|
Vector3 contactA;
|
|
|
|
Vector3 contactB;
|
|
|
|
Vector3 contactNormal;
|
|
|
|
Vector3 contactX;
|
|
|
|
Vector3 contactY;
|
|
|
|
Vector3 edgeA[2];
|
|
|
|
Vector3 edgeB[2];
|
|
|
|
float depth;
|
|
|
|
bool valid;
|
|
|
|
bool isEdgeEdge;
|
|
|
|
bool needTransform;
|
|
|
|
neBool ComputerEdgeContactPoint(ConvexTestResult & res);
|
|
|
|
neBool ComputerEdgeContactPoint2(float & au, float & bu);
|
|
|
|
void Reverse()
|
|
|
|
{
|
|
|
|
neSwap(contactA, contactB);
|
|
|
|
contactNormal *= -1.0f;
|
|
|
|
}*/
|
2017-03-19 00:36:26 +01:00
|
|
|
bool ComputerEdgeContactPoint2(float &au, float &bu);
|
2014-02-10 02:10:30 +01:00
|
|
|
};
|
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
bool ConvexTestResult::ComputerEdgeContactPoint2(float &au, float &bu) {
|
2014-02-10 02:10:30 +01:00
|
|
|
float d1343, d4321, d1321, d4343, d2121;
|
|
|
|
float numer, denom;
|
|
|
|
|
|
|
|
Vector3 p13;
|
|
|
|
Vector3 p43;
|
|
|
|
Vector3 p21;
|
|
|
|
Vector3 diff;
|
|
|
|
|
|
|
|
p13 = (edgeA[0]) - (edgeB[0]);
|
|
|
|
p43 = (edgeB[1]) - (edgeB[0]);
|
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
if (p43.length_squared() < CMP_EPSILON2) {
|
2014-02-10 02:10:30 +01:00
|
|
|
valid = false;
|
|
|
|
goto ComputerEdgeContactPoint2_Exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
p21 = (edgeA[1]) - (edgeA[0]);
|
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
if (p21.length_squared() < CMP_EPSILON2) {
|
2014-02-10 02:10:30 +01:00
|
|
|
valid = false;
|
|
|
|
goto ComputerEdgeContactPoint2_Exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
d1343 = p13.dot(p43);
|
|
|
|
d4321 = p43.dot(p21);
|
|
|
|
d1321 = p13.dot(p21);
|
|
|
|
d4343 = p43.dot(p43);
|
|
|
|
d2121 = p21.dot(p21);
|
|
|
|
|
|
|
|
denom = d2121 * d4343 - d4321 * d4321;
|
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
if (ABS(denom) < CMP_EPSILON) {
|
2014-02-10 02:10:30 +01:00
|
|
|
valid = false;
|
|
|
|
|
|
|
|
goto ComputerEdgeContactPoint2_Exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
numer = d1343 * d4321 - d1321 * d4343;
|
|
|
|
au = numer / denom;
|
|
|
|
bu = (d1343 + d4321 * (au)) / d4343;
|
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
if (au < 0.0f || au >= 1.0f) {
|
2014-02-10 02:10:30 +01:00
|
|
|
valid = false;
|
2017-03-19 00:36:26 +01:00
|
|
|
} else if (bu < 0.0f || bu >= 1.0f) {
|
2014-02-10 02:10:30 +01:00
|
|
|
valid = false;
|
2017-03-19 00:36:26 +01:00
|
|
|
} else {
|
2014-02-10 02:10:30 +01:00
|
|
|
valid = true;
|
|
|
|
}
|
|
|
|
{
|
|
|
|
Vector3 tmpv;
|
|
|
|
|
|
|
|
tmpv = p21 * au;
|
|
|
|
contactA = (edgeA[0]) + tmpv;
|
|
|
|
|
|
|
|
tmpv = p43 * bu;
|
|
|
|
contactB = (edgeB[0]) + tmpv;
|
|
|
|
}
|
|
|
|
|
|
|
|
diff = contactA - contactB;
|
|
|
|
|
|
|
|
depth = Math::sqrt(diff.dot(diff));
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
ComputerEdgeContactPoint2_Exit:
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct neCollisionResult {
|
|
|
|
|
|
|
|
float depth;
|
|
|
|
bool penetrate;
|
|
|
|
Matrix3 collisionFrame;
|
|
|
|
Vector3 contactA;
|
|
|
|
Vector3 contactB;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct TConvex {
|
|
|
|
|
|
|
|
float radius;
|
|
|
|
float half_height;
|
|
|
|
float CylinderRadius() const { return radius; }
|
|
|
|
float CylinderHalfHeight() const { return half_height; }
|
|
|
|
};
|
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
float GetDistanceFromLine2(Vector3 v, Vector3 &project, const Vector3 &pointA, const Vector3 &pointB) {
|
2014-02-10 02:10:30 +01:00
|
|
|
Vector3 ba = pointB - pointA;
|
|
|
|
|
|
|
|
float len = ba.length();
|
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
if (len < CMP_EPSILON)
|
|
|
|
ba = Vector3();
|
2014-02-10 02:10:30 +01:00
|
|
|
else
|
|
|
|
ba *= 1.0f / len;
|
|
|
|
|
|
|
|
Vector3 pa = v - pointA;
|
|
|
|
|
|
|
|
float k = pa.dot(ba);
|
|
|
|
|
|
|
|
project = pointA + ba * k;
|
|
|
|
|
|
|
|
Vector3 diff = v - project;
|
|
|
|
|
|
|
|
return diff.length();
|
|
|
|
}
|
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
void TestCylinderVertEdge(neCollisionResult &result, Vector3 &edgeA1, Vector3 &edgeA2, Vector3 &vertB,
|
|
|
|
TConvex &cA, TConvex &cB, Transform &transA, Transform &transB, bool flip) {
|
2014-02-10 02:10:30 +01:00
|
|
|
Vector3 project;
|
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
float dist = GetDistanceFromLine2(vertB, project, edgeA1, edgeA2);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
float depth = cA.CylinderRadius() + cB.CylinderRadius() - dist;
|
|
|
|
|
|
|
|
if (depth <= 0.0f)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (depth <= result.depth)
|
|
|
|
return;
|
|
|
|
|
|
|
|
result.penetrate = true;
|
|
|
|
|
|
|
|
result.depth = depth;
|
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
if (!flip) {
|
|
|
|
result.collisionFrame.set_axis(2, (project - vertB).normalized());
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
result.contactA = project - result.collisionFrame.get_axis(2) * cA.CylinderRadius();
|
|
|
|
|
|
|
|
result.contactB = vertB + result.collisionFrame.get_axis(2) * cB.CylinderRadius();
|
2017-03-19 00:36:26 +01:00
|
|
|
} else {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
result.collisionFrame.set_axis(2, (vertB - project).normalized());
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
result.contactA = vertB - result.collisionFrame.get_axis(2) * cB.CylinderRadius();
|
|
|
|
|
|
|
|
result.contactB = project + result.collisionFrame.get_axis(2) * cA.CylinderRadius();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
void TestCylinderVertVert(neCollisionResult &result, Vector3 &vertA, Vector3 &vertB,
|
|
|
|
TConvex &cA, TConvex &cB, Transform &transA, Transform &transB) {
|
2014-02-10 02:10:30 +01:00
|
|
|
Vector3 diff = vertA - vertB;
|
|
|
|
|
|
|
|
float dist = diff.length();
|
|
|
|
|
|
|
|
float depth = cA.CylinderRadius() + cB.CylinderRadius() - dist;
|
|
|
|
|
|
|
|
if (depth <= 0.0f)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (depth <= result.depth)
|
|
|
|
return;
|
|
|
|
|
|
|
|
result.penetrate = true;
|
|
|
|
|
|
|
|
result.depth = depth;
|
|
|
|
|
|
|
|
result.collisionFrame.set_axis(2, diff * (1.0f / dist));
|
|
|
|
|
|
|
|
result.contactA = vertA - result.collisionFrame.get_axis(2) * cA.CylinderRadius();
|
|
|
|
|
|
|
|
result.contactB = vertB + result.collisionFrame.get_axis(2) * cB.CylinderRadius();
|
|
|
|
}
|
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
void Cylinder2CylinderTest(neCollisionResult &result, TConvex &cA, Transform &transA, TConvex &cB, Transform &transB) {
|
2014-02-10 02:10:30 +01:00
|
|
|
result.penetrate = false;
|
|
|
|
|
|
|
|
Vector3 dir = transA.basis.get_axis(1).cross(transB.basis.get_axis(1));
|
|
|
|
|
|
|
|
float len = dir.length();
|
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
// bool isParallel = len<CMP_EPSILON;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
// int doVertCheck = 0;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
ConvexTestResult cr;
|
|
|
|
|
|
|
|
cr.edgeA[0] = transA.origin + transA.basis.get_axis(1) * cA.CylinderHalfHeight();
|
|
|
|
cr.edgeA[1] = transA.origin - transA.basis.get_axis(1) * cA.CylinderHalfHeight();
|
|
|
|
cr.edgeB[0] = transB.origin + transB.basis.get_axis(1) * cB.CylinderHalfHeight();
|
|
|
|
cr.edgeB[1] = transB.origin - transB.basis.get_axis(1) * cB.CylinderHalfHeight();
|
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
// float dot = transA.basis.get_axis(1).dot(transB.basis.get_axis(1));
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
if (len > CMP_EPSILON) {
|
2014-02-10 02:10:30 +01:00
|
|
|
float au, bu;
|
|
|
|
|
|
|
|
cr.ComputerEdgeContactPoint2(au, bu);
|
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
if (cr.valid) {
|
2014-02-10 02:10:30 +01:00
|
|
|
float depth = cA.CylinderRadius() + cB.CylinderRadius() - cr.depth;
|
|
|
|
|
|
|
|
if (depth <= 0.0f)
|
|
|
|
return;
|
|
|
|
|
|
|
|
result.depth = depth;
|
|
|
|
|
|
|
|
result.penetrate = true;
|
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
result.collisionFrame.set_axis(2, (cr.contactA - cr.contactB) * (1.0f / cr.depth));
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
result.contactA = cr.contactA - result.collisionFrame.get_axis(2) * cA.CylinderRadius();
|
|
|
|
|
|
|
|
result.contactB = cr.contactB + result.collisionFrame.get_axis(2) * cB.CylinderRadius();
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
result.depth = -1.0e6f;
|
|
|
|
|
|
|
|
int i;
|
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
for (i = 0; i < 2; i++) {
|
2014-02-10 02:10:30 +01:00
|
|
|
//project onto edge b
|
|
|
|
|
|
|
|
Vector3 diff = cr.edgeA[i] - cr.edgeB[1];
|
|
|
|
|
|
|
|
float dot = diff.dot(transB.basis.get_axis(1));
|
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
if (dot < 0.0f) {
|
2014-02-10 02:10:30 +01:00
|
|
|
TestCylinderVertVert(result, cr.edgeA[i], cr.edgeB[1], cA, cB, transA, transB);
|
2017-03-19 00:36:26 +01:00
|
|
|
} else if (dot > (2.0f * cB.CylinderHalfHeight())) {
|
2014-02-10 02:10:30 +01:00
|
|
|
TestCylinderVertVert(result, cr.edgeA[i], cr.edgeB[0], cA, cB, transA, transB);
|
2017-03-19 00:36:26 +01:00
|
|
|
} else {
|
2014-02-10 02:10:30 +01:00
|
|
|
TestCylinderVertEdge(result, cr.edgeB[0], cr.edgeB[1], cr.edgeA[i], cB, cA, transB, transA, true);
|
|
|
|
}
|
|
|
|
}
|
2017-03-19 00:36:26 +01:00
|
|
|
for (i = 0; i < 2; i++) {
|
2014-02-10 02:10:30 +01:00
|
|
|
//project onto edge b
|
|
|
|
|
|
|
|
Vector3 diff = cr.edgeB[i] - cr.edgeA[1];
|
|
|
|
|
|
|
|
float dot = diff.dot(transA.basis.get_axis(1));
|
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
if (dot < 0.0f) {
|
2014-02-10 02:10:30 +01:00
|
|
|
TestCylinderVertVert(result, cr.edgeB[i], cr.edgeA[1], cA, cB, transA, transB);
|
2017-03-19 00:36:26 +01:00
|
|
|
} else if (dot > (2.0f * cB.CylinderHalfHeight())) {
|
2014-02-10 02:10:30 +01:00
|
|
|
TestCylinderVertVert(result, cr.edgeB[i], cr.edgeA[0], cA, cB, transA, transB);
|
2017-03-19 00:36:26 +01:00
|
|
|
} else {
|
2014-02-10 02:10:30 +01:00
|
|
|
TestCylinderVertEdge(result, cr.edgeA[0], cr.edgeA[1], cr.edgeB[i], cA, cB, transA, transB, false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class TestMainLoop : public MainLoop {
|
|
|
|
|
|
|
|
RID meshA;
|
|
|
|
RID meshB;
|
|
|
|
RID poly;
|
|
|
|
RID instance;
|
|
|
|
RID camera;
|
|
|
|
RID viewport;
|
|
|
|
RID boxA;
|
|
|
|
RID boxB;
|
|
|
|
RID scenario;
|
|
|
|
|
|
|
|
Transform rot_a;
|
|
|
|
Transform rot_b;
|
|
|
|
|
|
|
|
bool quit;
|
2017-03-19 00:36:26 +01:00
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
public:
|
2017-03-19 00:36:26 +01:00
|
|
|
virtual void input_event(const InputEvent &p_event) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
if (p_event.type == InputEvent::MOUSE_MOTION && p_event.mouse_motion.button_mask & BUTTON_MASK_LEFT) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
rot_b.origin.y += -p_event.mouse_motion.relative_y / 100.0;
|
|
|
|
rot_b.origin.x += p_event.mouse_motion.relative_x / 100.0;
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
2017-03-19 00:36:26 +01:00
|
|
|
if (p_event.type == InputEvent::MOUSE_MOTION && p_event.mouse_motion.button_mask & BUTTON_MASK_MIDDLE) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
//rot_b.origin.x+=-p_event.mouse_motion.relative_y/100.0;
|
2017-03-19 00:36:26 +01:00
|
|
|
rot_b.origin.z += p_event.mouse_motion.relative_x / 100.0;
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
2017-03-19 00:36:26 +01:00
|
|
|
if (p_event.type == InputEvent::MOUSE_MOTION && p_event.mouse_motion.button_mask & BUTTON_MASK_RIGHT) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
float rot_x = -p_event.mouse_motion.relative_y / 100.0;
|
|
|
|
float rot_y = p_event.mouse_motion.relative_x / 100.0;
|
|
|
|
rot_b.basis = rot_b.basis * Matrix3(Vector3(1, 0, 0), rot_x) * Matrix3(Vector3(0, 1, 0), rot_y);
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
virtual void request_quit() {
|
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
quit = true;
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
virtual void init() {
|
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
VisualServer *vs = VisualServer::get_singleton();
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
camera = vs->camera_create();
|
|
|
|
|
|
|
|
viewport = vs->viewport_create();
|
|
|
|
vs->viewport_attach_to_screen(viewport);
|
2017-03-19 00:36:26 +01:00
|
|
|
vs->viewport_attach_camera(viewport, camera);
|
|
|
|
vs->camera_set_transform(camera, Transform(Matrix3(), Vector3(0, 0, 3)));
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
/* CONVEX SHAPE */
|
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
DVector<Plane> cylinder_planes = Geometry::build_cylinder_planes(0.5, 2, 9, Vector3::AXIS_Y);
|
2014-02-10 02:10:30 +01:00
|
|
|
RID cylinder_material = vs->fixed_material_create();
|
2017-03-19 00:36:26 +01:00
|
|
|
vs->fixed_material_set_param(cylinder_material, VisualServer::FIXED_MATERIAL_PARAM_DIFFUSE, Color(0.8, 0.2, 0.9));
|
|
|
|
vs->material_set_flag(cylinder_material, VisualServer::MATERIAL_FLAG_ONTOP, true);
|
2014-06-28 04:21:45 +02:00
|
|
|
//vs->material_set_flag( cylinder_material, VisualServer::MATERIAL_FLAG_WIREFRAME,true);
|
2017-03-19 00:36:26 +01:00
|
|
|
vs->material_set_flag(cylinder_material, VisualServer::MATERIAL_FLAG_DOUBLE_SIDED, true);
|
|
|
|
vs->material_set_flag(cylinder_material, VisualServer::MATERIAL_FLAG_UNSHADED, true);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
RID cylinder_mesh = vs->mesh_create();
|
|
|
|
Geometry::MeshData cylinder_data = Geometry::build_convex_mesh(cylinder_planes);
|
2017-03-19 00:36:26 +01:00
|
|
|
vs->mesh_add_surface_from_mesh_data(cylinder_mesh, cylinder_data);
|
|
|
|
vs->mesh_surface_set_material(cylinder_mesh, 0, cylinder_material);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
meshA = vs->instance_create2(cylinder_mesh, scenario);
|
|
|
|
meshB = vs->instance_create2(cylinder_mesh, scenario);
|
|
|
|
boxA = vs->instance_create2(vs->get_test_cube(), scenario);
|
|
|
|
boxB = vs->instance_create2(vs->get_test_cube(), scenario);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
RID lightaux = vs->light_create( VisualServer::LIGHT_OMNI );
|
|
|
|
vs->light_set_var( lightaux, VisualServer::LIGHT_VAR_RADIUS, 80 );
|
|
|
|
vs->light_set_var( lightaux, VisualServer::LIGHT_VAR_ATTENUATION, 1 );
|
|
|
|
vs->light_set_var( lightaux, VisualServer::LIGHT_VAR_ENERGY, 1.5 );
|
|
|
|
light = vs->instance_create2( lightaux );
|
|
|
|
*/
|
2017-03-19 00:36:26 +01:00
|
|
|
RID lightaux = vs->light_create(VisualServer::LIGHT_DIRECTIONAL);
|
2014-06-28 04:21:45 +02:00
|
|
|
//vs->light_set_color( lightaux, VisualServer::LIGHT_COLOR_AMBIENT, Color(0.0,0.0,0.0) );
|
2014-02-10 02:10:30 +01:00
|
|
|
//vs->light_set_shadow( lightaux, true );
|
2017-03-19 00:36:26 +01:00
|
|
|
RID light = vs->instance_create2(lightaux, scenario);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
//rot_a=Transform(Matrix3(Vector3(1,0,0),Math_PI/2.0),Vector3());
|
2017-03-19 00:36:26 +01:00
|
|
|
rot_b = Transform(Matrix3(), Vector3(2, 0, 0));
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
//rot_x=0;
|
|
|
|
//rot_y=0;
|
2017-03-19 00:36:26 +01:00
|
|
|
quit = false;
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
virtual bool idle(float p_time) {
|
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
VisualServer *vs = VisualServer::get_singleton();
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
vs->instance_set_transform(meshA, rot_a);
|
|
|
|
vs->instance_set_transform(meshB, rot_b);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
neCollisionResult res;
|
|
|
|
TConvex a;
|
2017-03-19 00:36:26 +01:00
|
|
|
a.radius = 0.5;
|
|
|
|
a.half_height = 1;
|
|
|
|
Cylinder2CylinderTest(res, a, rot_a, a, rot_b);
|
2014-02-10 02:10:30 +01:00
|
|
|
if (res.penetrate) {
|
|
|
|
|
|
|
|
Matrix3 scale;
|
2017-03-19 00:36:26 +01:00
|
|
|
scale.scale(Vector3(0.1, 0.1, 0.1));
|
|
|
|
vs->instance_set_transform(boxA, Transform(scale, res.contactA));
|
|
|
|
vs->instance_set_transform(boxB, Transform(scale, res.contactB));
|
|
|
|
print_line("depth: " + rtos(res.depth));
|
|
|
|
} else {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
Matrix3 scale;
|
|
|
|
scale.scale(Vector3());
|
2017-03-19 00:36:26 +01:00
|
|
|
vs->instance_set_transform(boxA, Transform(scale, res.contactA));
|
|
|
|
vs->instance_set_transform(boxB, Transform(scale, res.contactB));
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
2017-03-19 00:36:26 +01:00
|
|
|
print_line("collided: " + itos(res.penetrate));
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual bool iteration(float p_time) {
|
|
|
|
|
|
|
|
return quit;
|
|
|
|
}
|
|
|
|
virtual void finish() {
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
MainLoop *test() {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
return memnew(TestMainLoop);
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
}
|