Changeset 683

Show
Ignore:
Timestamp:
06/27/07 16:55:33 (17 months ago)
Author:
leo
Message:

Added default mesh objects.

Location:
trunk/common
Files:
5 modified

Legend:

Unmodified
Added
Removed
  • trunk/common/lc_application.cpp

    r663 r683  
    11#include "lc_global.h" 
     2#include "lc_application.h" 
     3 
    24#include <stdio.h> 
    3 #include "lc_application.h" 
     5#include "lc_mesh.h" 
    46#include "library.h" 
    57#include "system.h" 
     
    257259    SystemInit(); 
    258260 
     261    lcCreateDefaultMeshes(); 
     262 
    259263    // Create a new project. 
    260264    Project* project = new Project(); 
     
    410414    m_Library = NULL; 
    411415 
     416    lcDestroyDefaultMeshes(); 
     417 
    412418    GL_Shutdown(); 
    413419} 
  • trunk/common/lc_flexpiece.cpp

    r681 r683  
    275275// FIXME: split this into another file 
    276276 
    277 // FIXME: move the sphere somewhere else. 
    278 static lcMesh* SphereMesh; 
     277#define LC_FLEXPIECE_POINT_SIZE 0.2f 
    279278 
    280279lcFlexiblePiecePoint::lcFlexiblePiecePoint(lcFlexiblePiece* Parent) 
     
    282281{ 
    283282    m_Parent = Parent; 
    284  
    285     if (!SphereMesh) 
    286         SphereMesh = lcCreateSphereMesh(0.2f, 8); 
    287283} 
    288284 
     
    301297    // FIXME: lcFlexiblePiece 
    302298 
     299    Matrix44 ScaleMatrix(Vector4(LC_FLEXPIECE_POINT_SIZE, 0.0f, 0.0f, 0.0f), Vector4(0.0f, LC_FLEXPIECE_POINT_SIZE, 0.0f, 0.0f), Vector4(0.0f, 0.0f, LC_FLEXPIECE_POINT_SIZE, 0.0f), Vector4(0.0f, 0.0f, 0.0f, 1.0f)); 
     300 
     301    Matrix44 ModelWorld = IdentityMatrix44(); 
     302    ModelWorld.SetTranslation(m_WorldPosition); 
     303 
    303304    lcRenderSection RenderSection; 
    304305 
    305306    RenderSection.Owner = (lcPieceObject*)this; 
    306     RenderSection.ModelWorld = IdentityMatrix44(); 
    307     RenderSection.ModelWorld.SetTranslation(m_WorldPosition); 
    308     RenderSection.Mesh = SphereMesh; 
    309     RenderSection.Section = &SphereMesh->m_Sections[0]; 
     307    RenderSection.ModelWorld = Mul(ScaleMatrix, ModelWorld);; 
     308    RenderSection.Mesh = lcSphereMesh; 
     309    RenderSection.Section = &lcSphereMesh->m_Sections[0]; 
    310310    RenderSection.Color = 0; 
    311311 
  • trunk/common/lc_mesh.cpp

    r680 r683  
    11#include "lc_global.h" 
     2#include "lc_mesh.h" 
     3 
    24#include <malloc.h> 
    35#include <stdlib.h> 
    46#include "opengl.h" 
    57#include "globals.h" 
    6 #include "lc_mesh.h" 
    78#include "system.h" 
    89#include "debug.h" 
     10 
     11lcMesh* lcSphereMesh; 
     12lcMesh* lcBoxMesh; 
     13lcMesh* lcWireframeBoxMesh; 
     14 
     15void lcCreateDefaultMeshes() 
     16{ 
     17    lcSphereMesh = lcCreateSphereMesh(1.0f, 16); 
     18    lcBoxMesh = lcCreateBoxMesh(Vector3(-1.0f, -1.0f, -1.0f), Vector3(1.0f, 1.0f, 1.0f)); 
     19    lcWireframeBoxMesh = lcCreateWireframeBoxMesh(Vector3(-1.0f, -1.0f, -1.0f), Vector3(1.0f, 1.0f, 1.0f)); 
     20} 
     21 
     22void lcDestroyDefaultMeshes() 
     23{ 
     24    delete lcSphereMesh; 
     25    lcSphereMesh = NULL; 
     26    delete lcBoxMesh; 
     27    lcBoxMesh = NULL; 
     28    delete lcWireframeBoxMesh; 
     29    lcWireframeBoxMesh = NULL; 
     30} 
    931 
    1032lcMesh* lcCreateSphereMesh(float Radius, int Slices) 
     
    88110} 
    89111 
    90 lcMesh* lcCreateWireframeBoxMesh(const Vector3& Min, const Vector3& Max) 
    91 { 
    92     int NumIndices = 12; 
     112lcMesh* lcCreateBoxMesh(const Vector3& Min, const Vector3& Max) 
     113{ 
     114    int NumIndices = 24; 
    93115    int NumVertices = 8; 
    94116 
     
    96118 
    97119    lcMeshEditor<u16> MeshEdit(BoxMesh); 
    98     MeshEdit.StartSection(GL_LINES, LC_COL_DEFAULT); 
     120    MeshEdit.StartSection(GL_QUADS, LC_COL_DEFAULT); 
    99121 
    100122    MeshEdit.AddVertex(Vector3(Min[0], Min[1], Min[2])); 
     
    109131    MeshEdit.AddIndex(0); 
    110132    MeshEdit.AddIndex(1); 
     133    MeshEdit.AddIndex(2); 
     134    MeshEdit.AddIndex(3); 
     135    MeshEdit.AddIndex(7); 
     136    MeshEdit.AddIndex(6); 
     137    MeshEdit.AddIndex(5); 
     138    MeshEdit.AddIndex(4); 
     139 
     140    MeshEdit.AddIndex(0); 
     141    MeshEdit.AddIndex(1); 
     142    MeshEdit.AddIndex(5); 
     143    MeshEdit.AddIndex(4); 
     144    MeshEdit.AddIndex(2); 
     145    MeshEdit.AddIndex(3); 
     146    MeshEdit.AddIndex(7); 
     147    MeshEdit.AddIndex(6); 
     148 
     149    MeshEdit.AddIndex(0); 
     150    MeshEdit.AddIndex(3); 
     151    MeshEdit.AddIndex(7); 
     152    MeshEdit.AddIndex(4); 
     153    MeshEdit.AddIndex(1); 
     154    MeshEdit.AddIndex(2); 
     155    MeshEdit.AddIndex(6); 
     156    MeshEdit.AddIndex(5); 
     157 
     158    MeshEdit.EndSection(); 
     159 
     160    return BoxMesh; 
     161} 
     162 
     163lcMesh* lcCreateWireframeBoxMesh(const Vector3& Min, const Vector3& Max) 
     164{ 
     165    int NumIndices = 24; 
     166    int NumVertices = 8; 
     167 
     168    lcMesh* BoxMesh = new lcMesh(1, NumIndices, NumVertices, NULL); 
     169 
     170    lcMeshEditor<u16> MeshEdit(BoxMesh); 
     171    MeshEdit.StartSection(GL_LINES, LC_COL_DEFAULT); 
     172 
     173    MeshEdit.AddVertex(Vector3(Min[0], Min[1], Min[2])); 
     174    MeshEdit.AddVertex(Vector3(Min[0], Max[1], Min[2])); 
     175    MeshEdit.AddVertex(Vector3(Max[0], Max[1], Min[2])); 
     176    MeshEdit.AddVertex(Vector3(Max[0], Min[1], Min[2])); 
     177    MeshEdit.AddVertex(Vector3(Min[0], Min[1], Max[2])); 
     178    MeshEdit.AddVertex(Vector3(Min[0], Max[1], Max[2])); 
     179    MeshEdit.AddVertex(Vector3(Max[0], Max[1], Max[2])); 
     180    MeshEdit.AddVertex(Vector3(Max[0], Min[1], Max[2])); 
     181 
     182    MeshEdit.AddIndex(0); 
     183    MeshEdit.AddIndex(1); 
    111184    MeshEdit.AddIndex(1); 
    112185    MeshEdit.AddIndex(2); 
  • trunk/common/lc_mesh.h

    r680 r683  
    33 
    44#include "opengl.h" 
     5#include "algebra.h" 
    56 
    67class lcVertexBuffer 
     
    273274 
    274275lcMesh* lcCreateSphereMesh(float Radius, int Slices); 
     276lcMesh* lcCreateBoxMesh(const Vector3& Min, const Vector3& Max); 
    275277lcMesh* lcCreateWireframeBoxMesh(const Vector3& Min, const Vector3& Max); 
    276278 
     279void lcCreateDefaultMeshes(); 
     280void lcDestroyDefaultMeshes(); 
     281 
     282extern lcMesh* lcSphereMesh; 
     283extern lcMesh* lcBoxMesh; 
     284extern lcMesh* lcWireframeBoxMesh; 
     285 
    277286#endif 
  • trunk/common/lc_pivot.cpp

    r681 r683  
    5656void lcPivot::AddToScene(lcScene* Scene, int Color) 
    5757{ 
     58    Matrix44 ScaleMatrix(Vector4(LC_PIVOT_SIZE, 0.0f, 0.0f, 0.0f), Vector4(0.0f, LC_PIVOT_SIZE, 0.0f, 0.0f), Vector4(0.0f, 0.0f, LC_PIVOT_SIZE, 0.0f), Vector4(0.0f, 0.0f, 0.0f, 1.0f)); 
     59 
    5860    // fixme: lcPivot 
    59     static lcMesh* BoxMesh = lcCreateWireframeBoxMesh(Vector3(-LC_PIVOT_SIZE, -LC_PIVOT_SIZE, -LC_PIVOT_SIZE), Vector3(LC_PIVOT_SIZE, LC_PIVOT_SIZE, LC_PIVOT_SIZE)); 
    60  
    6161    lcRenderSection RenderSection; 
    6262 
    6363    RenderSection.Owner = this; 
    64     RenderSection.ModelWorld = m_ModelWorld; 
    65     RenderSection.Mesh = BoxMesh; 
    66     RenderSection.Section = &BoxMesh->m_Sections[0]; 
     64    RenderSection.ModelWorld = Mul(ScaleMatrix, m_ModelWorld); 
     65    RenderSection.Mesh = lcWireframeBoxMesh; 
     66    RenderSection.Section = &lcWireframeBoxMesh->m_Sections[0]; 
    6767    RenderSection.Color = 1; 
    6868