<commit_before>/*************************************************************************
 *
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 *
 * Copyright 2008 by Sun Microsystems, Inc.
 *
 * OpenOffice.org - a multi-platform office productivity suite
 *
 * $RCSfile: RelationDlg.cxx,v $
 * $Revision: 1.28 $
 *
 * This file is part of OpenOffice.org.
 *
 * OpenOffice.org is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License version 3
 * only, as published by the Free Software Foundation.
 *
 * OpenOffice.org is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License version 3 for more details
 * (a copy is included in the LICENSE file that accompanied this code).
 *
 * You should have received a copy of the GNU Lesser General Public License
 * version 3 along with OpenOffice.org.  If not, see
 * <http://www.openoffice.org/license.html>
 * for a copy of the LGPLv3 License.
 *
 ************************************************************************/

// MARKER(update_precomp.py): autogen include statement, do not remove
#include "precompiled_dbaccess.hxx"
//#ifndef _SVX_TABWIN_HXX
//#include "tabwin.hxx"
//#endif
#ifndef DBAUI_RELATIONDIALOG_HRC
#include "RelationDlg.hrc"
#endif
#ifndef DBAUI_RELATIONDIALOG_HXX
#include "RelationDlg.hxx"
#endif

#ifndef _WRKWIN_HXX //autogen
#include <vcl/wrkwin.hxx>
#endif

#ifndef _SV_SVAPP_HXX //autogen
#include <vcl/svapp.hxx>
#endif
#ifndef _DBU_DLG_HRC_
#include "dbu_dlg.hrc"
#endif
#ifndef _DBA_DBACCESS_HELPID_HRC_
#include "dbaccess_helpid.hrc"
#endif
#ifndef _COM_SUN_STAR_SDBC_KEYRULE_HPP_
#include <com/sun/star/sdbc/KeyRule.hpp>
#endif

#ifndef _TOOLS_DEBUG_HXX
#include <tools/debug.hxx>
#endif
#ifndef TOOLS_DIAGNOSE_EX_H
#include <tools/diagnose_ex.h>
#endif
#ifndef DBAUI_TOOLS_HXX
#include "UITools.hxx"
#endif
#ifndef DBAUI_JOINDESIGNVIEW_HXX
#include "JoinDesignView.hxx"
#endif
#ifndef DBAUI_JOINCONTROLLER_HXX
#include "JoinController.hxx"
#endif
#ifndef _DBHELPER_DBEXCEPTION_HXX_
#include <connectivity/dbexception.hxx>
#endif
#ifndef DBAUI_RTABLECONNECTIONDATA_HXX
#include "RTableConnectionData.hxx"
#endif
#ifndef DBAUI_RELATIONCONTROL_HXX
#include "RelationControl.hxx"
#endif
#ifndef _CPPUHELPER_EXC_HLP_HXX_
#include <cppuhelper/exc_hlp.hxx>
#endif

#include <algorithm>

using namespace ::com::sun::star::uno;
using namespace ::com::sun::star::sdbc;
using namespace ::com::sun::star::container;
using namespace ::com::sun::star::beans;
using namespace ::dbaui;
using namespace ::dbtools;

//========================================================================
// class ORelationDialog
DBG_NAME(ORelationDialog)
//========================================================================
ORelationDialog::ORelationDialog( OJoinTableView* pParent,
                                 const TTableConnectionData::value_type& pConnectionData,
                                 BOOL bAllowTableSelect )
    :ModalDialog( pParent, ModuleRes(DLG_REL_PROPERTIES) )
    ,m_pTableMap(pParent->GetTabWinMap())

    ,aFL_CascUpd(           this, ModuleRes(FL_CASC_UPD) )
    ,aRB_NoCascUpd(         this, ModuleRes(RB_NO_CASC_UPD) )
    ,aRB_CascUpd(           this, ModuleRes(RB_CASC_UPD) )
    ,aRB_CascUpdNull(       this, ModuleRes(RB_CASC_UPD_NULL) )
    ,aRB_CascUpdDefault(    this, ModuleRes(RB_CASC_UPD_DEFAULT) )
    ,aFL_CascDel(           this, ModuleRes(FL_CASC_DEL) )
    ,aRB_NoCascDel(         this, ModuleRes(RB_NO_CASC_DEL) )
    ,aRB_CascDel(           this, ModuleRes(RB_CASC_DEL) )
    ,aRB_CascDelNull(       this, ModuleRes(RB_CASC_DEL_NULL) )
    ,aRB_CascDelDefault(    this, ModuleRes(RB_CASC_DEL_DEFAULT) )

    ,aPB_OK( this, ModuleRes( PB_OK ) )
    ,aPB_CANCEL( this, ModuleRes( PB_CANCEL ) )
    ,aPB_HELP( this, ModuleRes( PB_HELP ) )

    ,m_pOrigConnData( pConnectionData )
    ,m_bTriedOneUpdate(FALSE)
{
    DBG_CTOR(ORelationDialog,NULL);

    m_xConnection = pParent->getDesignView()->getController()->getConnection();

    //////////////////////////////////////////////////////////////////////
    // Connection kopieren
    m_pConnData.reset( static_cast<ORelationTableConnectionData*>(pConnectionData->NewInstance()) );
    m_pConnData->CopyFrom( *pConnectionData );

    Init(m_pConnData);
    m_pTableControl.reset( new OTableListBoxControl(this,ModuleRes(WND_CONTROL),m_pTableMap,this) );

    aPB_OK.SetClickHdl( LINK(this, ORelationDialog, OKClickHdl) );

    m_pTableControl->Init( m_pConnData );
    if ( bAllowTableSelect )
        m_pTableControl->fillListBoxes();
    else
        m_pTableControl->fillAndDisable(pConnectionData);

    m_pTableControl->lateInit();

    m_pTableControl->NotifyCellChange();

    FreeResource();
}

//------------------------------------------------------------------------
void ORelationDialog::Init(const TTableConnectionData::value_type& _pConnectionData)
{
    ORelationTableConnectionData* pConnData = static_cast<ORelationTableConnectionData*>(_pConnectionData.get());
    // Update Rules
    switch (pConnData->GetUpdateRules())
    {
    case KeyRule::NO_ACTION:
    case KeyRule::RESTRICT:
        aRB_NoCascUpd.Check( TRUE );
        break;

    case KeyRule::CASCADE:
        aRB_CascUpd.Check( TRUE );
        break;

    case KeyRule::SET_NULL:
        aRB_CascUpdNull.Check( TRUE );
        break;
    case KeyRule::SET_DEFAULT:
        aRB_CascUpdDefault.Check( TRUE );
        break;
    }

    // Delete Rules
    switch (pConnData->GetDeleteRules())
    {
    case KeyRule::NO_ACTION:
    case KeyRule::RESTRICT:
        aRB_NoCascDel.Check( TRUE );
        break;

    case KeyRule::CASCADE:
        aRB_CascDel.Check( TRUE );
        break;

    case KeyRule::SET_NULL:
        aRB_CascDelNull.Check( TRUE );
        break;
    case KeyRule::SET_DEFAULT:
        aRB_CascDelDefault.Check( TRUE );
        break;
    }
}

