// constructor and default values
InteractiveCamera::InteractiveCamera()
{
	centerPosition = Vector3Df(0, 0, 0);
	yaw = 0;
	pitch = 0.3;
	radius = 4;
	apertureRadius = 0.01; // 0.04
	focalDistance = 4.0f;

	resolution = Vector2Df(512, 512);  // width, height
	fov = Vector2Df(40, 40);
}
Ejemplo n.º 2
0
	void Lights::AddLight(const Vector3Df& pos, const Vector3Df& color)
	{
		if(m_numLights >= MAX_NUM_LIGHTS)
			return;

		m_pos.push_back(pos);
		m_color.push_back(color);
		m_radius.push_back(1.0f);
		m_dir.push_back(Vector3Df());
		m_angleInnerCone.push_back(0.0f);
		m_angleOuterCone.push_back(-1.0f);

		++m_numLights;
	}
Ejemplo n.º 3
0
	void AddQuadCubeToArray(std::vector<Vector3Df>& verts, const Vector3Df& min, const Vector3Df& max)
	{
		//x
		verts.push_back(Vector3Df(min.x, max.y, max.z));
		verts.push_back(Vector3Df(min.x, max.y, min.z));
		verts.push_back(Vector3Df(min.x, min.y, min.z));
		verts.push_back(Vector3Df(min.x, min.y, max.z));

		verts.push_back(Vector3Df(max.x, min.y, max.z));
		verts.push_back(Vector3Df(max.x, min.y, min.z));
		verts.push_back(Vector3Df(max.x, max.y, min.z));
		verts.push_back(Vector3Df(max.x, max.y, max.z));

 		//y
 		verts.push_back(Vector3Df(max.x, min.y, min.z));
 		verts.push_back(Vector3Df(max.x, min.y, max.z));
 		verts.push_back(Vector3Df(min.x, min.y, max.z));
 		verts.push_back(Vector3Df(min.x, min.y, min.z));
 
		verts.push_back(Vector3Df(max.x, max.y, max.z));
		verts.push_back(Vector3Df(max.x, max.y, min.z));
		verts.push_back(Vector3Df(min.x, max.y, min.z));
		verts.push_back(Vector3Df(min.x, max.y, max.z));
 
 		//z
		verts.push_back(Vector3Df(max.x, max.y, min.z));
		verts.push_back(Vector3Df(max.x, min.y, min.z));
		verts.push_back(Vector3Df(min.x, min.y, min.z));
		verts.push_back(Vector3Df(min.x, max.y, min.z));
 
		verts.push_back(Vector3Df(min.x, max.y, max.z));
		verts.push_back(Vector3Df(min.x, min.y, max.z));
		verts.push_back(Vector3Df(max.x, min.y, max.z));
		verts.push_back(Vector3Df(max.x, max.y, max.z));
	}
