/* Copyright (c) 2015 Alex Diener This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. Alex Diener alex@ludobloom.com */ #include "collision/CollisionCircle.h" #include "collision/CollisionRect2D.h" #include "collision/CollisionShared.h" #include "gamemath/Matrix4x4f.h" #include "gamemath/MouseCoordinateTransforms.h" #include "gamemath/Vector2f.h" #include "gamemath/VectorConversions.h" #include "renderer/VertexTypes.h" #include "shadercollection/ShaderCollection.h" #include "shell/Shell.h" #include "shell/ShellKeyCodes.h" #include "testharness/SingleFrameScreen2D.h" #include "testharness/SharedEvents.h" #include "testharness/TestHarness_globals.h" #include #include #include #define stemobject_implementation SingleFrameScreen2D stemobject_vtable_begin(); stemobject_vtable_entry(dispose); stemobject_vtable_entry(activate); stemobject_vtable_entry(deactivate); stemobject_vtable_end(); SingleFrameScreen2D * SingleFrameScreen2D_create(Renderer * renderer) { stemobject_create_implementation(init, renderer) } #define ARROW_RADIUS 0.375f static void writeArrowVertices(Vector2x position, Vector3x normal, VertexIO * vertexIO) { struct vertex_p2f_t2f_c4f vertices[4], vertex = {.texCoords = {0.0f, 0.0f}, .color = {1.0f, 0.0f, 0.0f, 1.0f}}; Vector2f positionf = VECTOR2f(xtof(position.x), xtof(position.y)); Vector2f normalf = VECTOR2f(xtof(normal.x), xtof(normal.y)); vertex.position[0] = positionf.x - normalf.x * ARROW_RADIUS; vertex.position[1] = positionf.y - normalf.y * ARROW_RADIUS; vertices[0] = vertex; vertex.position[0] = positionf.x + normalf.x * ARROW_RADIUS; vertex.position[1] = positionf.y + normalf.y * ARROW_RADIUS; vertices[1] = vertex; vertex.position[0] = positionf.x + normalf.y * ARROW_RADIUS * 0.5f; vertex.position[1] = positionf.y - normalf.x * ARROW_RADIUS * 0.5f; vertices[2] = vertex; vertex.position[0] = positionf.x - normalf.y * ARROW_RADIUS * 0.5f; vertex.position[1] = positionf.y + normalf.x * ARROW_RADIUS * 0.5f; vertices[3] = vertex; uint32_t indexes[6] = {0, 1, 1, 2, 1, 3}; VertexIO_writeIndexedVertices(vertexIO, sizeof(vertices) / sizeof(vertices[0]), vertices, sizeof(indexes) / sizeof(indexes[0]), indexes); } #define CIRCLE_TESSELATIONS 64 #define COLOR_RECT_LAST_POSITION COLOR4f(0.5f, 0.25f, 0.0f, 1.0f) #define COLOR_RECT_LAST_POSITION_HIGHLIGHT COLOR4f(0.75f, 0.625f, 0.125f, 1.0f) #define COLOR_RECT_POSITION COLOR4f(1.0f, 1.0f, 0.0f, 1.0f) #define COLOR_RECT_POSITION_HIGHLIGHT COLOR4f(1.0f, 1.0f, 0.875f, 1.0f) #define COLOR_RECT_POSITION_COLLIDING COLOR4f(1.0f, 0.0f, 0.0f, 1.0f) #define COLOR_RECT_POSITION_COLLIDING_HIGHLIGHT COLOR4f(1.0f, 0.75f, 0.75f, 1.0f) #define COLOR_CIRCLE_LAST_POSITION COLOR4f(0.0f, 0.25f, 0.5f, 1.0f) #define COLOR_CIRCLE_LAST_POSITION_HIGHLIGHT COLOR4f(0.125f, 0.625f, 0.75f, 1.0f) #define COLOR_CIRCLE_POSITION COLOR4f(0.0f, 1.0f, 1.0f, 1.0f) #define COLOR_CIRCLE_POSITION_HIGHLIGHT COLOR4f(0.875f, 1.0f, 1.0f, 1.0f) #define COLOR_CIRCLE_POSITION_COLLIDING COLOR4f(1.0f, 0.0f, 0.0f, 1.0f) #define COLOR_CIRCLE_POSITION_COLLIDING_HIGHLIGHT COLOR4f(1.0f, 0.75f, 0.75f, 1.0f) static void setVertexColor(struct vertex_p2f_t2f_c4f * vertex, Color4f color) { vertex->color[0] = color.red; vertex->color[1] = color.green; vertex->color[2] = color.blue; vertex->color[3] = color.alpha; } static void writeCollisionObjectVertices(Renderable * renderable, VertexIO * vertexIO, void * context) { SingleFrameScreen2D * self = context; struct vertex_p2f_t2f_c4f vertex = {.texCoords = {0.0f, 0.0f}}; for (size_t objectIndex = 0; objectIndex < OBJECT_COUNT_2D; objectIndex++) { CollisionObject * object = self->objects[objectIndex]; CollisionRecord collision; bool colliding = CollisionResolver_querySingle(self->resolver, object, &collision); switch (call_virtual(getShapeType, object)) { case COLLISION_SHAPE_RECT_2D: { CollisionRect2D * rect = (CollisionRect2D *) object; struct vertex_p2f_t2f_c4f vertices[8]; uint32_t indexes[8 + 4 * rect->solidLeft + 4 * rect->solidRight + 4 * rect->solidBottom + 4 * rect->solidTop]; unsigned int indexCount = 0; if (objectIndex == self->selectedObjectIndex) { setVertexColor(&vertex, COLOR_RECT_LAST_POSITION_HIGHLIGHT); } else { setVertexColor(&vertex, COLOR_RECT_LAST_POSITION); } vertex.position[0] = xtof(rect->lastPosition.x); vertex.position[1] = xtof(rect->lastPosition.y); vertices[0] = vertex; vertex.position[0] = xtof(rect->lastPosition.x + rect->lastSize.x); vertices[1] = vertex; vertex.position[1] = xtof(rect->lastPosition.y + rect->lastSize.y); vertices[2] = vertex; vertex.position[0] = xtof(rect->lastPosition.x); vertices[3] = vertex; if (colliding) { if (objectIndex == self->selectedObjectIndex) { setVertexColor(&vertex, COLOR_RECT_POSITION_COLLIDING_HIGHLIGHT); } else { setVertexColor(&vertex, COLOR_RECT_POSITION_COLLIDING); } } else { if (objectIndex == self->selectedObjectIndex) { setVertexColor(&vertex, COLOR_RECT_POSITION_HIGHLIGHT); } else { setVertexColor(&vertex, COLOR_RECT_POSITION); } } vertex.position[0] = xtof(rect->position.x); vertex.position[1] = xtof(rect->position.y); vertices[4] = vertex; vertex.position[0] = xtof(rect->position.x + rect->size.x); vertices[5] = vertex; vertex.position[1] = xtof(rect->position.y + rect->size.y); vertices[6] = vertex; vertex.position[0] = xtof(rect->position.x); vertices[7] = vertex; bool solid[4] = {rect->solidBottom, rect->solidRight, rect->solidTop, rect->solidLeft}; for (unsigned int vertexIndex = 0; vertexIndex < 4; vertexIndex++) { if (solid[vertexIndex]) { indexes[indexCount++] = vertexIndex; indexes[indexCount++] = (vertexIndex + 1) % 4; } } for (unsigned int vertexIndex = 0; vertexIndex < 4; vertexIndex++) { indexes[indexCount++] = 0 + vertexIndex; indexes[indexCount++] = 4 + vertexIndex; } for (unsigned int vertexIndex = 0; vertexIndex < 4; vertexIndex++) { if (solid[vertexIndex]) { indexes[indexCount++] = 4 + vertexIndex; indexes[indexCount++] = 4 + (vertexIndex + 1) % 4; } } VertexIO_writeIndexedVertices(vertexIO, sizeof(vertices) / sizeof(vertices[0]), vertices, sizeof(indexes) / sizeof(indexes[0]), indexes); if (colliding) { Vector2x collidingPosition = Vector2x_interpolate(rect->lastPosition, rect->position, collision.time); Vector2x collidingSize = Vector2x_interpolate(rect->lastSize, rect->size, collision.time); struct vertex_p2f_t2f_c4f vertices[4]; uint32_t indexes[2 * rect->solidLeft + 2 * rect->solidRight + 2 * rect->solidBottom + 2 * rect->solidTop]; unsigned int indexCount = 0; if (objectIndex == self->selectedObjectIndex) { setVertexColor(&vertex, COLOR_RECT_POSITION_HIGHLIGHT); } else { setVertexColor(&vertex, COLOR_RECT_POSITION); } vertex.position[0] = xtof(collidingPosition.x); vertex.position[1] = xtof(collidingPosition.y); vertices[0] = vertex; vertex.position[0] = xtof(collidingPosition.x + collidingSize.x); vertices[1] = vertex; vertex.position[1] = xtof(collidingPosition.y + collidingSize.y); vertices[2] = vertex; vertex.position[0] = xtof(collidingPosition.x); vertices[3] = vertex; bool solid[4] = {rect->solidBottom, rect->solidRight, rect->solidTop, rect->solidLeft}; for (unsigned int vertexIndex = 0; vertexIndex < 4; vertexIndex++) { if (solid[vertexIndex]) { indexes[indexCount++] = vertexIndex; indexes[indexCount++] = (vertexIndex + 1) % 4; } } VertexIO_writeIndexedVertices(vertexIO, sizeof(vertices) / sizeof(vertices[0]), vertices, sizeof(indexes) / sizeof(indexes[0]), indexes); writeArrowVertices(VECTOR2x(collidingPosition.x + collidingSize.x / 2, collidingPosition.y + collidingSize.y / 2), collision.normal, vertexIO); } break; } case COLLISION_SHAPE_CIRCLE: { CollisionCircle * circle = (CollisionCircle *) object; struct vertex_p2f_t2f_c4f vertices[CIRCLE_TESSELATIONS * 2]; uint32_t indexes[CIRCLE_TESSELATIONS * 4 + 4]; if (objectIndex == self->selectedObjectIndex) { setVertexColor(&vertex, COLOR_CIRCLE_LAST_POSITION_HIGHLIGHT); } else { setVertexColor(&vertex, COLOR_CIRCLE_LAST_POSITION); } for (unsigned int tesselationIndex = 0; tesselationIndex < CIRCLE_TESSELATIONS; tesselationIndex++) { vertex.position[0] = xtof(circle->lastPosition.x) + xtof(circle->radius) * cos(tesselationIndex * M_PI * 2 / CIRCLE_TESSELATIONS); vertex.position[1] = xtof(circle->lastPosition.y) + xtof(circle->radius) * sin(tesselationIndex * M_PI * 2 / CIRCLE_TESSELATIONS); vertices[tesselationIndex] = vertex; } if (colliding) { if (objectIndex == self->selectedObjectIndex) { setVertexColor(&vertex, COLOR_CIRCLE_POSITION_COLLIDING_HIGHLIGHT); } else { setVertexColor(&vertex, COLOR_CIRCLE_POSITION_COLLIDING); } } else { if (objectIndex == self->selectedObjectIndex) { setVertexColor(&vertex, COLOR_CIRCLE_POSITION_HIGHLIGHT); } else { setVertexColor(&vertex, COLOR_CIRCLE_POSITION); } } for (unsigned int tesselationIndex = 0; tesselationIndex < CIRCLE_TESSELATIONS; tesselationIndex++) { vertex.position[0] = xtof(circle->position.x) + xtof(circle->radius) * cos(tesselationIndex * M_PI * 2 / CIRCLE_TESSELATIONS); vertex.position[1] = xtof(circle->position.y) + xtof(circle->radius) * sin(tesselationIndex * M_PI * 2 / CIRCLE_TESSELATIONS); vertices[CIRCLE_TESSELATIONS + tesselationIndex] = vertex; } for (unsigned int tesselationIndex = 0; tesselationIndex < CIRCLE_TESSELATIONS; tesselationIndex++) { indexes[tesselationIndex * 2 + 0] = tesselationIndex; indexes[tesselationIndex * 2 + 1] = (tesselationIndex + 1) % CIRCLE_TESSELATIONS; } float angle = atan2(circle->position.y - circle->lastPosition.y, circle->position.x - circle->lastPosition.x); int bestEdgeIndex = round((angle + M_PI / 2) * CIRCLE_TESSELATIONS / (M_PI * 2)); bestEdgeIndex = (bestEdgeIndex % CIRCLE_TESSELATIONS + CIRCLE_TESSELATIONS) % CIRCLE_TESSELATIONS; indexes[CIRCLE_TESSELATIONS * 2 + 0] = bestEdgeIndex; indexes[CIRCLE_TESSELATIONS * 2 + 1] = bestEdgeIndex + CIRCLE_TESSELATIONS; bestEdgeIndex += CIRCLE_TESSELATIONS / 2; bestEdgeIndex %= CIRCLE_TESSELATIONS; indexes[CIRCLE_TESSELATIONS * 2 + 2] = bestEdgeIndex; indexes[CIRCLE_TESSELATIONS * 2 + 3] = bestEdgeIndex + CIRCLE_TESSELATIONS; for (unsigned int tesselationIndex = 0; tesselationIndex < CIRCLE_TESSELATIONS; tesselationIndex++) { indexes[CIRCLE_TESSELATIONS * 2 + 4 + tesselationIndex * 2] = CIRCLE_TESSELATIONS + tesselationIndex; indexes[CIRCLE_TESSELATIONS * 2 + 5 + tesselationIndex * 2] = CIRCLE_TESSELATIONS + (tesselationIndex + 1) % CIRCLE_TESSELATIONS; } VertexIO_writeIndexedVertices(vertexIO, sizeof(vertices) / sizeof(vertices[0]), vertices, sizeof(indexes) / sizeof(indexes[0]), indexes); if (colliding) { Vector2x collidingPosition = Vector2x_interpolate(circle->lastPosition, circle->position, collision.time); struct vertex_p2f_t2f_c4f vertices[CIRCLE_TESSELATIONS]; uint32_t indexes[CIRCLE_TESSELATIONS * 2]; if (objectIndex == self->selectedObjectIndex) { setVertexColor(&vertex, COLOR_CIRCLE_POSITION_HIGHLIGHT); } else { setVertexColor(&vertex, COLOR_CIRCLE_POSITION); } for (unsigned int tesselationIndex = 0; tesselationIndex < CIRCLE_TESSELATIONS; tesselationIndex++) { vertex.position[0] = xtof(collidingPosition.x) + xtof(circle->radius) * cos(tesselationIndex * M_PI * 2 / CIRCLE_TESSELATIONS); vertex.position[1] = xtof(collidingPosition.y) + xtof(circle->radius) * sin(tesselationIndex * M_PI * 2 / CIRCLE_TESSELATIONS); vertices[tesselationIndex] = vertex; } for (unsigned int tesselationIndex = 0; tesselationIndex < CIRCLE_TESSELATIONS; tesselationIndex++) { indexes[tesselationIndex * 2 + 0] = tesselationIndex; indexes[tesselationIndex * 2 + 1] = (tesselationIndex + 1) % CIRCLE_TESSELATIONS; } VertexIO_writeIndexedVertices(vertexIO, sizeof(vertices) / sizeof(vertices[0]), vertices, sizeof(indexes) / sizeof(indexes[0]), indexes); writeArrowVertices(collidingPosition, collision.normal, vertexIO); } break; } } } } bool SingleFrameScreen2D_init(SingleFrameScreen2D * self, Renderer * renderer) { call_super(init, self); self->renderer = renderer; self->renderLayer = RenderLayer_create(RENDER_LAYER_SORT_NONE, NULL, NULL); self->shaderConfiguration = ShaderConfiguration2DTexture_create(ShaderCollection_get2DTextureShader()); call_virtual(setTexture, self->shaderConfiguration, 0, g_blankTexture, false); self->renderPipelineConfiguration = default2DRenderPipelineConfiguration(RENDER_BLEND_ALPHA); self->renderable = Renderable_createWithCallback(PRIMITIVE_LINES, &self->renderPipelineConfiguration, self->shaderConfiguration, writeCollisionObjectVertices, NULL, self); self->intersectionManager = IntersectionManager_createWithStandardHandlers(); RenderLayer_addRenderable(self->renderLayer, self->renderable, 0, RECT4i_EMPTY); return true; } void SingleFrameScreen2D_dispose(SingleFrameScreen2D * self) { Renderable_dispose(self->renderable); ShaderConfiguration2DTexture_dispose(self->shaderConfiguration); IntersectionManager_dispose(self->intersectionManager); RenderLayer_dispose(self->renderLayer); call_super(dispose, self); } static bool draw(Atom eventID, void * eventData, void * context) { SingleFrameScreen2D * self = context; Renderer_clear(self->renderer, COLOR4f(0.0f, 0.0f, 0.0f, 0.0f)); Renderer_drawLayer(self->renderer, self->renderLayer, 0.0, 0.0); return true; } static bool keyDown(Atom eventID, void * eventData, void * context) { SingleFrameScreen2D * self = context; struct keyEvent * event = eventData; switch (event->keyCode) { case KEY_CODE_TAB: if (!self->dragging) { if (event->modifiers & MODIFIER_SHIFT_BIT) { self->selectedObjectIndex += OBJECT_COUNT_2D - 1; } else { self->selectedObjectIndex++; } self->selectedObjectIndex %= OBJECT_COUNT_2D; Shell_redisplay(); } break; case KEY_CODE_I: case KEY_CODE_J: case KEY_CODE_K: case KEY_CODE_L: if (call_virtual(getShapeType, self->objects[self->selectedObjectIndex]) == COLLISION_SHAPE_RECT_2D) { CollisionRect2D * rect = (CollisionRect2D *) self->objects[self->selectedObjectIndex]; CollisionRect2D_setSolidity(rect, event->keyCode == KEY_CODE_J ? !rect->solidLeft : rect->solidLeft, event->keyCode == KEY_CODE_L ? !rect->solidRight : rect->solidRight, event->keyCode == KEY_CODE_K ? !rect->solidBottom : rect->solidBottom, event->keyCode == KEY_CODE_I ? !rect->solidTop : rect->solidTop); Shell_redisplay(); } break; } return true; } #define DOUBLE_CLICK_INTERVAL 0.25 #define DOUBLE_CLICK_MAX_DISTANCE 4.0f static bool mouseDown(Atom eventID, void * eventData, void * context) { SingleFrameScreen2D * self = context; struct mouseEvent * event = eventData; static double lastClickTime; static Vector2f lastClickPosition; CollisionObject * object = self->objects[self->selectedObjectIndex]; double clickTime = Shell_getCurrentTime(); if (clickTime - lastClickTime < DOUBLE_CLICK_INTERVAL && fabs(event->position.x - lastClickPosition.x) <= DOUBLE_CLICK_MAX_DISTANCE && fabs(event->position.y - lastClickPosition.y) <= DOUBLE_CLICK_MAX_DISTANCE) { switch (call_virtual(getShapeType, object)) { case COLLISION_SHAPE_RECT_2D: { CollisionRect2D * rect = (CollisionRect2D *) object; rect->position = rect->lastPosition; rect->size = rect->lastSize; break; } case COLLISION_SHAPE_CIRCLE: { CollisionCircle * circle = (CollisionCircle *) object; circle->position = circle->lastPosition; break; } } Shell_redisplay(); self->dragging = false; } else { self->dragOrigin = Vector2f_toVector2x(transformMousePosition_signedCenter(VECTOR2f(event->position.x, event->position.y), g_viewWidth, g_viewHeight, 12.0f)); self->draggingLastPosition = event->modifiers & MODIFIER_SHIFT_BIT; self->draggingBoth = event->modifiers & MODIFIER_CONTROL_BIT; self->draggingSize = event->modifiers & MODIFIER_ALT_BIT; switch (call_virtual(getShapeType, object)) { case COLLISION_SHAPE_RECT_2D: { CollisionRect2D * rect = (CollisionRect2D *) object; self->dragStartPosition = rect->position; self->dragStartLastPosition = rect->lastPosition; self->dragStartSize = rect->size; self->dragStartLastSize = rect->lastSize; break; } case COLLISION_SHAPE_CIRCLE: { CollisionCircle * circle = (CollisionCircle *) object; self->dragStartPosition = circle->position; self->dragStartLastPosition = circle->lastPosition; self->dragStartRadius = circle->radius; break; } } self->dragging = true; } lastClickTime = clickTime; lastClickPosition = VECTOR2f(event->position.x, event->position.y); return true; } static bool mouseUp(Atom eventID, void * eventData, void * context) { SingleFrameScreen2D * self = context; self->dragging = false; return true; } static bool mouseDragged(Atom eventID, void * eventData, void * context) { SingleFrameScreen2D * self = context; struct mouseEvent * event = eventData; Vector2x mousePosition = Vector2f_toVector2x(transformMousePosition_signedCenter(VECTOR2f(event->position.x, event->position.y), g_viewWidth, g_viewHeight, 12.0f)); CollisionObject * object = self->objects[self->selectedObjectIndex]; switch (call_virtual(getShapeType, object)) { case COLLISION_SHAPE_RECT_2D: { CollisionRect2D * rect = (CollisionRect2D *) object; if (self->draggingLastPosition || self->draggingBoth) { if (self->draggingSize) { rect->lastSize.x = self->dragStartLastSize.x + mousePosition.x - self->dragOrigin.x; rect->lastSize.y = self->dragStartLastSize.y + mousePosition.y - self->dragOrigin.y; } else { rect->lastPosition.x = self->dragStartLastPosition.x + mousePosition.x - self->dragOrigin.x; rect->lastPosition.y = self->dragStartLastPosition.y + mousePosition.y - self->dragOrigin.y; } } if (!self->draggingLastPosition || self->draggingBoth) { if (self->draggingSize) { rect->size.x = self->dragStartSize.x + mousePosition.x - self->dragOrigin.x; rect->size.y = self->dragStartSize.y + mousePosition.y - self->dragOrigin.y; } else { rect->position.x = self->dragStartPosition.x + mousePosition.x - self->dragOrigin.x; rect->position.y = self->dragStartPosition.y + mousePosition.y - self->dragOrigin.y; } } break; } case COLLISION_SHAPE_CIRCLE: { CollisionCircle * circle = (CollisionCircle *) object; if (self->draggingSize) { circle->radius = self->dragStartRadius + mousePosition.y - self->dragOrigin.y; } else { if (self->draggingLastPosition || self->draggingBoth) { circle->lastPosition.x = self->dragStartLastPosition.x + mousePosition.x - self->dragOrigin.x; circle->lastPosition.y = self->dragStartLastPosition.y + mousePosition.y - self->dragOrigin.y; } if (!self->draggingLastPosition || self->draggingBoth) { circle->position.x = self->dragStartPosition.x + mousePosition.x - self->dragOrigin.x; circle->position.y = self->dragStartPosition.y + mousePosition.y - self->dragOrigin.y; } } break; } } Shell_redisplay(); return true; } static bool resized(Atom eventID, void * eventData, void * context) { SingleFrameScreen2D * self = context; Shell_redisplay(); call_virtual(setProjectionMatrix, self->shaderConfiguration, Matrix4x4f_ortho(MATRIX4x4f_IDENTITY, -12.0f * g_viewRatio, 12.0f * g_viewRatio, -12.0f, 12.0f, -1.0f, 1.0f)); return true; } void SingleFrameScreen2D_activate(SingleFrameScreen2D * self, Screen * lastScreen, const char * transitionName) { self->objects[0] = (CollisionObject *) CollisionRect2D_create(NULL, NULL, NULL, VECTOR2x(0x00000, 0x00000), VECTOR2x(0x10000, 0x10000), 0x00000); self->objects[1] = (CollisionObject *) CollisionRect2D_create(NULL, NULL, NULL, VECTOR2x(0x20000, -0x40000), VECTOR2x(0x50000, 0x20000), 0x00000); self->objects[2] = (CollisionObject *) CollisionCircle_create(NULL, NULL, NULL, VECTOR2x(-0x30000, 0x00000), 0x10000); self->objects[3] = (CollisionObject *) CollisionCircle_create(NULL, NULL, NULL, VECTOR2x(-0x20000, 0x50000), 0x08000); self->resolver = CollisionResolver_create(self->intersectionManager, false, NULL, NULL); CollisionResolver_addObject(self->resolver, self->objects[0]); CollisionResolver_addObject(self->resolver, self->objects[1]); CollisionResolver_addObject(self->resolver, self->objects[2]); CollisionResolver_addObject(self->resolver, self->objects[3]); self->dragging = false; self->draggingLastPosition = false; self->draggingBoth = false; self->draggingSize = false; self->selectedObjectIndex = 0; EventDispatcher_registerForEvent(self->screenManager->eventDispatcher, ATOM(EVENT_KEY_DOWN), keyDown, self); EventDispatcher_registerForEvent(self->screenManager->eventDispatcher, ATOM(EVENT_MOUSE_DOWN), mouseDown, self); EventDispatcher_registerForEvent(self->screenManager->eventDispatcher, ATOM(EVENT_MOUSE_UP), mouseUp, self); EventDispatcher_registerForEvent(self->screenManager->eventDispatcher, ATOM(EVENT_MOUSE_DRAGGED), mouseDragged, self); EventDispatcher_registerForEvent(self->screenManager->eventDispatcher, ATOM(EVENT_RESIZED), resized, self); EventDispatcher_registerForEvent(self->screenManager->eventDispatcher, ATOM(EVENT_DRAW), draw, self); call_virtual(setProjectionMatrix, self->shaderConfiguration, Matrix4x4f_ortho(MATRIX4x4f_IDENTITY, -12.0f * g_viewRatio, 12.0f * g_viewRatio, -12.0f, 12.0f, -1.0f, 1.0f)); Shell_redisplay(); } void SingleFrameScreen2D_deactivate(SingleFrameScreen2D * self, Screen * nextScreen, const char * transitionName) { size_t objectIndex; for (objectIndex = 0; objectIndex < OBJECT_COUNT_2D; objectIndex++) { call_virtual(dispose, self->objects[objectIndex]); } CollisionResolver_dispose(self->resolver); EventDispatcher_unregisterForEvent(self->screenManager->eventDispatcher, ATOM(EVENT_KEY_DOWN), keyDown, self); EventDispatcher_unregisterForEvent(self->screenManager->eventDispatcher, ATOM(EVENT_MOUSE_DOWN), mouseDown, self); EventDispatcher_unregisterForEvent(self->screenManager->eventDispatcher, ATOM(EVENT_MOUSE_UP), mouseUp, self); EventDispatcher_unregisterForEvent(self->screenManager->eventDispatcher, ATOM(EVENT_MOUSE_DRAGGED), mouseDragged, self); EventDispatcher_unregisterForEvent(self->screenManager->eventDispatcher, ATOM(EVENT_RESIZED), resized, self); EventDispatcher_unregisterForEvent(self->screenManager->eventDispatcher, ATOM(EVENT_DRAW), draw, self); }