//------------------------------------------------------------------------
ORelationDialog::~ORelationDialog()
{
    DBG_DTOR(ORelationDialog,NULL);
}

//------------------------------------------------------------------------

//------------------------------------------------------------------------
IMPL_LINK( ORelationDialog, OKClickHdl, Button*, /*pButton*/ )
{
    //////////////////////////////////////////////////////////////////////
    // RadioButtons auslesen
    UINT16 nAttrib = 0;

    // Delete Rules
    if( aRB_NoCascDel.IsChecked() )
        nAttrib |= KeyRule::NO_ACTION;
    if( aRB_CascDel.IsChecked() )
        nAttrib |= KeyRule::CASCADE;
    if( aRB_CascDelNull.IsChecked() )
        nAttrib |= KeyRule::SET_NULL;
    if( aRB_CascDelDefault.IsChecked() )
        nAttrib |= KeyRule::SET_DEFAULT;

    ORelationTableConnectionData* pConnData = static_cast<ORelationTableConnectionData*>(m_pConnData.get());
    pConnData->SetDeleteRules( nAttrib );

    // Update Rules
    nAttrib = 0;
    if( aRB_NoCascUpd.IsChecked() )
        nAttrib |= KeyRule::NO_ACTION;
    if( aRB_CascUpd.IsChecked() )
        nAttrib |= KeyRule::CASCADE;
    if( aRB_CascUpdNull.IsChecked() )
        nAttrib |= KeyRule::SET_NULL;
    if( aRB_CascUpdDefault.IsChecked() )
        nAttrib |= KeyRule::SET_DEFAULT;
    pConnData->SetUpdateRules( nAttrib );

    m_pTableControl->SaveModified();

    //// wenn die ComboBoxen fuer die Tabellenauswahl enabled sind (Constructor mit bAllowTableSelect==TRUE), dann muss ich in die
    //// Connection auch die Tabellennamen stecken
    //m_pConnData->SetSourceWinName(m_pTableControl->getSourceWinName());
    //m_pConnData->SetDestWinName(m_pTableControl->getDestWinName());

    // try to create the relation
    try
    {
        ORelationTableConnectionData* pOrigConnData = static_cast<ORelationTableConnectionData*>(m_pOrigConnData.get());
        if (*pConnData != *pOrigConnData || pConnData->Update())
        {
            m_pOrigConnData->CopyFrom( *m_pConnData );
            EndDialog( RET_OK );
            return 0L;
        }
    }
    catch( const SQLException& )
    {
        ::dbaui::showError( SQLExceptionInfo( ::cppu::getCaughtException() ),
                            this,
                            static_cast<OJoinTableView*>(GetParent())->getDesignView()->getController()->getORB());
    }
    catch( const Exception& )
    {
        DBG_UNHANDLED_EXCEPTION();
    }

    m_bTriedOneUpdate = TRUE;
    // this means that the original connection may be lost (if m_pConnData was not a newly created but an
    // existent conn to be modified), which we reflect by returning RET_NO (see ::Execute)

    // try again
    Init(m_pConnData);
    m_pTableControl->Init( m_pConnData );
    m_pTableControl->lateInit();

    return 0;
}

//------------------------------------------------------------------------
short ORelationDialog::Execute()
{
    short nResult = ModalDialog::Execute();
    if ((nResult != RET_OK) && m_bTriedOneUpdate)
        return RET_NO;

    return nResult;
}
// -----------------------------------------------------------------------------
TTableConnectionData::value_type ORelationDialog::getConnectionData() const
{
    return m_pConnData;
}
// -----------------------------------------------------------------------------
void ORelationDialog::setValid(sal_Bool _bValid)
{
    aPB_OK.Enable(_bValid);
}
// -----------------------------------------------------------------------------
void ORelationDialog::notifyConnectionChange()
{
    Init(m_pConnData);
}
// -----------------------------------------------------------------------------

<commit_msg>INTEGRATION: CWS dba30d (1.28.10); FILE MERGED 2008/05/29 11:28:35 fs 1.28.10.1: during #i80943#: refactoring: IController now passed around as reference, not as pointer<commit_after>/*************************************************************************
 *
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 *
 * Copyright 2008 by Sun Microsystems, Inc.
 *
 * OpenOffice.org - a multi-platform office productivity suite
 *
 * $RCSfile: RelationDlg.cxx,v $
 * $Revision: 1.29 $
 *
 * This file is part of OpenOffice.org.
 *
 * OpenOffice.org is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License version 3
 * only, as published by the Free Software Foundation.
 *
 * OpenOffice.org is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License version 3 for more details
 * (a copy is included in the LICENSE file that accompanied this code).
 *
 * You should have received a copy of the GNU Lesser General Public License
 * version 3 along with OpenOffice.org.  If not, see
 * <http://www.openoffice.org/license.html>
 * for a copy of the LGPLv3 License.
 *
 ************************************************************************/

// MARKER(update_precomp.py): autogen include statement, do not remove
#include "precompiled_dbaccess.hxx"
//#ifndef _SVX_TABWIN_HXX
//#include "tabwin.hxx"
//#endif
#ifndef DBAUI_RELATIONDIALOG_HRC
#include "RelationDlg.hrc"
#endif
#ifndef DBAUI_RELATIONDIALOG_HXX
#include "RelationDlg.hxx"
#endif

#ifndef _WRKWIN_HXX //autogen
#include <vcl/wrkwin.hxx>
#endif

#ifndef _SV_SVAPP_HXX //autogen
#include <vcl/svapp.hxx>
#endif
#ifndef _DBU_DLG_HRC_
#include "dbu_dlg.hrc"
#endif
#ifndef _DBA_DBACCESS_HELPID_HRC_
#include "dbaccess_helpid.hrc"
#endif
#ifndef _COM_SUN_STAR_SDBC_KEYRULE_HPP_
#include <com/sun/star/sdbc/KeyRule.hpp>
#endif

