MCPcopy Create free account
hub / github.com/WolfireGames/overgrowth / DrawBox

Function DrawBox

Source/Editors/map_editor.cpp:623–665  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

621}
622
623static void DrawBox(const Box& box_, const Object* object_, bool highlight, const vec4& box_color) {
624 mat4 transform = object_->GetTransform();
625 // Translate
626 transform[0 + 3 * 4] += box_.center[0];
627 transform[1 + 3 * 4] += box_.center[1];
628 transform[2 + 3 * 4] += box_.center[2];
629 // Scale
630 transform[0 + 0 * 4] *= box_.dims[0];
631 transform[1 + 0 * 4] *= box_.dims[0];
632 transform[2 + 0 * 4] *= box_.dims[0];
633 transform[0 + 1 * 4] *= box_.dims[1];
634 transform[1 + 1 * 4] *= box_.dims[1];
635 transform[2 + 1 * 4] *= box_.dims[1];
636 transform[0 + 2 * 4] *= box_.dims[2];
637 transform[1 + 2 * 4] *= box_.dims[2];
638 transform[2 + 2 * 4] *= box_.dims[2];
639
640 vec4 draw_color = box_color;
641 draw_color[3] *= highlight ? 1.0f : 0.2f;
642
643 static const GLfloat vertices[] = {
644 -0.5f, -0.5f, 0.5f, 0.5f, -0.5f, 0.5f, 0.5f, 0.5f, 0.5f, -0.5f, 0.5f, 0.5f, // front (in coord system: +x to the right, +y up, -z into distance)
645 -0.5f, -0.5f, -0.5f, 0.5f, -0.5f, -0.5f, 0.5f, 0.5f, -0.5f, -0.5f, 0.5f, -0.5f, // back
646 };
647 static const GLubyte edges[] = {
648 0, 1, 1, 2, 2, 3, 3, 0, 4, 5, 5, 6,
649 6, 7, 7, 4, 4, 0, 7, 3, 5, 1, 6, 2};
650
651 GLfloat transformed_vertices[3 * 8];
652 for (int i = 0; i < 8; ++i) {
653 vec3 temp = TransformVec3(transform, *(vec3*)&vertices[i * 3]);
654 memcpy(&transformed_vertices[i * 3], &temp, sizeof(vec3));
655 }
656
657 // Draw edges of box
658 for (int i = 0; i < 12; i++) {
659 int start_index = edges[i * 2 + 0] * 3;
660 int end_index = edges[i * 2 + 1] * 3;
661 vec3 start = *(vec3*)&transformed_vertices[start_index];
662 vec3 end = *(vec3*)&transformed_vertices[end_index];
663 DebugDraw::Instance()->AddLine(start, end, draw_color, _delete_on_draw);
664 }
665}
666
667static void DrawControlledFace(const Box& box_, const Object* object_, int face_selected_, FaceDisplay face_display_) {
668 PROFILER_GPU_ZONE(g_profiler_ctx, "DrawControlledFace");

Callers 1

DrawMethod · 0.85

Calls 3

TransformVec3Function · 0.70
GetTransformMethod · 0.45
AddLineMethod · 0.45

Tested by

no test coverage detected