Beispiel #1
0
void shapeGroup::RefteshTotalData()
{
	ShapeList TMPShapeList = SG_ShapeData;

	ShapeList::iterator	SG_ShapeData_Iterator = TMPShapeList.begin();

	SG_Size = TMPShapeList.size();

	const int	VAOSize = SG_Size * 12;
	const int	ItemSize = SG_Size * 20;

	GLfloat*	SG_TmpTotalData = (GLfloat*)malloc(sizeof(GLfloat) * ItemSize);


	if (SG_TmpTotalData == nullptr)
	{
		std::cout << "[Warning]Can't malloc(" << sizeof(GLfloat) * ItemSize << ")" << std::endl;

		return;
	}

	//start to copy
	for (int LoopShapeNumber = 0; LoopShapeNumber < SG_Size; LoopShapeNumber++)
	{
		//VAO
		SG_TmpTotalData[LoopShapeNumber * 12 + 0] = SG_ShapeData_Iterator->Shape->VAO_Data[0] + SG_ShapeData_Iterator->Location[0];
		SG_TmpTotalData[LoopShapeNumber * 12 + 1] = SG_ShapeData_Iterator->Shape->VAO_Data[1] + SG_ShapeData_Iterator->Location[1];
		SG_TmpTotalData[LoopShapeNumber * 12 + 2] = SG_ShapeData_Iterator->Shape->VAO_Data[2] + SG_ShapeData_Iterator->Location[2];

		SG_TmpTotalData[LoopShapeNumber * 12 + 3] = SG_ShapeData_Iterator->Shape->VAO_Data[3] + SG_ShapeData_Iterator->Location[0];
		SG_TmpTotalData[LoopShapeNumber * 12 + 4] = SG_ShapeData_Iterator->Shape->VAO_Data[4] + SG_ShapeData_Iterator->Location[1];
		SG_TmpTotalData[LoopShapeNumber * 12 + 5] = SG_ShapeData_Iterator->Shape->VAO_Data[5] + SG_ShapeData_Iterator->Location[2];

		SG_TmpTotalData[LoopShapeNumber * 12 + 6] = SG_ShapeData_Iterator->Shape->VAO_Data[6] + SG_ShapeData_Iterator->Location[0];
		SG_TmpTotalData[LoopShapeNumber * 12 + 7] = SG_ShapeData_Iterator->Shape->VAO_Data[7] + SG_ShapeData_Iterator->Location[1];
		SG_TmpTotalData[LoopShapeNumber * 12 + 8] = SG_ShapeData_Iterator->Shape->VAO_Data[8] + SG_ShapeData_Iterator->Location[2];

		SG_TmpTotalData[LoopShapeNumber * 12 + 9] = SG_ShapeData_Iterator->Shape->VAO_Data[9] + SG_ShapeData_Iterator->Location[0];
		SG_TmpTotalData[LoopShapeNumber * 12 + 10] = SG_ShapeData_Iterator->Shape->VAO_Data[10] + SG_ShapeData_Iterator->Location[1];
		SG_TmpTotalData[LoopShapeNumber * 12 + 11] = SG_ShapeData_Iterator->Shape->VAO_Data[11] + SG_ShapeData_Iterator->Location[2];
		//TexturePos
		for (int i = 0; i < 8; i++)
		{
			SG_TmpTotalData[VAOSize + LoopShapeNumber * 8 + i] = SG_ShapeData_Iterator->Shape->TexturePos_Data[i];
		}
		SG_ShapeData_Iterator++;
	}
	SG_TotalData = SG_TmpTotalData;

	SG_NeedRefreshBuffer = true;
	SG_IsRefreshingData = false;
}
Beispiel #2
0
void DatabaseCanvas::OnDropTable(wxCommandEvent &event)
{
    ShapeList list;
    bool isTable;
    int answer;
    MyErdTable *erdTable = NULL;
    DatabaseTable *table = NULL;
    wxString name;
    ConstraintSign *sign = NULL;
    Constraint *constraint = NULL;
    DrawingDocument *doc = (DrawingDocument *) m_view->GetDocument();
    Database *db = doc->GetDatabase();
    std::vector<std::wstring> errors, localColumns, refColumn;
    std::vector<FKField *> newFK;
    std::wstring command;
    int match = 0;
    GetSelectedShapes( list );
    if( list.size() == 1 )
        isTable = true;
    else
        isTable = false;
    for( ShapeList::iterator it = list.begin(); it != list.end(); it++ )
    {
        MyErdTable *tbl = wxDynamicCast( (*it), MyErdTable );
        if( tbl )
            erdTable = tbl;
        ConstraintSign *s = wxDynamicCast( (*it), ConstraintSign );
        if( s )
            sign = s;
    }
    if( isTable )
    {
        table = &( const_cast<DatabaseTable &>( erdTable->GetTable() ) );
        name = const_cast<DatabaseTable &>( erdTable->GetTable() ).GetTableName();
    }
    else
    {
        constraint = sign->GetConstraint();
        constraint->GetLocalColumns( localColumns );
        constraint->GetRefColumns( refColumn );
        match = constraint->GetPGMatch();
    }
    int eventId = event.GetId();
    if( eventId == wxID_DROPOBJECT )
    {
        wxString message = _( "You are about to delete " );
        if( isTable )
            message += _( "table " ) + name + _( ". Are you sure?" );
        else
        {
            message += _( "foreign key " );
            wxString fkName = constraint->GetName();
            if( !fkName.empty() )
                message += fkName;
            else
                message += _( " on " ) + const_cast<DatabaseTable *>( constraint->GetFKTable() )->GetTableName() + _( " references " ) + constraint->GetRefTable() + _( ". Are you sure?" );
        }
        answer = wxMessageBox( message, _( "Database" ), wxYES_NO | wxNO_DEFAULT );
    }
    else
        answer = wxYES;
    if( answer == wxYES )
    {
        if( isTable && ( ( eventId == wxID_DROPOBJECT && !db->DeleteTable( name.ToStdWstring(), errors ) ) || eventId != wxID_DROPOBJECT ) )
        {
            if( m_realSelectedShape == m_selectedShape )
            {
                m_realSelectedShape = NULL;
                ShapeList listShapes;
                m_pManager.GetShapes( CLASSINFO( MyErdTable ), listShapes );
                int size = listShapes.size();
                if( listShapes.size() == 1 )
                    m_realSelectedShape = NULL;
                else
                {
                    MyErdTable *tableToRemove = (MyErdTable *) ( listShapes.Item( size - 1 )->GetData() );
                    if( tableToRemove == erdTable )
                        m_realSelectedShape = (MyErdTable *) ( listShapes.Item( size - 2 )->GetData() );
                    else
                    {
                        bool found = false;
                        int i;
                        for( i = 0; i < size - 1 || !found; i++ )
                            if( listShapes.Item( i )->GetData() == erdTable )
                                found = true;
                        m_realSelectedShape = listShapes.Item( i + 1 )->GetData();
                    }
                }
            }
            m_pManager.RemoveShape( erdTable );
/*            for( ShapeList::iterator it = listShapes.begin(); it != listShapes.end() || !nextShapeFound; ++it )
            {
                CommentFieldShape *shape = wxDynamicCast( (*it), CommentFieldShape );
                if( m_showComments )
                {
                    shape->SetText( const_cast<Field *>( shape->GetFieldForComment() )->GetComment() );
                }
                else
                {
                    shape->SetText( wxEmptyString );
                }
            }*/
            std::map<std::wstring, std::vector<DatabaseTable *> > tables = db->GetTableVector().m_tables;
            std::vector<DatabaseTable *> tableVec = tables.at( db->GetTableVector().m_dbName );
            std::vector<std::wstring> &names = doc->GetTableNameVector();
            if( event.GetId() == wxID_DROPOBJECT )
            {
                tableVec.erase( std::remove( tableVec.begin(), tableVec.end(), table ), tableVec.end() );
            }
            else
                names.erase( std::remove( names.begin(), names.end(), table->GetTableName() ), names.end() );
/*            if( m_realSelectedShape == m_selectedShape )
            {
                
            }
            else
            {*/
                if( m_realSelectedShape )
                    m_realSelectedShape->Select( true );
//            }
        }
        else if( !isTable && !db->ApplyForeignKey( command, constraint->GetName().ToStdWstring(), *( const_cast<DatabaseTable *>( constraint->GetFKTable() ) ), localColumns, constraint->GetRefTable().ToStdWstring(), refColumn, constraint->GetOnDelete(), constraint->GetOnUpdate(), false, newFK, false, match, errors ) )
        {
            sign->DeleteConstraint();
            m_pManager.RemoveShape( sign->GetParentShape() );
            Refresh();
        }
        else
        {
            for( std::vector<std::wstring>::iterator it = errors.begin(); it < errors.end(); it++ )
            {
                wxMessageBox( (*it) );
            }
        }
    }
    Refresh();
}
DemoScene raytracer::gui::constructDemoScene()
{
    /// Load resources
    ResourceManager* resourceManager = ResourceManager::getInstance();
    Texture* terrainTexture = new TerrainHeightTexture( // multitexture for terrain
	    resourceManager->createImage("terrainImage1", "resources/terrain_dirt.tga"),
	    resourceManager->createImage("terrainImage2", "resources/terrain_grass.tga"),
	    resourceManager->createImage("terrainImage3", "resources/terrain_rock.tga"),
	    resourceManager->createImage("terrainImage4", "resources/terrain_snow.tga")
    );
    std::vector<Image*> skyBoxImages(6);
    skyBoxImages[0] = resourceManager->createImage("skyboxFront", "resources/miramar_ft.tga");
    skyBoxImages[1] = resourceManager->createImage("skyboxRight", "resources/miramar_rt.tga");
    skyBoxImages[2] = resourceManager->createImage("skyboxBack", "resources/miramar_bk.tga");
    skyBoxImages[3] = resourceManager->createImage("skyboxLeft", "resources/miramar_lf.tga");
    skyBoxImages[4] = resourceManager->createImage("skyboxUp", "resources/miramar_up.tga");
    skyBoxImages[5] = resourceManager->createImage("skyboxDown", "resources/miramar_dn.tga");
    std::vector<Texture*> skyBoxTextures(6);
    skyBoxTextures[0] = resourceManager->createTexture("skyboxFrontTexture", "skyboxFront");
    skyBoxTextures[1] = resourceManager->createTexture("skyboxRightTexture", "skyboxRight");
	skyBoxTextures[2] = resourceManager->createTexture("skyboxBackTexture", "skyboxBack");
	skyBoxTextures[3] = resourceManager->createTexture("skyboxLeftTexture", "skyboxLeft");
	skyBoxTextures[4] = resourceManager->createTexture("skyboxUpTexture", "skyboxUp");
	skyBoxTextures[5] = resourceManager->createTexture("skyboxDownTexture", "skyboxDown");
    // Define scene
    AABB sceneBoundary(Vector3(-1000, -1000, -1000), Vector3(1000, 1000, 1000));
    ShapeList shapes;
    shapes.push_back(new Sphere(Vector3(0.0f, 8.0f, -25.0f), 2.0f,
        new Material(0.5f, 1.2f, 0.5f, 20.0f, Material::NO_REFLECTION,
        Material::NO_REFRACTION, Colour(0.4f, 0.4f, 0.8f), NULL)
    ));
    shapes.push_back(new Sphere(Vector3(-4.0f, 10.0f, -20.0f), 2.0f,
        new Material(0.5f, 3.0f, 1.0f, 20.0f, 1.0f,
        Material::NO_REFRACTION, Colour(), NULL)
    ));
    shapes.push_back(new Sphere(Vector3(0.0f, 5.0f, -15.0f), 2.0f,
        new Material(0.5f, 1.2f, 0.5f, 20.0f, 0.5f,
            1.6666, Colour(0.8f, 0.2f, 0.2f), NULL)
    ));
    shapes.push_back(new Sphere(Vector3(3.0f, 5.0f, -26.5f), 1.0f,
        new Material(5.0f, 0.0f, 0.0f, 0.0f, 0.4f,
        Material::NO_REFRACTION, Colour(0.9f, 0.65f, 0.0f), NULL)
    ));
    // Load skybox
    shapes.push_back(shapeloaders::getSkyBox(common::SKYBOX_SIZE, skyBoxTextures));

	// Define all possible viewpoints
	std::vector<Camera> cameras;
	cameras.reserve(3);
	cameras.push_back(Camera(
        Vector3(0, 5.0f, 0), Vector3(0, 0, -1), Vector3(0, 1, 0),
        Rect(-100, 100, -100, 100), 200, false));
	cameras.push_back(Camera(
        Vector3(-10, 3.0f, -10.0f), Vector3(1, 0.2f, -1), Vector3(0, 1, 0),
        Rect(-100, 100, -100, 100), 200, false));        
	cameras.push_back(Camera(
        Vector3(5.0f, 30.0f, -50.0f), Vector3(0.0f, -0.6f, 1), Vector3(0, 1, 0),
        Rect(-100, 100, -100, 100), 200, false));
        
    // Load all possible terrain
    std::vector<std::string> heightmapFilenames;
    heightmapFilenames.push_back("resources/heightmap.tga");
    heightmapFilenames.push_back("resources/heightmap2.tga");
    heightmapFilenames.push_back("resources/heightmap3.tga");
    std::vector<Image*> heightmaps;
    for (unsigned int i = 0; (i < heightmapFilenames.size()); i++)
    	heightmaps.push_back( resourceManager->createImage("heightmap", heightmapFilenames[i]) );
    std::vector<Vector3> terrainOffsets;
    for (unsigned int i = 0; (i < heightmaps.size()); i++)
    {
		terrainOffsets.push_back(Vector3(
			-((common::TERRAIN_CELL_SIZE * heightmaps[i]->getWidth()) / 2.0f),
			0.0f, -((common::TERRAIN_CELL_SIZE * heightmaps[i]->getHeight()) / 2.0f))
		);
	}
	ShapeList terrainVariants;
    for (unsigned int i = 0; (i < heightmaps.size()); i++)
    {
		Shape* unoptimisedTerrain = shapeloaders::getTerrainFromHeightmap(
			heightmapFilenames[i], common::TERRAIN_CELL_SIZE,
			common::TERRAIN_MAX_HEIGHT, terrainOffsets[i], terrainTexture, false);
		Shape* optimisedTerrain = shapeloaders::getTerrainFromHeightmap(
			heightmapFilenames[i], common::TERRAIN_CELL_SIZE,
			common::TERRAIN_MAX_HEIGHT, terrainOffsets[i], terrainTexture, true);
	    terrainVariants.push_back(unoptimisedTerrain);
        terrainVariants.push_back(optimisedTerrain);
    }
    
    // Construct test shapes (lines of each terrain's octree)
    ShapeList octreeLines;
    for (unsigned int i = 0; (i < terrainVariants.size()); i += 2) // go in 2s so unoptimised terrain is skipped
    {
        LineList lines = dynamic_cast<Octree*>(terrainVariants[i + 1])->getBoundingLines();
        ShapeList lineShapes = generateLines(lines, 0.4f, NULL);
        BoundingShape* rootOfLines = new BoundingShape(lineShapes, sceneBoundary);
        octreeLines.push_back(rootOfLines);
    }

	// Create renderer to render scene
	Raytracer* renderer = new Raytracer(cameras[0]);
    renderer->setRootShape(new BoundingShape(shapes, sceneBoundary));
    // Add light sources 
    std::vector<PointLight> pointLights;
    pointLights.push_back(PointLight(
        Vector3(-100, 70, 100),
        Colour(0.2f, 0.2f, 0.2f),
        Colour(0.4f, 0.4f, 0.4f),
        Colour(1.0f, 1.0f, 1.0f)
    ));
    pointLights.push_back(PointLight(
        Vector3(3.0f, 5.0f, -26.5f),
        Colour(0.0f, 0.0f, 0.0f),
        Colour(0.6f, 0.76f, 0.0f),
        Colour(1.0f, 0.3f, 0.0f)
    ));
    // Disable test shapes at start
    renderer->showTestShapes(false);
    
	// Return the entire scene
	DemoScene scene = { renderer, cameras, terrainVariants, octreeLines, pointLights };
	return scene;
}