#ifndef _TOOLS_DEBUG_HXX
#include <tools/debug.hxx>
#endif
#ifndef TOOLS_DIAGNOSE_EX_H
#include <tools/diagnose_ex.h>
#endif
#ifndef DBAUI_TOOLS_HXX
#include "UITools.hxx"
#endif
#ifndef DBAUI_JOINDESIGNVIEW_HXX
#include "JoinDesignView.hxx"
#endif
#ifndef DBAUI_JOINCONTROLLER_HXX
#include "JoinController.hxx"
#endif
#ifndef _DBHELPER_DBEXCEPTION_HXX_
#include <connectivity/dbexception.hxx>
#endif
#ifndef DBAUI_RTABLECONNECTIONDATA_HXX
#include "RTableConnectionData.hxx"
#endif
#ifndef DBAUI_RELATIONCONTROL_HXX
#include "RelationControl.hxx"
#endif
#ifndef _CPPUHELPER_EXC_HLP_HXX_
#include <cppuhelper/exc_hlp.hxx>
#endif

#include <algorithm>

using namespace ::com::sun::star::uno;
using namespace ::com::sun::star::sdbc;
using namespace ::com::sun::star::container;
using namespace ::com::sun::star::beans;
using namespace ::dbaui;
using namespace ::dbtools;

//========================================================================
// class ORelationDialog
DBG_NAME(ORelationDialog)
//========================================================================
ORelationDialog::ORelationDialog( OJoinTableView* pParent,
                                 const TTableConnectionData::value_type& pConnectionData,
                                 BOOL bAllowTableSelect )
    :ModalDialog( pParent, ModuleRes(DLG_REL_PROPERTIES) )
    ,m_pTableMap(pParent->GetTabWinMap())

    ,aFL_CascUpd(           this, ModuleRes(FL_CASC_UPD) )
    ,aRB_NoCascUpd(         this, ModuleRes(RB_NO_CASC_UPD) )
    ,aRB_CascUpd(           this, ModuleRes(RB_CASC_UPD) )
    ,aRB_CascUpdNull(       this, ModuleRes(RB_CASC_UPD_NULL) )
    ,aRB_CascUpdDefault(    this, ModuleRes(RB_CASC_UPD_DEFAULT) )
    ,aFL_CascDel(           this, ModuleRes(FL_CASC_DEL) )
    ,aRB_NoCascDel(         this, ModuleRes(RB_NO_CASC_DEL) )
    ,aRB_CascDel(           this, ModuleRes(RB_CASC_DEL) )
    ,aRB_CascDelNull(       this, ModuleRes(RB_CASC_DEL_NULL) )
    ,aRB_CascDelDefault(    this, ModuleRes(RB_CASC_DEL_DEFAULT) )

    ,aPB_OK( this, ModuleRes( PB_OK ) )
    ,aPB_CANCEL( this, ModuleRes( PB_CANCEL ) )
    ,aPB_HELP( this, ModuleRes( PB_HELP ) )

    ,m_pOrigConnData( pConnectionData )
    ,m_bTriedOneUpdate(FALSE)
{
    DBG_CTOR(ORelationDialog,NULL);

    m_xConnection = pParent->getDesignView()->getController().getConnection();

    //////////////////////////////////////////////////////////////////////
    // Connection kopieren
    m_pConnData.reset( static_cast<ORelationTableConnectionData*>(pConnectionData->NewInstance()) );
    m_pConnData->CopyFrom( *pConnectionData );

    Init(m_pConnData);
    m_pTableControl.reset( new OTableListBoxControl(this,ModuleRes(WND_CONTROL),m_pTableMap,this) );

    aPB_OK.SetClickHdl( LINK(this, ORelationDialog, OKClickHdl) );

    m_pTableControl->Init( m_pConnData );
    if ( bAllowTableSelect )
        m_pTableControl->fillListBoxes();
    else
        m_pTableControl->fillAndDisable(pConnectionData);

    m_pTableControl->lateInit();

    m_pTableControl->NotifyCellChange();

    FreeResource();
}

//------------------------------------------------------------------------
void ORelationDialog::Init(const TTableConnectionData::value_type& _pConnectionData)
{
    ORelationTableConnectionData* pConnData = static_cast<ORelationTableConnectionData*>(_pConnectionData.get());
    // Update Rules
    switch (pConnData->GetUpdateRules())
    {
    case KeyRule::NO_ACTION:
    case KeyRule::RESTRICT:
        aRB_NoCascUpd.Check( TRUE );
        break;

    case KeyRule::CASCADE:
        aRB_CascUpd.Check( TRUE );
        break;

    case KeyRule::SET_NULL:
        aRB_CascUpdNull.Check( TRUE );
        break;
    case KeyRule::SET_DEFAULT:
        aRB_CascUpdDefault.Check( TRUE );
        break;
    }

    // Delete Rules
    switch (pConnData->GetDeleteRules())
    {
    case KeyRule::NO_ACTION:
    case KeyRule::RESTRICT:
        aRB_NoCascDel.Check( TRUE );
        break;

    case KeyRule::CASCADE:
        aRB_CascDel.Check( TRUE );
        break;

    case KeyRule::SET_NULL:
        aRB_CascDelNull.Check( TRUE );
        break;
    case KeyRule::SET_DEFAULT:
        aRB_CascDelDefault.Check( TRUE );
        break;
    }
}

//------------------------------------------------------------------------
ORelationDialog::~ORelationDialog()
{
    DBG_DTOR(ORelationDialog,NULL);
}

//------------------------------------------------------------------------

//------------------------------------------------------------------------
IMPL_LINK( ORelationDialog, OKClickHdl, Button*, /*pButton*/ )
{
    //////////////////////////////////////////////////////////////////////
    // RadioButtons auslesen
    UINT16 nAttrib = 0;

    // Delete Rules
    if( aRB_NoCascDel.IsChecked() )
        nAttrib |= KeyRule::NO_ACTION;
    if( aRB_CascDel.IsChecked() )
        nAttrib |= KeyRule::CASCADE;
    if( aRB_CascDelNull.IsChecked() )
        nAttrib |= KeyRule::SET_NULL;
    if( aRB_CascDelDefault.IsChecked() )
        nAttrib |= KeyRule::SET_DEFAULT;

    ORelationTableConnectionData* pConnData = static_cast<ORelationTableConnectionData*>(m_pConnData.get());
    pConnData->SetDeleteRules( nAttrib );

    // Update Rules
    nAttrib = 0;
    if( aRB_NoCascUpd.IsChecked() )
        nAttrib |= KeyRule::NO_ACTION;
    if( aRB_CascUpd.IsChecked() )
        nAttrib |= KeyRule::CASCADE;
    if( aRB_CascUpdNull.IsChecked() )
        nAttrib |= KeyRule::SET_NULL;
    if( aRB_CascUpdDefault.IsChecked() )
        nAttrib |= KeyRule::SET_DEFAULT;
    pConnData->SetUpdateRules( nAttrib );

    m_pTableControl->SaveModified();

    //// wenn die ComboBoxen fuer die Tabellenauswahl enabled sind (Constructor mit bAllowTableSelect==TRUE), dann muss ich in die
    //// Connection auch die Tabellennamen stecken
    //m_pConnData->SetSourceWinName(m_pTableControl->getSourceWinName());
    //m_pConnData->SetDestWinName(m_pTableControl->getDestWinName());

    // try to create the relation
    try
    {
        ORelationTableConnectionData* pOrigConnData = static_cast<ORelationTableConnectionData*>(m_pOrigConnData.get());
        if (*pConnData != *pOrigConnData || pConnData->Update())
        {
            m_pOrigConnData->CopyFrom( *m_pConnData );
            EndDialog( RET_OK );
            return 0L;
        }
    }
    catch( const SQLException& )
    {
        ::dbaui::showError( SQLExceptionInfo( ::cppu::getCaughtException() ),
                            this,
                            static_cast<OJoinTableView*>(GetParent())->getDesignView()->getController().getORB());
    }
    catch( const Exception& )
    {
        DBG_UNHANDLED_EXCEPTION();
    }

    m_bTriedOneUpdate = TRUE;
    // this means that the original connection may be lost (if m_pConnData was not a newly created but an
    // existent conn to be modified), which we reflect by returning RET_NO (see ::Execute)

    // try again
    Init(m_pConnData);
    m_pTableControl->Init( m_pConnData );
    m_pTableControl->lateInit();

    return 0;
}

