Changeset 380

Show
Ignore:
Timestamp:
09/15/11 10:29:13 (8 months ago)
Author:
Carsten
Message:

Model Editor:
Add a spatial grid to the model editor as described in item 3 of #79.
The user can turn the grid on and off and set the spacing of the grid lines.

Closes #79.

Location:
cafu/trunk/CaWE/ModelEditor
Files:
3 modified

Legend:

Unmodified
Added
Removed
  • cafu/trunk/CaWE/ModelEditor/ScenePropGrid.cpp

    r318 r380  
    2727#include "../GameConfig.hpp" 
    2828#include "../MapBrush.hpp" 
     29#include "../Options.hpp" 
    2930#include "MaterialSystem/MapComposition.hpp" 
    3031#include "MaterialSystem/TextureMap.hpp" 
     
    4344      m_BackgroundColor(wxColour(wxConfigBase::Get()->Read("ModelEditor/SceneSetup/BackgroundColor", "rgb(0, 128, 255)"))), 
    4445      m_ShowOrigin(wxConfigBase::Get()->Read("ModelEditor/SceneSetup/ShowOrigin", 1l)!=0), 
     46      m_ShowGrid(wxConfigBase::Get()->Read("ModelEditor/SceneSetup/ShowGrid", 0l)!=0), 
     47      m_GridSpacing(Options.Grid.InitialSpacing), 
    4548      m_GroundPlane_Show(wxConfigBase::Get()->Read("ModelEditor/SceneSetup/GroundPlane_Show", 1l)!=0), 
    4649      m_Model_ShowMesh(wxConfigBase::Get()->Read("ModelEditor/SceneSetup/Model_ShowMesh", 1l)!=0), 
     
    8487    AppendIn(GeneralCat, new wxColourProperty("Background Color", wxPG_LABEL, m_BackgroundColor)); 
    8588    AppendIn(GeneralCat, new wxBoolProperty("Show Origin", wxPG_LABEL, m_ShowOrigin)); 
     89    AppendIn(GeneralCat, new wxBoolProperty("Show Grid", wxPG_LABEL, m_ShowGrid)); 
     90    AppendIn(GeneralCat, new wxFloatProperty("Grid Spacing", wxPG_LABEL, m_GridSpacing)); 
    8691 
    8792 
     
    182187         if (PropName=="Background Color")                m_BackgroundColor << Prop->GetValue(); 
    183188    else if (PropName=="Show Origin")                     m_ShowOrigin=Prop->GetValue().GetBool(); 
     189    else if (PropName=="Show Grid")                       m_ShowGrid=Prop->GetValue().GetBool(); 
     190    else if (PropName=="Grid Spacing")                    m_GridSpacing=PropValueF; 
    184191    else if (PropName=="Camera.Pos.x")                    Camera.Pos.x=PropValueF; 
    185192    else if (PropName=="Camera.Pos.y")                    Camera.Pos.y=PropValueF; 
  • cafu/trunk/CaWE/ModelEditor/ScenePropGrid.hpp

    r318 r380  
    5151        wxColour             m_BackgroundColor; 
    5252        bool                 m_ShowOrigin; 
     53        bool                 m_ShowGrid; 
     54        float                m_GridSpacing; 
    5355        bool                 m_GroundPlane_Show; 
    5456        bool                 m_Model_ShowMesh; 
  • cafu/trunk/CaWE/ModelEditor/SceneView3D.cpp

    r360 r380  
    600600    } 
    601601 
     602    // Render the grid. 
     603    if (ScenePropGrid->m_ShowGrid) 
     604    { 
     605        for (unsigned int PlaneNr=0; PlaneNr<3; PlaneNr++) 
     606        { 
     607            static MatSys::MeshT Mesh(MatSys::MeshT::Lines); 
     608 
     609            const unsigned int NumLines=17; 
     610            const float        Spacing =ScenePropGrid->m_GridSpacing; 
     611            const float        MaxCoord=Spacing * ((NumLines-1)/2); 
     612 
     613            if (Mesh.Vertices.Size()==0) 
     614            { 
     615                Mesh.Vertices.PushBackEmptyExact(NumLines*2); 
     616 
     617                const float r=Options.Grid.ColorHighlight1.Red()   / 255.0f; 
     618                const float g=Options.Grid.ColorHighlight1.Green() / 255.0f; 
     619                const float b=Options.Grid.ColorHighlight1.Blue()  / 255.0f; 
     620 
     621                for (unsigned int LineNr=0; LineNr<NumLines; LineNr++) 
     622                { 
     623                    Mesh.Vertices[LineNr*2  ].SetColor(r, g, b); 
     624                    Mesh.Vertices[LineNr*2+1].SetColor(r, g, b); 
     625                } 
     626            } 
     627 
     628            for (unsigned int DirNr=0; DirNr<2; DirNr++) 
     629            { 
     630                for (unsigned int LineNr=0; LineNr<NumLines; LineNr++) 
     631                { 
     632                    Vector3fT A; 
     633                    Vector3fT B; 
     634 
     635                    A[(PlaneNr+1+DirNr) % 3]=-MaxCoord; 
     636                    A[(PlaneNr+2-DirNr) % 3]=Spacing*LineNr - MaxCoord; 
     637 
     638                    B[(PlaneNr+1+DirNr) % 3]=MaxCoord; 
     639                    B[(PlaneNr+2-DirNr) % 3]=Spacing*LineNr - MaxCoord; 
     640 
     641                    Mesh.Vertices[LineNr*2  ].SetOrigin(A); 
     642                    Mesh.Vertices[LineNr*2+1].SetOrigin(B); 
     643                } 
     644 
     645                MatSys::Renderer->SetCurrentMaterial(m_Renderer.GetRMatWireframe()); 
     646                MatSys::Renderer->RenderMesh(Mesh); 
     647            } 
     648        } 
     649    } 
     650 
    602651    // Render a small cross at the (world-space) position of each active light source. 
    603652    const ArrayT<ModelDocumentT::LightSourceT*>& LightSources=m_Parent->GetModelDoc()->GetLightSources();