void DrawUtils::draw_ring ( DrawBatcher &draw_batcher, const std::shared_ptr<CameraObject> &camera, const std::shared_ptr<MaterialResource> &material, const std::shared_ptr<ShaderResource> &shader, const Matrix4 &transform, const Color4b &color, DTfloat size) { draw_batcher.batch_begin(camera, material, shader, transform, DT3GL_PRIM_LINE_LOOP, DrawBatcher::FMT_V | DrawBatcher::FMT_C); const DTfloat MAX_SEGMENTS = 64.0F; for (DTuint i = 0; i <= MAX_SEGMENTS; ++i) { DTfloat angle = static_cast<DTfloat>(i) / MAX_SEGMENTS * 2.0F * PI; draw_batcher.add().v(size * std::cos(angle), 0.0F, size * std::sin(angle)).c(color); } draw_batcher.batch_end(); draw_batcher.draw(); }
void DrawUtils::draw_cone( DrawBatcher &draw_batcher, const std::shared_ptr<CameraObject> &camera, const std::shared_ptr<MaterialResource> &material, const std::shared_ptr<ShaderResource> &shader, const Matrix4 &transform, const Color4b &color, DTfloat radius, DTfloat length) { draw_batcher.batch_begin(camera, material, shader, transform, DT3GL_PRIM_TRI_STRIP, DrawBatcher::FMT_V | DrawBatcher::FMT_C); const DTint MAX_SEGMENTS = 16; for (DTint i = 0; i < MAX_SEGMENTS; ++i) { DTfloat angle = static_cast<DTfloat>(i) / MAX_SEGMENTS * 2.0F * PI; DTfloat angle_plus_1 = static_cast<DTfloat>(i+1) / MAX_SEGMENTS * 2.0F * PI; draw_batcher.add().v(radius * std::cos(angle), -length, radius * std::sin(angle)).c(color); draw_batcher.add().v(radius * std::cos(angle_plus_1), -length, radius * std::sin(angle_plus_1)).c(color); draw_batcher.add().v(0.0F,length,0.0F).c(color); } draw_batcher.batch_end(); draw_batcher.draw(); }
void EdManipGUIObject::draw (EdLevelToolWindow *parent, const std::shared_ptr<CameraObject> &camera, DTfloat scale) { if (getSelection().size() != 1) return; GUIObject *gui_object = checkedCast<GUIObject*>(getSelection().front()); if (!gui_object) return; // Override the camera with a screen aligned one CameraObject gui_camera = *camera; // Copy all camera attributes gui_camera.setOrtho(0.0F,1.0F,0.0F,1.0F,1.0F,-1.0F); gui_camera.setTranslationLocal(Vector3(0.0F,0.0F,0.0F)); gui_camera.setOrientationLocal(Matrix3::identity()); DrawUtils::activateCamera(&gui_camera); Matrix4 axis; Matrix4 transform = getManipulatorTransform(); scale = 7.0F / System::getRenderer()->getScreenWidth(); ::glPushName(0); Rectangle r = gui_object->getRectangle(); Vector3 p0 = Vector3(r.getMinusX(), r.getMinusY(), 0.0F); Vector3 p1 = Vector3(r.getPlusX(), r.getMinusY(), 0.0F); Vector3 p2 = Vector3(r.getPlusX(), r.getPlusY(), 0.0F); Vector3 p3 = Vector3(r.getMinusX(), r.getPlusY(), 0.0F); // Translate ::glLoadName(TRANSLATE); axis = Matrix4( Matrix3( 1.0F, 0.0F, 0.0F, 0.0F, 1.0F, 0.0F, 0.0F, 0.0F, 1.0F), Vector3(0.0F,0.0F,0.0F), scale); drawCube(&_red_material, transform * axis); // X Axis ::glLoadName(MINUS_X); axis = Matrix4( Matrix3( 1.0F, 0.0F, 0.0F, 0.0F, 1.0F, 0.0F, 0.0F, 0.0F, 1.0F), (p0+p3)*0.5F, scale); drawCube(&_red_material, transform * axis); ::glLoadName(PLUS_X); axis = Matrix4( Matrix3( 1.0F, 0.0F, 0.0F, 0.0F, 1.0F, 0.0F, 0.0F, 0.0F, 1.0F), (p1+p2)*0.5F, scale); drawCube(&_red_material, transform * axis); // Y Axis ::glLoadName(MINUS_Y); axis = Matrix4( Matrix3( 1.0F, 0.0F, 0.0F, 0.0F, 1.0F, 0.0F, 0.0F, 0.0F, 1.0F), (p0+p1)*0.5F, scale); drawCube(&_red_material, transform * axis); ::glLoadName(PLUS_Y); axis = Matrix4( Matrix3( 1.0F, 0.0F, 0.0F, 0.0F, 1.0F, 0.0F, 0.0F, 0.0F, 1.0F), (p2+p3)*0.5F, scale); drawCube(&_red_material, transform * axis); ::glLoadName(0); // Draw Lines DrawBatcher b; b.batchBegin(&_line_material, transform, DrawBatcher::BATCH_LINE_LOOP, DrawBatcher::FMT_V); b.vertex(p0); b.vertex(p1); b.vertex(p2); b.vertex(p3); b.batchEnd(); ::glPopName(); // Pop component DrawUtils::activateCamera(camera); }
void ComponentDrawCamera::draw (CameraObject* camera) { CameraObject *placeable = checkedCast<CameraObject*>(getOwner()); if (!placeable) return; _line_material.setBlendEnable(false); _line_material.setDepthEnable(true); _line_material.setCullMode(DT3GL_CULL_NONE); _line_material.setColor(_color); _line_material.setShader(ShaderResource::getShader(FilePath("{editorline.shdr}"))); DrawBatcher b; b.batchBegin(&_line_material, placeable->getTransform(), DrawBatcher::BATCH_LINES, DrawBatcher::FMT_V); // Can for (DTuint i = 0; i < ARRAY_SIZE(can); ++i) { b.vertex( Vector3(THICKNESS, can[i].x, can[i].y) ); b.vertex( Vector3(-THICKNESS, can[i].x, can[i].y) ); } for (DTuint i = 0; i < ARRAY_SIZE(can)-1; ++i) { b.vertex( Vector3(THICKNESS, can[i].x, can[i].y) ); b.vertex( Vector3(THICKNESS, can[i+1].x, can[i+1].y) ); b.vertex( Vector3(-THICKNESS, can[i].x, can[i].y) ); b.vertex( Vector3(-THICKNESS, can[i+1].x, can[i+1].y) ); } // Box for (DTuint i = 0; i < ARRAY_SIZE(box); ++i) { b.vertex( Vector3(THICKNESS, box[i].x, box[i].y) ); b.vertex( Vector3(-THICKNESS, box[i].x, box[i].y) ); } for (DTuint i = 0; i < ARRAY_SIZE(box)-1; ++i) { b.vertex( Vector3(THICKNESS, box[i].x, box[i].y) ); b.vertex( Vector3(THICKNESS, box[i+1].x, box[i+1].y) ); b.vertex( Vector3(-THICKNESS, box[i].x, box[i].y) ); b.vertex( Vector3(-THICKNESS, box[i+1].x, box[i+1].y) ); } // Side for (DTuint i = 0; i < ARRAY_SIZE(side); ++i) { b.vertex( Vector3(THICKNESS, side[i].x, side[i].y) ); b.vertex( Vector3(SIDE_THICKNESS+THICKNESS, side[i].x, side[i].y) ); } for (DTuint i = 0; i < ARRAY_SIZE(side)-1; ++i) { b.vertex( Vector3(THICKNESS, side[i].x, side[i].y) ); b.vertex( Vector3(THICKNESS, side[i+1].x, side[i+1].y) ); b.vertex( Vector3(SIDE_THICKNESS+THICKNESS, side[i].x, side[i].y) ); b.vertex( Vector3(SIDE_THICKNESS+THICKNESS, side[i+1].x, side[i+1].y) ); } // Lens for (DTuint i = 0; i < ARRAY_SIZE(lens); ++i) { b.vertex( Vector3(LENS_THICKNESS, lens[i].x, lens[i].y) ); b.vertex( Vector3(-LENS_THICKNESS, lens[i].x, lens[i].y) ); } for (DTuint i = 0; i < ARRAY_SIZE(lens)-1; ++i) { b.vertex( Vector3(LENS_THICKNESS, lens[i].x, lens[i].y) ); b.vertex( Vector3(LENS_THICKNESS, lens[i+1].x, lens[i+1].y) ); b.vertex( Vector3(-LENS_THICKNESS, lens[i].x, lens[i].y) ); b.vertex( Vector3(-LENS_THICKNESS, lens[i+1].x, lens[i+1].y) ); } b.batchEnd(); b.flush(); // Frustum placeable->calculateFrustum(); Matrix4 projection_inv = placeable->getProjection().inversed(); Vector3 near_p0, near_p1, near_p2, near_p3; Vector3 far_p0, far_p1, far_p2, far_p3; MATTransform4H(projection_inv, Vector3(-1.0F,-1.0F,-1.0F), near_p0); MATTransform4H(projection_inv, Vector3(1.0F,-1.0F,-1.0F), near_p1); MATTransform4H(projection_inv, Vector3(1.0F,1.0F,-1.0F), near_p2); MATTransform4H(projection_inv, Vector3(-1.0F,1.0F,-1.0F), near_p3); MATTransform4H(projection_inv, Vector3(-1.0F,-1.0F,1.0F), far_p0); MATTransform4H(projection_inv, Vector3(1.0F,-1.0F,1.0F), far_p1); MATTransform4H(projection_inv, Vector3(1.0F,1.0F,1.0F), far_p2); MATTransform4H(projection_inv, Vector3(-1.0F,1.0F,1.0F), far_p3); b.batchBegin (&_line_material, placeable->getTransform(), DrawBatcher::BATCH_LINE_LOOP, DrawBatcher::FMT_V); b.vertex ( near_p0); b.vertex ( near_p1); b.vertex ( near_p2); b.vertex ( near_p3); b.batchEnd(); b.flush(); b.batchBegin (&_line_material, placeable->getTransform(), DrawBatcher::BATCH_LINE_LOOP, DrawBatcher::FMT_V); b.vertex ( far_p0); b.vertex ( far_p1); b.vertex ( far_p2); b.vertex ( far_p3); b.batchEnd(); b.flush(); b.batchBegin (&_line_material, placeable->getTransform(), DrawBatcher::BATCH_LINE_LOOP, DrawBatcher::FMT_V); b.vertex ( near_p0); b.vertex ( near_p1); b.vertex ( far_p1); b.vertex ( far_p0); b.batchEnd(); b.flush(); b.batchBegin (&_line_material, placeable->getTransform(), DrawBatcher::BATCH_LINE_LOOP, DrawBatcher::FMT_V); b.vertex ( near_p2); b.vertex ( near_p3); b.vertex ( far_p3); b.vertex ( far_p2); b.batchEnd(); b.flush(); }
void EdLevelManipScale::draw (EdLevelToolWindow *parent, const std::shared_ptr<CameraObject> &camera, DTfloat scale) { DrawBatcher b; Matrix4 axis; Matrix4 transform = getManipulatorTransform(); Matrix3 orientation = transform.orientation(); Vector3 translation = transform.translation(); transform = Matrix4(orientation, translation, scale); ::glPushName(0); // Center ::glLoadName(CENTER); axis = Matrix4( Matrix3( 1.0F, 0.0F, 0.0F, 0.0F, 1.0F, 0.0F, 0.0F, 0.0F, 1.0F), Vector3(0.0F,0.0F,0.0F), 1.0F); DrawUtils::draw_cube ( b, camera, _tool_material, _shader, transform * axis, Color4b::white, 0.05F); b.flush(); // X Axis ::glLoadName(PLUS_X); axis = Matrix4( Matrix3( 0.0F, 1.0F, 0.0F, 1.0F, 0.0F, 0.0F, 0.0F, 0.0F, -1.0F), Vector3(1.0F,0.0F,0.0F), 1.0F); DrawUtils::draw_cube ( b, camera, _tool_material, _shader, transform * axis, Color4b::red, 0.05F); b.flush(); // Y Axis ::glLoadName(PLUS_Y); axis = Matrix4( Matrix3( 1.0F, 0.0F, 0.0F, 0.0F, 1.0F, 0.0F, 0.0F, 0.0F, 1.0F), Vector3(0.0F,1.0F,0.0F), 1.0F); DrawUtils::draw_cube ( b, camera, _tool_material, _shader, transform * axis, Color4b::green, 0.05F); b.flush(); // Z Axis ::glLoadName(PLUS_Z); axis = Matrix4( Matrix3( 1.0F, 0.0F, 0.0F, 0.0F, 0.0F, -1.0F, 0.0F, 1.0F, 0.0F), Vector3(0.0F,0.0F,1.0F), 1.0F); DrawUtils::draw_cube ( b, camera, _tool_material, _shader, transform * axis, Color4b::blue, 0.05F); b.flush(); ::glPopName(); // Draw Lines b.batch_begin(camera, _tool_material, _shader, transform, DT3GL_PRIM_LINES, DrawBatcher::FMT_V); b.add().v(0.0F,0.0F,0.0F); b.add().v(1.0F,0.0F,0.0F); b.add().v(0.0F,0.0F,0.0F); b.add().v(0.0F,1.0F,0.0F); b.add().v(0.0F,0.0F,0.0F); b.add().v(0.0F,0.0F,1.0F); b.batch_end(); }
void DrawUtils::draw_cube ( DrawBatcher &draw_batcher, const std::shared_ptr<CameraObject> &camera, const std::shared_ptr<MaterialResource> &material, const std::shared_ptr<ShaderResource> &shader, const Matrix4 &transform, DTfloat size) { draw_batcher.batch_begin(camera, material, shader, transform, DT3GL_PRIM_TRI_STRIP, DrawBatcher::FMT_V); // Sized draw_batcher.add().v(-size,-size,size); draw_batcher.add().v(size,-size,size); draw_batcher.add().v(-size,size,size); draw_batcher.add().v(size,size,size); draw_batcher.add().v(-size,size,-size); draw_batcher.add().v(size,size,-size); draw_batcher.add().v(-size,-size,-size); draw_batcher.add().v(size,-size,-size); draw_batcher.add().v(-size,-size,size); draw_batcher.add().v(size,-size,size); draw_batcher.add().v(size,-size,size); // Degenerate draw_batcher.add().v(size,-size,size); // Degenerate draw_batcher.add().v(size,-size,size); draw_batcher.add().v(size,-size,-size); draw_batcher.add().v(size,size,size); draw_batcher.add().v(size,size,-size); draw_batcher.add().v(size,size,-size); // Degenerate draw_batcher.add().v(-size,-size,-size); // Degenerate draw_batcher.add().v(-size,-size,-size); draw_batcher.add().v(-size,-size,size); draw_batcher.add().v(-size,size,-size); draw_batcher.add().v(-size,size,size); // // Top // draw_batcher.add().v(-size,size,-size); // draw_batcher.add().v(-size,size,size); // draw_batcher.add().v(size,size,-size); // draw_batcher.add().v(size,size,size); // // draw_batcher.add().v(size,size,size); // Degenerate // // // Bottom // draw_batcher.add().v(-size,-size,size); // draw_batcher.add().v(-size,-size,-size); // draw_batcher.add().v(size,-size,size); // draw_batcher.add().v(size,-size,-size); draw_batcher.batch_end(); draw_batcher.draw(); }
void DrawUtils::draw_quad_stretch_center_3x3 ( DrawBatcher &draw_batcher, const std::shared_ptr<CameraObject> &camera, const std::shared_ptr<MaterialResource> &material, const std::shared_ptr<ShaderResource> &shader, const Color4f &color, const Matrix4 &transform, DTfloat xpos, DTfloat ypos, DTfloat xsize, DTfloat ysize, DTfloat corner_width, DTfloat corner_height) { // Adjust corner width if (corner_width > xsize * 0.5F) corner_width = xsize * 0.5F; if (corner_height > ysize * 0.5F) corner_height = ysize * 0.5F; // Makes the corners of the image. This means we have to draw nine rectangles. DTfloat one_third_x = 1.0F / 3.0F; DTfloat two_thirds_x = 1.0F - one_third_x; DTfloat one_third_y = 1.0F / 3.0F; DTfloat two_thirds_y = 1.0F - one_third_y; const DTfloat minus_x = xpos; const DTfloat plus_x = xpos + xsize; const DTfloat minus_y = ypos; const DTfloat plus_y = ypos + ysize; DTfloat inner_left = minus_x + corner_width; DTfloat inner_right = plus_x - corner_width; DTfloat inner_top = plus_y - corner_height; DTfloat inner_bottom = minus_y + corner_height; if (inner_left > inner_right) inner_left = inner_right = (minus_x + plus_x) * 0.5F; if (inner_bottom > inner_top) inner_bottom = inner_top = (minus_y + plus_y) * 0.5F; draw_batcher.batch_begin(camera, material, shader, transform, DT3GL_PRIM_TRI_STRIP, DrawBatcher::FMT_V | DrawBatcher::FMT_T0 | DrawBatcher::FMT_C); // Bottom row draw_batcher.add().v(minus_x, inner_bottom, 0.0F) .t0(0.0F, one_third_y) .c(color); draw_batcher.add().v(minus_x, minus_y, 0.0F) .t0(0.0F, 0.0F) .c(color); draw_batcher.add().v(inner_left, inner_bottom, 0.0F) .t0(one_third_x, one_third_y) .c(color); draw_batcher.add().v(inner_left, minus_y, 0.0F) .t0(one_third_x, 0.0F) .c(color); draw_batcher.add().v(inner_right, inner_bottom, 0.0F) .t0(two_thirds_x, one_third_y) .c(color); draw_batcher.add().v(inner_right, minus_y, 0.0F) .t0(two_thirds_x, 0.0F) .c(color); draw_batcher.add().v(plus_x, inner_bottom, 0.0F) .t0(1.0F, one_third_y) .c(color); draw_batcher.add().v(plus_x, minus_y, 0.0F) .t0(1.0F, 0.0F) .c(color); draw_batcher.add().v(plus_x, minus_y, 0.0F) .t0(1.0F, 0.0F) .c(color); // Degenerate draw_batcher.add().v(plus_x, minus_y, 0.0F) .t0(1.0F, 0.0F) .c(color); // Degenerate // Middle row draw_batcher.add().v(minus_x, inner_top, 0.0F) .t0(0.0F, two_thirds_y) .c(color); draw_batcher.add().v(minus_x, inner_bottom, 0.0F) .t0(0.0F, one_third_y) .c(color); draw_batcher.add().v(inner_left, inner_top, 0.0F) .t0(one_third_x, two_thirds_y) .c(color); draw_batcher.add().v(inner_left, inner_bottom, 0.0F) .t0(one_third_x, one_third_y) .c(color); draw_batcher.add().v(inner_right, inner_top, 0.0F) .t0(two_thirds_x, two_thirds_y) .c(color); draw_batcher.add().v(inner_right, inner_bottom, 0.0F) .t0(two_thirds_x, one_third_y) .c(color); draw_batcher.add().v(plus_x, inner_top, 0.0F) .t0(1.0F, two_thirds_y) .c(color); draw_batcher.add().v(plus_x, inner_bottom, 0.0F) .t0(1.0F, one_third_y) .c(color); draw_batcher.add().v(plus_x, inner_bottom, 0.0F) .t0(1.0F, one_third_y) .c(color); // Degenerate draw_batcher.add().v(plus_x, inner_bottom, 0.0F) .t0(1.0F, one_third_y) .c(color); // Degenerate // Top row draw_batcher.add().v(minus_x, plus_y, 0.0F) .t0(0.0F, 1.0F) .c(color); draw_batcher.add().v(minus_x, inner_top, 0.0F) .t0(0.0F, two_thirds_y) .c(color); draw_batcher.add().v(inner_left, plus_y, 0.0F) .t0(one_third_x, 1.0F) .c(color); draw_batcher.add().v(inner_left, inner_top, 0.0F) .t0(one_third_x, two_thirds_y) .c(color); draw_batcher.add().v(inner_right, plus_y, 0.0F) .t0(two_thirds_x, 1.0F) .c(color); draw_batcher.add().v(inner_right, inner_top, 0.0F) .t0(two_thirds_x, two_thirds_y) .c(color); draw_batcher.add().v(plus_x, plus_y, 0.0F) .t0(1.0F, 1.0F) .c(color); draw_batcher.add().v(plus_x, inner_top, 0.0F) .t0(1.0F, two_thirds_y) .c(color); draw_batcher.batch_end(); draw_batcher.draw(); }
void DrawUtils::draw_selection ( DrawBatcher &draw_batcher, const std::shared_ptr<CameraObject> &camera, const std::shared_ptr<MaterialResource> &material, const std::shared_ptr<ShaderResource> &shader, const Matrix4 &transform, const Color4b &color, DTfloat radius) { const DTfloat SEL_size = radius * 0.2F; // Draw box around object draw_batcher.batch_begin(camera, material, shader, transform, DT3GL_PRIM_LINES, DrawBatcher::FMT_V | DrawBatcher::FMT_C); // - - - draw_batcher.add().v(-radius,-radius,-radius) .c(color); draw_batcher.add().v(-radius+SEL_size,-radius,-radius) .c(color); draw_batcher.add().v(-radius,-radius,-radius) .c(color); draw_batcher.add().v(-radius,-radius+SEL_size,-radius) .c(color); draw_batcher.add().v(-radius,-radius,-radius) .c(color); draw_batcher.add().v(-radius,-radius,-radius+SEL_size) .c(color); // - - + draw_batcher.add().v(-radius,-radius,+radius) .c(color); draw_batcher.add().v(-radius+SEL_size,-radius,+radius) .c(color); draw_batcher.add().v(-radius,-radius,+radius) .c(color); draw_batcher.add().v(-radius,-radius+SEL_size,+radius) .c(color); draw_batcher.add().v(-radius,-radius,+radius) .c(color); draw_batcher.add().v(-radius,-radius,+radius-SEL_size) .c(color); // - + - draw_batcher.add().v(-radius,+radius,-radius) .c(color); draw_batcher.add().v(-radius+SEL_size,+radius,-radius) .c(color); draw_batcher.add().v(-radius,+radius,-radius) .c(color); draw_batcher.add().v(-radius,+radius-SEL_size,-radius) .c(color); draw_batcher.add().v(-radius,+radius,-radius) .c(color); draw_batcher.add().v(-radius,+radius,-radius+SEL_size) .c(color); // - + + draw_batcher.add().v(-radius,+radius,+radius) .c(color); draw_batcher.add().v(-radius+SEL_size,+radius,+radius) .c(color); draw_batcher.add().v(-radius,+radius,+radius) .c(color); draw_batcher.add().v(-radius,+radius-SEL_size,+radius) .c(color); draw_batcher.add().v(-radius,+radius,+radius) .c(color); draw_batcher.add().v(-radius,+radius,+radius-SEL_size) .c(color); // + - - draw_batcher.add().v(+radius,-radius,-radius) .c(color); draw_batcher.add().v(+radius-SEL_size,-radius,-radius) .c(color); draw_batcher.add().v(+radius,-radius,-radius) .c(color); draw_batcher.add().v(+radius,-radius+SEL_size,-radius) .c(color); draw_batcher.add().v(+radius,-radius,-radius) .c(color); draw_batcher.add().v(+radius,-radius,-radius+SEL_size) .c(color); // + - + draw_batcher.add().v(+radius,-radius,+radius) .c(color); draw_batcher.add().v(+radius-SEL_size,-radius,+radius) .c(color); draw_batcher.add().v(+radius,-radius,+radius) .c(color); draw_batcher.add().v(+radius,-radius+SEL_size,+radius) .c(color); draw_batcher.add().v(+radius,-radius,+radius) .c(color); draw_batcher.add().v(+radius,-radius,+radius-SEL_size) .c(color); // + + - draw_batcher.add().v(+radius,+radius,-radius) .c(color); draw_batcher.add().v(+radius-SEL_size,+radius,-radius) .c(color); draw_batcher.add().v(+radius,+radius,-radius) .c(color); draw_batcher.add().v(+radius,+radius-SEL_size,-radius) .c(color); draw_batcher.add().v(+radius,+radius,-radius) .c(color); draw_batcher.add().v(+radius,+radius,-radius+SEL_size) .c(color); // + + + draw_batcher.add().v(+radius,+radius,+radius) .c(color); draw_batcher.add().v(+radius-SEL_size,+radius,+radius) .c(color); draw_batcher.add().v(+radius,+radius,+radius) .c(color); draw_batcher.add().v(+radius,+radius-SEL_size,+radius) .c(color); draw_batcher.add().v(+radius,+radius,+radius) .c(color); draw_batcher.add().v(+radius,+radius,+radius-SEL_size) .c(color); draw_batcher.batch_end(); draw_batcher.draw(); }