//------------------------------------------------------------------------
short ORelationDialog::Execute()
{
    short nResult = ModalDialog::Execute();
    if ((nResult != RET_OK) && m_bTriedOneUpdate)
        return RET_NO;

    return nResult;
}
// -----------------------------------------------------------------------------
TTableConnectionData::value_type ORelationDialog::getConnectionData() const
{
    return m_pConnData;
}
// -----------------------------------------------------------------------------
void ORelationDialog::setValid(sal_Bool _bValid)
{
    aPB_OK.Enable(_bValid);
}
// -----------------------------------------------------------------------------
void ORelationDialog::notifyConnectionChange()
{
    Init(m_pConnData);
}
// -----------------------------------------------------------------------------

<|endoftext|>


<commit_before>/*
 *  Copyright 2014 Nathaniel Lewis, Matthew Bucci, Anthony Popelar, Brian Bamsch
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *  http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */

#include "GLMesh.h"

// Open asset importer library
#include <assimp/Importer.hpp>
#include <assimp/postprocess.h>
#include <assimp/scene.h>
#include <assimp/vector3.h>

// Default constructor (loads all submeshes from model file)
GLMesh::GLMesh(const std::string& directory, const std::string& name, TextureCache& _textureCache) : textureCache(_textureCache)
{
    // Get the filename
    std::string filename = directory + "/" + name;

    // Create an importer object for asset importer
    Assimp::Importer Importer;

    // Load a model with the asset importer
    const aiScene* pScene = Importer.ReadFile(filename.c_str(), aiProcess_Triangulate | aiProcess_GenSmoothNormals | aiProcess_FlipUVs);

    // If the import failed, we have a problem
    if(!pScene)
    {
        SDL_LogError(SDL_LOG_CATEGORY_ERROR, "Error parsing '%s': '%s'\n", filename.c_str(), Importer.GetErrorString());
        throw std::exception();
    }

    // Initialize all of the submeshes
    for(unsigned int i = 0; i < pScene->mNumMeshes; i++)
    {
        // Get a pointer to the mesh in question
        const aiMesh *mesh = pScene->mMeshes[i];

        // Create a submesh object
        Submesh *submesh = new Submesh();

        // Set the material id
        submesh->material = mesh->mMaterialIndex;

        // Copy the vertex data from the mesh
        glBindBuffer(GL_ARRAY_BUFFER, submesh->vertexBuffer);
        glBufferData(GL_ARRAY_BUFFER, mesh->mNumVertices * sizeof(aiVector3D), mesh->mVertices, GL_STATIC_DRAW);

        // Copy the normal data form the mesh
        glBindBuffer(GL_ARRAY_BUFFER, submesh->normalBuffer);
        glBufferData(GL_ARRAY_BUFFER, mesh->mNumVertices * sizeof(aiVector3D), mesh->mNormals, GL_STATIC_DRAW);

        // Copy the texture coordinates from the mesh
        glBindBuffer(GL_ARRAY_BUFFER, submesh->textureCoordinateBuffer);
        glBufferData(GL_ARRAY_BUFFER, mesh->mNumVertices * sizeof(aiVector3D), mesh->mTextureCoords[0], GL_STATIC_DRAW);

        // Build the index buffer
        std::vector<unsigned int> indexBuffer;
        for(unsigned j = 0; j < mesh->mNumFaces; j++)
        {
            // Get the face
            const aiFace       *face = &(mesh->mFaces[j]);
            const unsigned int *it   = face->mIndices;

            // Make sure this face has the correct number of indices
            _ASSERTE(face->mNumIndices == 3);

            // Insert this data into the index buffer
            indexBuffer.insert(indexBuffer.end(), it, it+3);
        }

        // Upload the index buffer to the GPU
        glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, submesh->indexBuffer);
        glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(unsigned int) * indexBuffer.size(), indexBuffer.data(), GL_STATIC_DRAW);
        submesh->indexCount = indexBuffer.size();

        // Add this submesh to the mesh
        submeshes.push_back(submesh);
    }

    // Load textures for this model
    for (unsigned int i = 0 ; i < pScene->mNumMaterials ; i++)
    {
        // Get a pointer to the material
        const aiMaterial* material = pScene->mMaterials[i];

        // If this maerial has textures associated with it
        if (material->GetTextureCount(aiTextureType_DIFFUSE))
        {
            // Get the name of the texture
            aiString Path;

            // Get the texture name
            if (material->GetTexture(aiTextureType_DIFFUSE, 0, &Path, NULL, NULL, NULL, NULL, NULL) == AI_SUCCESS)
            {
                // Calculate the path to the mesh
                std::string path = directory + "/" + Path.data;

                // Cache this texture
                textureCache.GetTexture(path);

                // Push back this path
                textures.push_back(path);
            }
        }
    }

    // Success
    SDL_Log("Loaded mesh: \"%s\"\n", filename.c_str());
}

// Destroy this mesh
GLMesh::~GLMesh()
{
    // Iterate through all the submeshes
    for(std::vector<Submesh *>::iterator it = submeshes.begin(); it != submeshes.end(); ++it)
    {
        delete *it;
    }
}

