示例#1
0
文件: DrawUtils.cpp 项目: UIKit0/DT3
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();
}
示例#2
0
文件: DrawUtils.cpp 项目: UIKit0/DT3
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();
}
示例#3
0
文件: DrawUtils.cpp 项目: UIKit0/DT3
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();
}
示例#4
0
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();
}
示例#5
0
文件: DrawUtils.cpp 项目: UIKit0/DT3
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();
}
示例#6
0
文件: DrawUtils.cpp 项目: UIKit0/DT3
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();
}