示例#1
0
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);
}
示例#2
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();

    

}