// Draw this mesh
void GLMesh::Draw(GL3DProgram *shader)
{
    // Iterate through all the submeshes
    for(std::vector<Submesh *>::iterator it = submeshes.begin(); it != submeshes.end(); ++it)
    {
#if !(defined __ANDROID__)
        // Bind the vertex array object
        glBindVertexArray((*it)->attributes);

        // If the shader has changed, reload the vertex array object pointers
        if(shader != priorShader)
        {
            // Enable the vertex array object attributes that we will be using
            glEnableVertexAttribArray(shader->AttributeVertex());
            glEnableVertexAttribArray(shader->AttributeNormal());
            glEnableVertexAttribArray(shader->AttributeTexture());
#endif
            // Set the vertex attribute pointer
            glBindBuffer(GL_ARRAY_BUFFER, (*it)->vertexBuffer);
            glVertexAttribPointer(shader->AttributeVertex(), 3, GL_FLOAT, GL_FALSE, 0, 0);

            // Set the normal attribute pointer
            glBindBuffer(GL_ARRAY_BUFFER, (*it)->normalBuffer);
            glVertexAttribPointer(shader->AttributeNormal(), 3, GL_FLOAT, GL_FALSE, 0, 0);

            // Set the texture coordinate attribute pointer
            glBindBuffer(GL_ARRAY_BUFFER, (*it)->textureCoordinateBuffer);
            glVertexAttribPointer(shader->AttributeTexture(), 3, GL_FLOAT, GL_FALSE, 0, 0);

            // Set the index buffer
            glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, (*it)->indexBuffer);

#if !(defined __ANDROID__)
        }
#endif
        // Bind the texture
        glActiveTexture(GL_TEXTURE0);
        textureCache.GetTexture(*(textures.begin() + (*it)->material))->Bind();

        // Set the reflectivity
        glm::vec2 specular = glm::vec2(1.0, 1.0);
        glUniform2fv(glGetUniformLocation(shader->GetId(), "material_reflectivity"), 2, (const GLfloat *) &specular);

        // Draw this mesh
        glDrawElements(GL_TRIANGLES, (*it)->indexCount, GL_UNSIGNED_INT, 0);
    }

    // Store the new shader pointer
    priorShader = shader;
}

// Initialization of the submesh object
GLMesh::Submesh::Submesh()
{
#if !(defined __ANDROID__)
    // Generate a vertex array
    glGenVertexArrays(1, &attributes);
#endif

    // Generate the buffers for the submesh
    glGenBuffers(4, buffers);
}

// Deletion of the submesh object
GLMesh::Submesh::~Submesh()
{
#if !(defined __ANDROID__)
    // Generate a vertex array
    glDeleteVertexArrays(1, &attributes);
#endif
    // Delete the buffers
    glDeleteBuffers(4, buffers);
}<commit_msg>Edited the logging system for GLMesh<commit_after>/*
 *  Copyright 2014 Nathaniel Lewis, Matthew Bucci, Anthony Popelar, Brian Bamsch
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *  http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */

#include "GLMesh.h"

// Open asset importer library
#include <assimp/Importer.hpp>
#include <assimp/postprocess.h>
#include <assimp/scene.h>
#include <assimp/vector3.h>

// Default constructor (loads all submeshes from model file)
GLMesh::GLMesh(const std::string& directory, const std::string& name, TextureCache& _textureCache) : textureCache(_textureCache)
{

    // Get the filename
    std::string filename = directory + "/" + name;

    // Create an importer object for asset importer
    Assimp::Importer Importer;

    // Load a model with the asset importer
    const aiScene* pScene = Importer.ReadFile(filename.c_str(), aiProcess_Triangulate | aiProcess_GenSmoothNormals | aiProcess_FlipUVs);

    // If the import failed, we have a problem
    if(!pScene)
    {
        std::cerr << "Error parsing " << filename << ": " << Importer.GetErrorString() << std::endl;
        throw std::exception();
    }

    // Initialize all of the submeshes
    for(unsigned int i = 0; i < pScene->mNumMeshes; i++)
    {
        // Get a pointer to the mesh in question
        const aiMesh *mesh = pScene->mMeshes[i];

        // Create a submesh object
        Submesh *submesh = new Submesh();

        // Set the material id
        submesh->material = mesh->mMaterialIndex;

        // Copy the vertex data from the mesh
        glBindBuffer(GL_ARRAY_BUFFER, submesh->vertexBuffer);
        glBufferData(GL_ARRAY_BUFFER, mesh->mNumVertices * sizeof(aiVector3D), mesh->mVertices, GL_STATIC_DRAW);

        // Copy the normal data form the mesh
        glBindBuffer(GL_ARRAY_BUFFER, submesh->normalBuffer);
        glBufferData(GL_ARRAY_BUFFER, mesh->mNumVertices * sizeof(aiVector3D), mesh->mNormals, GL_STATIC_DRAW);

        // Copy the texture coordinates from the mesh
        glBindBuffer(GL_ARRAY_BUFFER, submesh->textureCoordinateBuffer);
        glBufferData(GL_ARRAY_BUFFER, mesh->mNumVertices * sizeof(aiVector3D), mesh->mTextureCoords[0], GL_STATIC_DRAW);

        // Build the index buffer
        std::vector<unsigned int> indexBuffer;
        for(unsigned j = 0; j < mesh->mNumFaces; j++)
        {
            // Get the face
            const aiFace       *face = &(mesh->mFaces[j]);
            const unsigned int *it   = face->mIndices;

            // Make sure this face has the correct number of indices
            _ASSERTE(face->mNumIndices == 3);

            // Insert this data into the index buffer
            indexBuffer.insert(indexBuffer.end(), it, it+3);
        }

        // Upload the index buffer to the GPU
        glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, submesh->indexBuffer);
        glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(unsigned int) * indexBuffer.size(), indexBuffer.data(), GL_STATIC_DRAW);
        submesh->indexCount = indexBuffer.size();

        // Add this submesh to the mesh
        submeshes.push_back(submesh);
    }

    // Load textures for this model
    for (unsigned int i = 0 ; i < pScene->mNumMaterials ; i++)
    {
        // Get a pointer to the material
        const aiMaterial* material = pScene->mMaterials[i];

        // If this maerial has textures associated with it
        if (material->GetTextureCount(aiTextureType_DIFFUSE))
        {
            // Get the name of the texture
            aiString Path;

            // Get the texture name
            if (material->GetTexture(aiTextureType_DIFFUSE, 0, &Path, NULL, NULL, NULL, NULL, NULL) == AI_SUCCESS)
            {
                // Calculate the path to the mesh
                std::string path = directory + "/" + Path.data;

                // Cache this texture
                textureCache.GetTexture(path);

                // Push back this path
                textures.push_back(path);
            }
        }
    }

    // Success
    std::cout << "Loaded mesh: \"" << filename.c_str() << "\"" << std::endl;
}

// Destroy this mesh
GLMesh::~GLMesh()
{
    // Iterate through all the submeshes
    for(std::vector<Submesh *>::iterator it = submeshes.begin(); it != submeshes.end(); ++it)
    {
        delete *it;
    }
}

