// Cross product. Finds perpendicular direction to plane defined by 2. Also useful for lighting and angles Direction Direction::Cross(const Direction& direction) const { return Direction::Coordinates( Get_Y() * direction.Get_Z() - Get_Z() * direction.Get_Y(), Get_Z() * direction.Get_X() - Get_X() * direction.Get_Z(), Get_X() * direction.Get_Y() - Get_Y() * direction.Get_X()); }
//--------------------------------------------------------- void CAir_Flow_Height::Get_Lee(int x, int y, double &Sum_A, double &Sum_B) { double Weight_A = Sum_A = 0.0; double Weight_B = Sum_B = 0.0; if( m_pDEM->is_InGrid(x, y) ) { double z, d, id, w; TSG_Point p; d = id = Get_Cellsize(); p = Get_System()->Get_Grid_to_World(x, y); while( id <= m_maxDistance && Get_Next(p, d, true) ) { if( Get_Z(p, d, z) ) { Weight_A += w = d * pow(id, -m_dLuv); Sum_A += w * z; Weight_B += w = d * pow(id, -m_dLee); Sum_B += w * z; } d *= m_Acceleration; id += d; } if( Weight_A > 0.0 ) { Sum_A /= Weight_A; } if( Weight_B > 0.0 ) { Sum_B /= Weight_B; } } }
//--------------------------------------------------------- bool CSG_Shape_Point::On_Assign(CSG_Shape *pShape) { if( pShape->Get_Point_Count(0) > 0 ) { CSG_Shape::Add_Point(pShape->Get_Point(0)); Set_Z(Get_Z(0), 0); Set_M(Get_M(0), 0); return( true ); } return( false ); }
//--------------------------------------------------------- bool CSG_PRQuadTree_Node::Add_Point(double x, double y, double z) { if( Contains(x, y) ) { if( has_Statistics() ) { Get_X()->Add_Value(x); Get_Y()->Add_Value(y); Get_Z()->Add_Value(z); } int i = y < m_yCenter ? (x < m_xCenter ? 0 : 3) : (x < m_xCenter ? 1 : 2); //------------------------------------------------- if( m_pChildren[i] == NULL ) { double Size = 0.5 * m_Size; switch( i ) { case 0: m_pChildren[i] = new CSG_PRQuadTree_Leaf(m_xCenter - Size, m_yCenter - Size, Size, x, y, z); break; case 1: m_pChildren[i] = new CSG_PRQuadTree_Leaf(m_xCenter - Size, m_yCenter + Size, Size, x, y, z); break; case 2: m_pChildren[i] = new CSG_PRQuadTree_Leaf(m_xCenter + Size, m_yCenter + Size, Size, x, y, z); break; case 3: m_pChildren[i] = new CSG_PRQuadTree_Leaf(m_xCenter + Size, m_yCenter - Size, Size, x, y, z); break; } return( true ); } //----------------------------------------------------- if( m_pChildren[i]->is_Leaf() ) { CSG_PRQuadTree_Leaf *pLeaf = m_pChildren[i]->asLeaf(); if( x != pLeaf->Get_X() || y != pLeaf->Get_Y() ) { if( has_Statistics() ) { m_pChildren[i] = new CSG_PRQuadTree_Node_Statistics (pLeaf); } else { m_pChildren[i] = new CSG_PRQuadTree_Node (pLeaf); } ((CSG_PRQuadTree_Node *)m_pChildren[i])->Add_Point(x, y, z); } else { if( !pLeaf->has_Statistics() ) { m_pChildren[i] = new CSG_PRQuadTree_Leaf_List(pLeaf->m_xCenter, pLeaf->m_yCenter, pLeaf->m_Size, x, y, pLeaf->Get_Z()); delete(pLeaf); } ((CSG_PRQuadTree_Leaf_List *)m_pChildren[i])->Add_Value(z); } return( true ); } //------------------------------------------------- // if( m_pChildren[i]->is_Node() ) { return( ((CSG_PRQuadTree_Node *)m_pChildren[i])->Add_Point(x, y, z) ); } } return( false ); }
//--------------------------------------------------------- CSG_Shape * CSG_PointCloud::_Set_Shape(int iPoint) { SG_UI_Progress_Lock(true); CSG_Shape *pShape = m_Shapes.Get_Shape(0); if( pShape->is_Modified() && m_Shapes_Index >= 0 && m_Shapes_Index < Get_Count() ) { m_Cursor = m_Points[m_Shapes_Index]; for(int i=0; i<Get_Field_Count(); i++) { switch( Get_Field_Type(i) ) { default: Set_Value(i, pShape->asDouble(i)); break; case SG_DATATYPE_Date: case SG_DATATYPE_String: Set_Value(i, pShape->asString(i)); break; } } Set_Value(0, pShape->Get_Point(0).x); Set_Value(1, pShape->Get_Point(0).y); Set_Value(2, pShape->Get_Z (0) ); } if( iPoint >= 0 && iPoint < Get_Count() ) { if(1|| iPoint != m_Shapes_Index ) { m_Cursor = m_Points[iPoint]; pShape->Set_Point(Get_X(), Get_Y(), 0, 0); pShape->Set_Z (Get_Z() , 0, 0); for(int i=0; i<Get_Field_Count(); i++) { switch( Get_Field_Type(i) ) { default: pShape->Set_Value(i, Get_Value(i)); break; case SG_DATATYPE_Date: case SG_DATATYPE_String: { CSG_String s; Get_Value(i, s); pShape->Set_Value(i, s); } break; } } m_Shapes_Index = iPoint; pShape->m_Index = iPoint; pShape->Set_Selected(is_Selected(iPoint)); } m_Shapes.Set_Modified(false); SG_UI_Progress_Lock(false); return( pShape ); } m_Shapes_Index = -1; SG_UI_Progress_Lock(false); return( NULL ); }
// Dot product. Useful for lighting float Direction::Dot(const Direction& direction) const { float answer = (Get_X() * direction.Get_X()) + (Get_Y() * direction.Get_Y()) + (Get_Z() * direction.Get_Z()); return (answer); }
// Makes a vertex with the X, Y, and Z values glm::vec3 Direction::To_Vertex(void) const { return (glm::vec3(Get_X(), Get_Y(), Get_Z())); }
// Find the distance between this direction and another Direction Direction::Distance(const Direction& to) const { Direction copy = to; copy.Add_Coordinates(-1 * Get_X(), -1 * Get_Y(), -1 * Get_Z()); return (copy); }
// Add values to the coordinates of the direction void Direction::Add_Coordinates(const float x, const float y, const float z) { Set_Coordinates(Get_X() + x, Get_Y() + y, Get_Z() + z); return; }
void Direction::Set_Y(const float y) { Set_Coordinates(Get_X(), y, Get_Z()); }
// Set the relative coordinates of the direction void Direction::Set_X(const float x) { Set_Coordinates(x, Get_Y(), Get_Z()); }