void InteractiveCamera::strafe(float m){
	Vector3Df strafeAxis = cross(viewDirection, Vector3Df(0, 1, 0));
	strafeAxis.normalize();
	centerPosition += strafeAxis * m;
}
Ejemplo n.º 5
0
void loadIGES(char* filename)
{
    if(!filename) return;
    std::cout << "test" << std::endl;

    boost::interprocess::managed_shared_memory segment(boost::interprocess::open_only, "OCCSharedMem");  
    TestFaces *m_trisp = segment.find<TestFaces>("m_tris").first;
    //TestFaces *m_facesp = segment.find<TestFaces>("m_faces").first;

    Vector3DfAllocator vector3df_alloc_inst(segment.get_segment_manager());
    TestFace *m_facep = segment.construct<TestFace>("m_facep")(vector3df_alloc_inst);

    std::cout << "connected to shared mem" << std::endl;
    std::cout << filename << std::endl;

    //STEPControl_Reader *readerp = new STEPControl_Reader;
    IGESControl_Controller::Init();
    Message_MsgFile::LoadFromEnv("CSF_XSMessage","IGES");
    Message_MsgFile::LoadFromEnv("CSF_SHMessageStd","SHAPEStd");
    IGESControl_Reader reader;
    std::cout << filename << std::endl;
    reader.ReadFile(filename);
    reader.PrintCheckLoad(Standard_True,IFSelect_GeneralInfo);

    Standard_Integer NbRoots = reader.NbRootsForTransfer();
    std::cout << "Number of Roots in the IGES File: " << NbRoots << std::endl;
    Standard_Integer NbTrans = reader.TransferRoots();
    std::cout << "IGES roots transferred: " << NbTrans << std::endl;
    std::cout << "Number of resulting shapes is: " << reader.NbShapes() << std::endl;
    TopoDS_Shape resulting_shape = reader.OneShape();
    // gp_Trsf theTrans;
    // gp_Axl Axis = gp_Axl(gp_Pnt(200,60,60),gp_Dir(0.,1.,0.)); 
    // theTrans.SetRotation(Axis,30*PI/180); // Rotation of 30 degrees 
    // BRepBuilderAPI_Transform myBRepTransformation(resulting_shape,theTrans,true); 
    // TopoDS_Shape TransformedShape = myBRepTransformation.Shape();
    TopoDS_Iterator topo_iter;
    //m_topodsshapes.push_back(resulting_shape);
    //BRepMesh::Mesh(resulting_shape, 1.0);
    TopExp_Explorer faceExp(resulting_shape, TopAbs_FACE);

    for(; faceExp.More(); faceExp.Next())
    {


        //  TopExp_Explorer vertexExp(faceExp.Current(), TopAbs_VERTEX);
        //int f_n = 0;
        TopLoc_Location L = faceExp.Current().Location();
        BRepMesh::Mesh(faceExp.Current(), .1);
        Handle (Poly_Triangulation) facing = BRep_Tool::Triangulation(TopoDS::Face(faceExp.Current()),L);
        //  const Poly_Array1OfTriangle & triangles = facing->Triangles();
        //  const TColgp_Array1OfPnt & nodes = facing->Nodes();
        //  std::cout << "opencascaded: facing->NbTriangles() = " << facing->NbTriangles() << std::endl;
        if (!facing.IsNull())
        {
            TopExp_Explorer vertexExp(faceExp.Current(), TopAbs_VERTEX);
            //int f_n = 0;
            //TopLoc_Location L = faceExp.Current().Location();
            // BRepMesh::Mesh(faceExp.Current(), .1);
            // Handle (Poly_Triangulation) facing = BRep_Tool::Triangulation(TopoDS::Face(faceExp.Current()),L);
            const Poly_Array1OfTriangle & triangles = facing->Triangles();
            const TColgp_Array1OfPnt & nodes = facing->Nodes();
            std::cout << "opencascaded: facing->NbTriangles() = " << facing->NbTriangles() << std::endl;

            for ( int i=facing->NbTriangles(); i >= 1; --i )
            {
                m_facep->clear();
                Poly_Triangle triangle = triangles(i);

                Standard_Integer node1,node2,node3;
                triangle.Get(node1, node2, node3);

                gp_Pnt v1 = nodes(node1).Transformed(L);
                gp_Pnt v2 = nodes(node2).Transformed(L);
                gp_Pnt v3 = nodes(node3).Transformed(L);

                m_facep->push_back(Vector3Df(v1.X(), v1.Y(), v1.Z()));
                m_facep->push_back(Vector3Df(v2.X(), v2.Y(), v2.Z()));
                m_facep->push_back(Vector3Df(v3.X(), v3.Y(), v3.Z()));
                m_trisp->push_back(*m_facep);

            }
        }

    }

}
Ejemplo n.º 6
0
void loadSTEP(char* filename)
{
    if(!filename) return;
    std::cout << "test" << std::endl;
    boost::interprocess::managed_shared_memory segment(boost::interprocess::open_only, "OCCSharedMem");  
    TestFaces *m_trisp = segment.find<TestFaces>("m_tris").first;
    //TestFaces *m_facesp = segment.find<TestFaces>("m_faces").first;

    Vector3DfAllocator vector3df_alloc_inst(segment.get_segment_manager());
    TestFace *m_facep = segment.construct<TestFace>("m_facep")(vector3df_alloc_inst);

    std::cout << "connected to shared mem" << std::endl;
    std::cout << filename << std::endl;

    //STEPControl_Reader *readerp = new STEPControl_Reader;
    STEPControl_Reader reader;
    std::cout << filename << std::endl;
    reader.ReadFile(filename);
    Standard_Integer NbRoots = reader.NbRootsForTransfer();
    std::cout << "Number of Roots in the STEP File: " << NbRoots << std::endl;
    Standard_Integer NbTrans = reader.TransferRoots();
    std::cout << "STEP roots transferred: " << NbTrans << std::endl;
    std::cout << "Number of resulting shapes is: " << reader.NbShapes() << std::endl;
    TopoDS_Shape resulting_shape = reader.OneShape();
    // gp_Trsf theTrans;
    // gp_Axl Axis = gp_Axl(gp_Pnt(200,60,60),gp_Dir(0.,1.,0.)); 
    // theTrans.SetRotation(Axis,30*PI/180); // Rotation of 30 degrees 
    // BRepBuilderAPI_Transform myBRepTransformation(resulting_shape,theTrans,true); 
    // TopoDS_Shape TransformedShape = myBRepTransformation.Shape();
    TopoDS_Iterator topo_iter;
    //m_topodsshapes.push_back(resulting_shape);
    // BRepMesh::Mesh(resulting_shape, 0.05);
    TopExp_Explorer faceExp(resulting_shape, TopAbs_FACE);

    for(; faceExp.More(); faceExp.Next())
    {


        //  TopExp_Explorer vertexExp(faceExp.Current(), TopAbs_VERTEX);
        //int f_n = 0;
        TopLoc_Location L = faceExp.Current().Location();
        BRepMesh::Mesh(faceExp.Current(), .1);
        Handle (Poly_Triangulation) facing = BRep_Tool::Triangulation(TopoDS::Face(faceExp.Current()),L);
        //  const Poly_Array1OfTriangle & triangles = facing->Triangles();
        //  const TColgp_Array1OfPnt & nodes = facing->Nodes();
        //  std::cout << "opencascaded: facing->NbTriangles() = " << facing->NbTriangles() << std::endl;
        if (!facing.IsNull())
        {
            TopExp_Explorer vertexExp(faceExp.Current(), TopAbs_VERTEX);
            //int f_n = 0;
            //TopLoc_Location L = faceExp.Current().Location();
            // BRepMesh::Mesh(faceExp.Current(), .1);
            // Handle (Poly_Triangulation) facing = BRep_Tool::Triangulation(TopoDS::Face(faceExp.Current()),L);
            const Poly_Array1OfTriangle & triangles = facing->Triangles();
            const TColgp_Array1OfPnt & nodes = facing->Nodes();
            std::cout << "opencascaded: facing->NbTriangles() = " << facing->NbTriangles() << std::endl;

            for ( int i=facing->NbTriangles(); i >= 1; --i )
            {
                m_facep->clear();
                Poly_Triangle triangle = triangles(i);

                Standard_Integer node1,node2,node3;
                triangle.Get(node1, node2, node3);

                gp_Pnt v1 = nodes(node1).Transformed(L);
                gp_Pnt v2 = nodes(node2).Transformed(L);
                gp_Pnt v3 = nodes(node3).Transformed(L);

                m_facep->push_back(Vector3Df(v1.X(), v1.Y(), v1.Z()));
                m_facep->push_back(Vector3Df(v2.X(), v2.Y(), v2.Z()));
                m_facep->push_back(Vector3Df(v3.X(), v3.Y(), v3.Z()));
                m_trisp->push_back(*m_facep);

            }
        }
        /*
           for(; vertexExp.More(); vertexExp.Next())
           {
           m_facep->clear();
           const TopoDS_Vertex& aVertex = TopoDS::Vertex(vertexExp.Current());
        //TopoDS_Edge edge = TopoDS::Edge(shape);
        TopLoc_Location location;
        Standard_Real pFirst, pLast;
        //Handle(Geom_Curve) curve = BRep_Tool::Curve(anEdge, location, pFirst, pLast);
        //std::cout << "pFirst = " << pFirst << std::endl;
        gp_Pnt p = BRep_Tool::Pnt(aVertex);
        std::cout << "Vector3Df(" << p.X() << ", " << p.Y() << ", " << p.Z() << std::endl;
        //points.push_back(Vector3Df(p.X()/1000.0, p.Y()/1000.0, p.Z()/1000.0));
        m_facep->push_back(Vector3Df(p.X()/1000.0, p.Y()/1000.0, p.Z()/1000.0));
        //      TopLoc_Location L;
        //        Handle (Poly_Triangulation) facing = BRep_Tool::Triangulation(aFace,L);
        //        if(!(facing.IsNull()))std::cout << "Number of Triangles in Face #" << f_n << ": " << facing->NbTriangles() << std::endl;
        //        f_n++;
        }
        m_facesp->push_back(*m_facep);
        */
    }
    //std::cout << " opencascaded: m_trisp->size()" << m_trisp->size() << std::endl;

    //  segment.destroy<TestFaces>("m_tris");

}
Ejemplo n.º 7
0
void WindsimCellsInit(Windsim *sim)
{
    if (!sim) { X2(bad_arg, "NULL sim pointer"); }
    
    /* Initialises a stack of cells over the simulation, the depth of each cell
     * (I will generally use "depth" to describe height in the Z axis, reserving
     * "height" for describing the Y axis) being smaller at lower altitudes
     * in order to give greater accuracy at the more important area. Heights
     * increase in proportion: 1, 2, 3, ... n.
     * 
     * Each cell is initialised with an approximation so that the simulation
     * converges to realistic point as soon as possible.
     * */
    double altitude = 0;
    double n = (double) sim->size.z + 1;
    
    // for each layer
    for (size_t z = 0; z < sim->size.z; z++)
    {
        // smaller depths nearer the surface for accuracy
        // using depths of nx for 
        // and x = 2h/((n)(n-1))
        double x = 2.0 * sim->height / (n * (n - 1));
        double depth = x * (1.0 + (double) z);
        altitude += depth * 0.5; // midpoint
        
        // Find width of cell by extending a triangle from planet radius to
        // height of layer.
        double width = TriangleExtendedOpposite
        (
            sim->world->radius,
            sim->world->dimension.x / (double) sim->size.x,
            altitude
        );
        
        double height = TriangleExtendedOpposite
        (
            sim->world->radius,
            sim->world->dimension.y / (double) sim->size.y,
            altitude
        );
        
        // for width and height
        for (size_t i = 0; i < sim->size.x * sim->size.y; i++)
        {
            Windcell *cell = WindcellAtZI(sim, z, i);
            
            // initialise with an approximation
            WindcellInit
            (
                cell,
                altitude,
                0.15 * width * height * depth, // air mass kg
                273.15, // temperature in Kelvin (0 C)
                0.0, // moisture kg
                Vector3Df(width, height, depth) // m*m*m
            );
        }
        
        altitude += depth * 0.5; // move beyond midpoint
    }
    
    return;
    
    err_bad_arg:
        return;
}