// Draw this mesh
void GLMesh::Draw(GL3DProgram *shader)
{
    // Iterate through all the submeshes
    for(std::vector<Submesh *>::iterator it = submeshes.begin(); it != submeshes.end(); ++it)
    {
#if !(defined __ANDROID__)
        // Bind the vertex array object
        glBindVertexArray((*it)->attributes);

        // If the shader has changed, reload the vertex array object pointers
        if(shader != priorShader)
        {
            // Enable the vertex array object attributes that we will be using
            glEnableVertexAttribArray(shader->AttributeVertex());
            glEnableVertexAttribArray(shader->AttributeNormal());
            glEnableVertexAttribArray(shader->AttributeTexture());
#endif
            // Set the vertex attribute pointer
            glBindBuffer(GL_ARRAY_BUFFER, (*it)->vertexBuffer);
            glVertexAttribPointer(shader->AttributeVertex(), 3, GL_FLOAT, GL_FALSE, 0, 0);

            // Set the normal attribute pointer
            glBindBuffer(GL_ARRAY_BUFFER, (*it)->normalBuffer);
            glVertexAttribPointer(shader->AttributeNormal(), 3, GL_FLOAT, GL_FALSE, 0, 0);

            // Set the texture coordinate attribute pointer
            glBindBuffer(GL_ARRAY_BUFFER, (*it)->textureCoordinateBuffer);
            glVertexAttribPointer(shader->AttributeTexture(), 3, GL_FLOAT, GL_FALSE, 0, 0);

            // Set the index buffer
            glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, (*it)->indexBuffer);

#if !(defined __ANDROID__)
        }
#endif
        // Bind the texture
        glActiveTexture(GL_TEXTURE0);
        textureCache.GetTexture(*(textures.begin() + (*it)->material))->Bind();

        // Set the reflectivity
        glm::vec2 specular = glm::vec2(1.0, 1.0);
        glUniform2fv(glGetUniformLocation(shader->GetId(), "material_reflectivity"), 2, (const GLfloat *) &specular);

        // Draw this mesh
        glDrawElements(GL_TRIANGLES, (*it)->indexCount, GL_UNSIGNED_INT, 0);
    }

    // Store the new shader pointer
    priorShader = shader;
}

// Initialization of the submesh object
GLMesh::Submesh::Submesh()
{
#if !(defined __ANDROID__)
    // Generate a vertex array
    glGenVertexArrays(1, &attributes);
#endif

    // Generate the buffers for the submesh
    glGenBuffers(4, buffers);
}

// Deletion of the submesh object
GLMesh::Submesh::~Submesh()
{
#if !(defined __ANDROID__)
    // Generate a vertex array
    glDeleteVertexArrays(1, &attributes);
#endif
    // Delete the buffers
    glDeleteBuffers(4, buffers);
}<|endoftext|>


<commit_before>/*************************************************************************
 *
 *  $RCSfile: GeneralUndo.hxx,v $
 *
 *  $Revision: 1.3 $
 *
 *  last change: $Author: hr $ $Date: 2004-05-10 13:07:11 $
 *
 *  The Contents of this file are made available subject to the terms of
 *  either of the following licenses
 *
 *         - GNU Lesser General Public License Version 2.1
 *         - Sun Industry Standards Source License Version 1.1
 *
 *  Sun Microsystems Inc., October, 2000
 *
 *  GNU Lesser General Public License Version 2.1
 *  =============================================
 *  Copyright 2000 by Sun Microsystems, Inc.
 *  901 San Antonio Road, Palo Alto, CA 94303, USA
 *
 *  This library is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU Lesser General Public
 *  License version 2.1, as published by the Free Software Foundation.
 *
 *  This library is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *  Lesser General Public License for more details.
 *
 *  You should have received a copy of the GNU Lesser General Public
 *  License along with this library; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston,
 *  MA  02111-1307  USA
 *
 *
 *  Sun Industry Standards Source License Version 1.1
 *  =================================================
 *  The contents of this file are subject to the Sun Industry Standards
 *  Source License Version 1.1 (the License); You may not use this file
 *  except in compliance with the License. You may obtain a copy of the
 *  License at http://www.openoffice.org/license.html.
 *
 *  Software provided under this License is provided on an AS IS basis,
 *  WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
 *  WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
 *  MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
 *  See the License for the specific provisions governing your rights and
 *  obligations concerning the Software.
 *
 *  The Initial Developer of the Original Code is: Sun Microsystems, Inc.
 *
 *  Copyright: 2000 by Sun Microsystems, Inc.
 *
 *  All Rights Reserved.
 *
 *  Contributor(s): _______________________________________
 *
 *
 ************************************************************************/
#ifndef DBAUI_GENERALUNDO_HXX
#define DBAUI_GENERALUNDO_HXX

#ifndef _UNDO_HXX
#include <svtools/undo.hxx>
#endif
#ifndef _DBAUI_MODULE_DBU_HXX_
#include "moduledbu.hxx"
#endif

namespace dbaui
{
    // ================================================================================================
    // SbaCommentUndoAction - Undo-Basisklasse fuer Aktionen, deren GetComment einen aus einer Sba-Ressource
    // geladenen String liefert

    class OCommentUndoAction : public SfxUndoAction
    {
    protected:
        String  m_strComment; // undo, redo comment

    public:
        TYPEINFO();
        OCommentUndoAction(USHORT nCommentID) { m_strComment = String(ModuleRes(nCommentID)); }

        virtual UniString   GetComment() const { return m_strComment; }
    };
}
#endif // DBAUI_GENERALUNDO_HXX

<commit_msg>INTEGRATION: CWS ooo19126 (1.3.236); FILE MERGED 2005/09/05 17:34:18 rt 1.3.236.1: #i54170# Change license header: remove SISSL<commit_after>/*************************************************************************
 *
 *  OpenOffice.org - a multi-platform office productivity suite
 *
 *  $RCSfile: GeneralUndo.hxx,v $
 *
 *  $Revision: 1.4 $
 *
 *  last change: $Author: rt $ $Date: 2005-09-08 15:17:41 $
 *
 *  The Contents of this file are made available subject to
 *  the terms of GNU Lesser General Public License Version 2.1.
 *
 *
 *    GNU Lesser General Public License Version 2.1
 *    =============================================
 *    Copyright 2005 by Sun Microsystems, Inc.
 *    901 San Antonio Road, Palo Alto, CA 94303, USA
 *
 *    This library is free software; you can redistribute it and/or
 *    modify it under the terms of the GNU Lesser General Public
 *    License version 2.1, as published by the Free Software Foundation.
 *
 *    This library is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *    Lesser General Public License for more details.
 *
 *    You should have received a copy of the GNU Lesser General Public
 *    License along with this library; if not, write to the Free Software
 *    Foundation, Inc., 59 Temple Place, Suite 330, Boston,
 *    MA  02111-1307  USA
 *
 ************************************************************************/
