예제 #1
0
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();

    

}
예제 #2
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();
}