#ifndef DBAUI_GENERALUNDO_HXX
#define DBAUI_GENERALUNDO_HXX

#ifndef _UNDO_HXX
#include <svtools/undo.hxx>
#endif
#ifndef _DBAUI_MODULE_DBU_HXX_
#include "moduledbu.hxx"
#endif

namespace dbaui
{
    // ================================================================================================
    // SbaCommentUndoAction - Undo-Basisklasse fuer Aktionen, deren GetComment einen aus einer Sba-Ressource
    // geladenen String liefert

    class OCommentUndoAction : public SfxUndoAction
    {
    protected:
        String  m_strComment; // undo, redo comment

    public:
        TYPEINFO();
        OCommentUndoAction(USHORT nCommentID) { m_strComment = String(ModuleRes(nCommentID)); }

        virtual UniString   GetComment() const { return m_strComment; }
    };
}
#endif // DBAUI_GENERALUNDO_HXX

<|endoftext|>


<commit_before>// TODO: Create Quadrilateralized spherical cube

#include "Planet.hpp"
#include <math.h>

Planet::Planet(IrrlichtDevice* Device, const stringw Name, const io::path &Texture, const f32 Radius)
{
	m_pDevice			= Device;
	m_pSMgr 			= Device->getSceneManager();
	m_pDriver 			= Device->getVideoDriver();

	m_pShowWireframe 	= false;
	m_pShowPointCloud 	= false;
	m_pShowBoundingBox 	= false;
	m_pShowNormal 		= false;
	m_pShowVelocity 	= false;

	m_pName 			= Name;

	// m_pSceneNode 	= m_pSMgr->addSphereSceneNode(Radius, 160, 0, -1, vector3df(0, 0, 0), vector3df(0, 0, 0));
	m_pSceneNode		= m_pSMgr->addMeshSceneNode(createPlanetMesh(Radius));

	m_pSceneNode->setMaterialFlag(video::EMF_LIGHTING, false);

	m_pSceneNode->setMaterialTexture(0, m_pDriver->getTexture("../assets/cubemap/earth/top.png"));
}

Planet::~Planet()
{
}

SMeshBuffer* Planet::createPlanetQLSCFaceMeshBuffer(const f32 Radius, const vector3df Normal)
{
	const f32 circ 		= 2 * 3.141592 * Radius;
	const f32 range 	= circ / 4;

	const u32 polyCount = 90;

	SMeshBuffer* buffer = new SMeshBuffer();
	S3DVertex vtx;
	vtx.Color.set(255, 255, 255, 255);
	vtx.Pos.set(0, 0, -Radius);

	// Create the vertices
	for (u32 xx = 0; xx < polyCount; ++xx)
	{
		for (u32 yy = 0; yy < polyCount; ++yy)
		{
			vtx.Pos.X = (f32)xx / (f32)polyCount * Radius - Radius * 0.5;
			vtx.Pos.Y = (f32)yy / (f32)polyCount * Radius - Radius * 0.5;
			vtx.TCoords.set((f32)xx / (f32)polyCount, (f32)yy / (f32)polyCount);
			buffer->Vertices.push_back(vtx);
		}
	}

	// Create the indices
	for (u32 xx = 0; xx < polyCount - 1; ++xx)
	{
		for (u32 yy = 0; yy < polyCount - 1; ++yy)
		{
			const u32 cur = xx * polyCount + yy;

			buffer->Indices.push_back(cur);
			buffer->Indices.push_back(cur + 1);
			buffer->Indices.push_back(cur + polyCount);

			buffer->Indices.push_back(cur + 1);
			buffer->Indices.push_back(cur + 1 + polyCount);
			buffer->Indices.push_back(cur + polyCount);
		}
	}

	// Recalculate Normals

	buffer->recalculateBoundingBox();
	buffer->setHardwareMappingHint(EHM_STATIC);

	return buffer;
}

IMesh* Planet::createPlanetMesh(const f32 Radius)
{
	SMesh* mesh 		= new SMesh;
	SMeshBuffer* face 	= 0;

	face = createPlanetQLSCFaceMeshBuffer(Radius, vector3df(1, 0, 0));
	mesh->addMeshBuffer(face);
	face->drop();

	// face = createPlanetQLSCFaceMeshBuffer(Radius, vector3df(0, 1, 0));
	// mesh->addMeshBuffer(face);
	// face->drop();

	// face = createPlanetQLSCFaceMeshBuffer(Radius, vector3df(0, 0, 1));
	// mesh->addMeshBuffer(face);
	// face->drop();

	// face = createPlanetQLSCFaceMeshBuffer(Radius, vector3df(-1, 0, 0));
	// mesh->addMeshBuffer(face);
	// face->drop();

	// face = createPlanetQLSCFaceMeshBuffer(Radius, vector3df(0, -1, 0));
	// mesh->addMeshBuffer(face);
	// face->drop();

	// face = createPlanetQLSCFaceMeshBuffer(Radius, vector3df(0, 0, -1));
	// mesh->addMeshBuffer(face);
	// face->drop();

	mesh->recalculateBoundingBox();

	return mesh;
}

// virtual void Planet::OnRegisterSceneNode()
// {
// 	if (IsVisible)
// 		m_pSMgr->registerNodeForRendering(this);

// 	ISceneNode::OnRegisterSceneNode();
// }

// virtual void Planet::render()
// {
// 	u16 indices[] = {   0,2,3, 2,1,3, 1,0,3, 2,0,1  };
// 	video::IVideoDriver* driver = SceneManager->getVideoDriver();

// 	driver->setMaterial(m_pMaterial);
// 	driver->setTransform(video::ETS_WORLD, AbsoluteTransformation);
// 	driver->drawVertexPrimitiveList(&Vertices[0], 4, &indices[0], 4, video::EVT_STANDARD, scene::EPT_TRIANGLES, video::EIT_16BIT);
// }

// virtual const core::aabbox3d<f32>& Planet::getBoundingBox() const
// {
// 	return Box;
// }

// virtual u32 Planet::getMaterialCount() const
// {
// 	return 1;
// }

// virtual video::SMaterial& Planet::getMaterial(u32 i)
// {
// 	return Material;
// }

void Planet::setName(stringw Name)
{
	m_pName = Name;
}
stringw Planet::getName()
{
	return m_pName;
}

void Planet::showWireframe(const bool State)
{
	if (m_pSceneNode != 0)
	{
		m_pSceneNode->setMaterialFlag(video::EMF_WIREFRAME, State);
		if (State) showPointCloud(false);
	}

	m_pShowWireframe = State;
}

void Planet::showPointCloud(const bool State)
{
	if (m_pSceneNode != 0)
	{
		m_pSceneNode->setMaterialFlag(video::EMF_POINTCLOUD, State);
		if (State) showWireframe(false);
	}

	m_pShowPointCloud = State;
}

void Planet::showBoundingBox(const bool State)
{
	// TODO: Show/hide bounding box
	m_pShowBoundingBox = State;
}

void Planet::showNormal(const bool State)
{
	// TODO: Show/hide normals
	m_pShowNormal = State;
}

void Planet::showVelocity(const bool State)
{
	// TODO: Show/hide velocity markers
	m_pShowVelocity = State;
}<commit_msg>Minor refactor<commit_after>// TODO: Create Quadrilateralized spherical cube

#include "Planet.hpp"
#include <math.h>

Planet::Planet(IrrlichtDevice* Device, const stringw Name, const io::path &Texture, const f32 Radius)
{
	m_pDevice			= Device;
	m_pSMgr 			= Device->getSceneManager();
	m_pDriver 			= Device->getVideoDriver();

	m_pShowWireframe 	= false;
	m_pShowPointCloud 	= false;
	m_pShowBoundingBox 	= false;
	m_pShowNormal 		= false;
	m_pShowVelocity 	= false;

	m_pName 			= Name;

	// m_pSceneNode 	= m_pSMgr->addSphereSceneNode(Radius, 160, 0, -1, vector3df(0, 0, 0), vector3df(0, 0, 0));
	m_pSceneNode		= m_pSMgr->addMeshSceneNode(createPlanetMesh(Radius));

	m_pSceneNode->setMaterialFlag(video::EMF_LIGHTING, false);

	m_pSceneNode->setMaterialTexture(0, m_pDriver->getTexture("../assets/cubemap/earth/left.png"));

Planet::~Planet()
{
}

SMeshBuffer* Planet::createPlanetQLSCFaceMeshBuffer(const f32 Radius, const vector3df Normal)
{
	const f32 circ 		= 2 * 3.141592 * Radius;
	const f32 range 	= circ / 4;

	const u32 polyCount = 90;

	SMeshBuffer* buffer = new SMeshBuffer();
	S3DVertex vtx;
	vtx.Color.set(255, 255, 255, 255);

	// Create the vertices
	for (u32 xx = 0; xx < polyCount; ++xx)
	{
		for (u32 yy = 0; yy < polyCount; ++yy)
		{
			vtx.Pos.set(
				(f32)xx / (f32)polyCount * Radius - Radius * 0.5,
				(f32)yy / (f32)polyCount * Radius - Radius * 0.5,
				-Radius);

			vtx.TCoords.set((f32)xx / (f32)polyCount, (f32)yy / (f32)polyCount);
			buffer->Vertices.push_back(vtx);
		}
	}

	// Create the indices
	for (u32 xx = 0; xx < polyCount - 1; ++xx)
	{
		for (u32 yy = 0; yy < polyCount - 1; ++yy)
		{
			const u32 cur = xx * polyCount + yy;

			buffer->Indices.push_back(cur);
			buffer->Indices.push_back(cur + 1);
			buffer->Indices.push_back(cur + polyCount);

			buffer->Indices.push_back(cur + 1);
			buffer->Indices.push_back(cur + 1 + polyCount);
			buffer->Indices.push_back(cur + polyCount);
		}
	}

	// Recalculate Normals

	buffer->recalculateBoundingBox();
	buffer->setHardwareMappingHint(EHM_STATIC);

	return buffer;
}

IMesh* Planet::createPlanetMesh(const f32 Radius)
{
	SMesh* mesh 		= new SMesh;
	SMeshBuffer* face 	= 0;

	face = createPlanetQLSCFaceMeshBuffer(Radius, vector3df(1, 0, 0));
	mesh->addMeshBuffer(face);
	face->drop();

	face = createPlanetQLSCFaceMeshBuffer(Radius, vector3df(0, 1, 0));
	mesh->addMeshBuffer(face);
	face->drop();

	// face = createPlanetQLSCFaceMeshBuffer(Radius, vector3df(0, 0, 1));
	// mesh->addMeshBuffer(face);
	// face->drop();

	// face = createPlanetQLSCFaceMeshBuffer(Radius, vector3df(-1, 0, 0));
	// mesh->addMeshBuffer(face);
	// face->drop();

	// face = createPlanetQLSCFaceMeshBuffer(Radius, vector3df(0, -1, 0));
	// mesh->addMeshBuffer(face);
	// face->drop();

	// face = createPlanetQLSCFaceMeshBuffer(Radius, vector3df(0, 0, -1));
	// mesh->addMeshBuffer(face);
	// face->drop();

	mesh->recalculateBoundingBox();

	return mesh;
}

// virtual void Planet::OnRegisterSceneNode()
// {
// 	if (IsVisible)
// 		m_pSMgr->registerNodeForRendering(this);

// 	ISceneNode::OnRegisterSceneNode();
// }

// virtual void Planet::render()
// {
// 	u16 indices[] = {   0,2,3, 2,1,3, 1,0,3, 2,0,1  };
// 	video::IVideoDriver* driver = SceneManager->getVideoDriver();

// 	driver->setMaterial(m_pMaterial);
// 	driver->setTransform(video::ETS_WORLD, AbsoluteTransformation);
// 	driver->drawVertexPrimitiveList(&Vertices[0], 4, &indices[0], 4, video::EVT_STANDARD, scene::EPT_TRIANGLES, video::EIT_16BIT);
// }

// virtual const core::aabbox3d<f32>& Planet::getBoundingBox() const
// {
// 	return Box;
// }

// virtual u32 Planet::getMaterialCount() const
// {
// 	return 1;
// }

// virtual video::SMaterial& Planet::getMaterial(u32 i)
// {
// 	return Material;
// }

void Planet::setName(stringw Name)
{
	m_pName = Name;
}
stringw Planet::getName()
{
	return m_pName;
}

void Planet::showWireframe(const bool State)
{
	if (m_pSceneNode != 0)
	{
		m_pSceneNode->setMaterialFlag(video::EMF_WIREFRAME, State);
		if (State) showPointCloud(false);
	}

	m_pShowWireframe = State;
}

void Planet::showPointCloud(const bool State)
{
	if (m_pSceneNode != 0)
	{
		m_pSceneNode->setMaterialFlag(video::EMF_POINTCLOUD, State);
		if (State) showWireframe(false);
	}

	m_pShowPointCloud = State;
}

void Planet::showBoundingBox(const bool State)
{
	// TODO: Show/hide bounding box
	m_pShowBoundingBox = State;
}

void Planet::showNormal(const bool State)
{
	// TODO: Show/hide normals
	m_pShowNormal = State;
}

void Planet::showVelocity(const bool State)
{
	// TODO: Show/hide velocity markers
	m_pShowVelocity = State;
}<|endoftext|>