Exemplo n.º 1
0
Pointer<BoxOverlap<NDIM> >
EdgeSynchCopyFillPattern::calculateOverlap(const BoxGeometry<NDIM>& dst_geometry,
                                           const BoxGeometry<NDIM>& src_geometry,
                                           const Box<NDIM>& /*dst_patch_box*/,
                                           const Box<NDIM>& src_mask,
                                           const bool overwrite_interior,
                                           const IntVector<NDIM>& src_offset) const
{
    Pointer<EdgeOverlap<NDIM> > box_geom_overlap =
        dst_geometry.calculateOverlap(src_geometry, src_mask, overwrite_interior, src_offset);
#if !defined(NDEBUG)
    TBOX_ASSERT(box_geom_overlap);
#endif
    if (box_geom_overlap->isOverlapEmpty()) return box_geom_overlap;

    const EdgeGeometry<NDIM>* const t_dst_geometry =
        dynamic_cast<const EdgeGeometry<NDIM>*>(&dst_geometry);
#if !defined(NDEBUG)
    TBOX_ASSERT(t_dst_geometry);
#endif
    BoxList<NDIM> dst_boxes[NDIM];
    for (unsigned int axis = 0; axis < NDIM; ++axis)
    {
        if (axis == d_axis) continue;
        bool skip = false;
        for (unsigned int d = 0; d < NDIM && !skip; ++d)
        {
            if (d != d_axis)
            {
                skip = skip || (src_offset(d) != 0);
            }
        }
        if (!skip)
        {
            // Determine the stencil box.
            const Box<NDIM>& dst_box = t_dst_geometry->getBox();
            Box<NDIM> stencil_box = EdgeGeometry<NDIM>::toEdgeBox(dst_box, axis);
            stencil_box.lower()(d_axis) = stencil_box.upper()(d_axis);

            // Intersect the original overlap boxes with the stencil box.
            const BoxList<NDIM>& box_geom_overlap_boxes =
                box_geom_overlap->getDestinationBoxList(axis);
            for (BoxList<NDIM>::Iterator it(box_geom_overlap_boxes); it; it++)
            {
                const Box<NDIM> overlap_box = stencil_box * it();
                if (!overlap_box.empty()) dst_boxes[axis].appendItem(overlap_box);
            }
        }
    }
    return new EdgeOverlap<NDIM>(dst_boxes, src_offset);
} // calculateOverlap
Exemplo n.º 2
0
void RigidBody2DSim::boxBoxNarrowPhaseCollision( const unsigned idx0, const unsigned idx1, const BoxGeometry& box0, const BoxGeometry& box1, const VectorXs& q0, const VectorXs& q1, std::vector<std::unique_ptr<Constraint>>& active_set ) const
{
  if( isKinematicallyScripted( idx0 ) || isKinematicallyScripted( idx1 ) )
  {
    std::cerr << "Box-Box kinematic collisions not yet supported." << std::endl;
    std::exit( EXIT_FAILURE );
  }

  // Note: Detection is at q1...
  const Vector2s x0_t1{ q1.segment<2>( 3 * idx0 ) };
  const scalar theta0_t1{ q1( 3 * idx0 + 2 ) };
  const Vector2s x1_t1{ q1.segment<2>( 3 * idx1 ) };
  const scalar theta1_t1{ q1( 3 * idx1 + 2 ) };
  Vector2s n;
  std::vector<Vector2s> points;
  BoxBoxTools::isActive( x0_t1, theta0_t1, box0.r(), x1_t1, theta1_t1, box1.r(), n, points );

  // ... but constraint construction is at q0 to conserve angular momentum
  for( const Vector2s& point : points )
  {
    active_set.emplace_back( new BodyBodyConstraint{ idx0, idx1, point, n, q0 } );
  }
}
Exemplo n.º 3
0
void updateScene() {
	// update camera rotation and height
	double angle = t * speed;
	double rotationCenterX = 0.0;
	double rotationCenterZ = 0.0;

	double camX = rotationCenterX + camRadius*cos(DegreesToRadians * 90 + angle);
	double camZ = rotationCenterZ + camRadius*sin(DegreesToRadians * 90 + angle);
	vec4 camPos = vec4(camX, camY, camZ, 1.0);
	vec4 camTarget = vec4(0.0, 0.0, 0.0, 1.0);
	vec4 camUp = vec4(0.0, 1.0, 0.0, 0.0);

	camera.LookAt(camPos, camTarget, camUp);

	// update MVP
	camera.updateMatrix();
	ColorCube.updateMatrix();
	scene.updateMatrix();

	// update light rotation and height
	lightX = rotationCenterX + lightRadius*cos(DegreesToRadians * lightAngle);
	lightZ = rotationCenterZ + lightRadius*sin(DegreesToRadians * lightAngle);
}
Exemplo n.º 4
0
//---------------------------------------------------------------------------//
// Box intersection test.
TEUCHOS_UNIT_TEST( Box, intersection_test )
{
    using namespace DataTransferKit;
 
    bool has_intersect;
    BoxGeometry intersection;
    Teuchos::Tuple<double,6> bounds;

    BoxGeometry box_1( 0, 0, 0, 0.0, 0.0, 0.0, 1.0, 1.0, 1.0);
    BoxGeometry box_2( 0, 0, 0, 0.25, 0.25, 0.25, 0.75, 0.75, 0.75);
    BoxGeometry box_3( 0, 0, 0, -1.0, -1.0, -1.0, 0.67, 0.67, 0.67);
    BoxGeometry box_4( 0, 0, 0, 4.3, 6.2, -1.2, 5.6, 7.8, -0.8 );
    BoxGeometry box_5( 0, 0, 0, 1.0, 1.0, 1.0, 1.1, 1.1, 1.1 );

    has_intersect = BoxGeometry::intersectBoxes( box_1, box_2, intersection );
    TEST_ASSERT( has_intersect );
    intersection.boundingBox( bounds );
    TEST_EQUALITY( bounds[0], 0.25 );
    TEST_EQUALITY( bounds[1], 0.25 );
    TEST_EQUALITY( bounds[2], 0.25 );
    TEST_EQUALITY( bounds[3], 0.75 );
    TEST_EQUALITY( bounds[4], 0.75 );
    TEST_EQUALITY( bounds[5], 0.75 );

    has_intersect = BoxGeometry::intersectBoxes( box_1, box_1, intersection );
    TEST_ASSERT( has_intersect );
    intersection.boundingBox( bounds );
    TEST_EQUALITY( bounds[0], 0.0 );
    TEST_EQUALITY( bounds[1], 0.0 );
    TEST_EQUALITY( bounds[2], 0.0 );
    TEST_EQUALITY( bounds[3], 1.0 );
    TEST_EQUALITY( bounds[4], 1.0 );
    TEST_EQUALITY( bounds[5], 1.0 );

    has_intersect = BoxGeometry::intersectBoxes( box_3, box_1, intersection );
    TEST_ASSERT( has_intersect );
    intersection.boundingBox( bounds );
    TEST_EQUALITY( bounds[0], 0.0 );
    TEST_EQUALITY( bounds[1], 0.0 );
    TEST_EQUALITY( bounds[2], 0.0 );
    TEST_EQUALITY( bounds[3], 0.67 );
    TEST_EQUALITY( bounds[4], 0.67 );
    TEST_EQUALITY( bounds[5], 0.67 );

    has_intersect = BoxGeometry::intersectBoxes( box_4, box_1, intersection );
    TEST_ASSERT( !has_intersect );

    has_intersect = BoxGeometry::intersectBoxes( box_1, box_5, intersection );
    TEST_ASSERT( has_intersect );
    intersection.boundingBox( bounds );
    TEST_EQUALITY( bounds[0], 1.0 );
    TEST_EQUALITY( bounds[1], 1.0 );
    TEST_EQUALITY( bounds[2], 1.0 );
    TEST_EQUALITY( bounds[3], 1.0 );
    TEST_EQUALITY( bounds[4], 1.0 );
    TEST_EQUALITY( bounds[5], 1.0 );

    has_intersect = BoxGeometry::intersectBoxes( box_5, box_1, intersection );
    TEST_ASSERT( has_intersect );
    intersection.boundingBox( bounds );
    TEST_EQUALITY( bounds[0], 1.0 );
    TEST_EQUALITY( bounds[1], 1.0 );
    TEST_EQUALITY( bounds[2], 1.0 );
    TEST_EQUALITY( bounds[3], 1.0 );
    TEST_EQUALITY( bounds[4], 1.0 );
    TEST_EQUALITY( bounds[5], 1.0 );

    has_intersect = BoxGeometry::intersectBoxes( box_2, box_3, intersection );
    TEST_ASSERT( has_intersect );
    intersection.boundingBox( bounds );
    TEST_EQUALITY( bounds[0], 0.25 );
    TEST_EQUALITY( bounds[1], 0.25 );
    TEST_EQUALITY( bounds[2], 0.25 );
    TEST_EQUALITY( bounds[3], 0.67 );
    TEST_EQUALITY( bounds[4], 0.67 );
    TEST_EQUALITY( bounds[5], 0.67 );

    has_intersect = BoxGeometry::intersectBoxes( box_2, box_4, intersection );
    TEST_ASSERT( !has_intersect );

    has_intersect = BoxGeometry::intersectBoxes( box_2, box_5, intersection );
    TEST_ASSERT( !has_intersect );

    has_intersect = BoxGeometry::intersectBoxes( box_3, box_5, intersection );
    TEST_ASSERT( !has_intersect );

    has_intersect = BoxGeometry::intersectBoxes( box_3, box_4, intersection );
    TEST_ASSERT( !has_intersect );

    has_intersect = BoxGeometry::intersectBoxes( box_4, box_5, intersection );
    TEST_ASSERT( !has_intersect );
}
Pointer<BoxOverlap<NDIM> > SideNoCornersFillPattern::calculateOverlap(const BoxGeometry<NDIM>& dst_geometry,
                                                                      const BoxGeometry<NDIM>& src_geometry,
                                                                      const Box<NDIM>& /*dst_patch_box*/,
                                                                      const Box<NDIM>& src_mask,
                                                                      const bool overwrite_interior,
                                                                      const IntVector<NDIM>& src_offset) const
{
    Pointer<SideOverlap<NDIM> > box_geom_overlap =
        dst_geometry.calculateOverlap(src_geometry, src_mask, overwrite_interior, src_offset);
#if !defined(NDEBUG)
    TBOX_ASSERT(box_geom_overlap);
#endif
    const SideGeometry<NDIM>* const t_dst_geometry = dynamic_cast<const SideGeometry<NDIM>*>(&dst_geometry);
#if !defined(NDEBUG)
    TBOX_ASSERT(t_dst_geometry);
#endif
    boost::array<BoxList<NDIM>, NDIM> dst_boxes;
    if (!box_geom_overlap->isOverlapEmpty())
    {
        const Box<NDIM>& dst_box = t_dst_geometry->getBox();
        for (unsigned int axis = 0; axis < NDIM; ++axis)
        {
            const BoxList<NDIM>& box_geom_overlap_boxes = box_geom_overlap->getDestinationBoxList(axis);

            // Determine the stencil boxes with the specified ghost cell width.
            BoxList<NDIM> stencil_boxes;
            if (NDIM == 2 || (!d_include_edges_on_src_level && !d_include_edges_on_dst_level))
            {
                for (unsigned int i = 0; i < NDIM; ++i)
                {
                    Box<NDIM> box = dst_box;
                    box.lower()(i) -= d_stencil_width(i);
                    box.upper()(i) += d_stencil_width(i);
                    stencil_boxes.appendItem(SideGeometry<NDIM>::toSideBox(box, axis));
                }
            }
            else
            {
                for (unsigned int j = 0; j < NDIM; ++j)
                {
                    for (unsigned int i = 0; i < NDIM; ++i)
                    {
                        if (i == j) continue;
                        Box<NDIM> box = dst_box;
                        box.lower()(i) -= d_stencil_width(i);
                        box.upper()(i) += d_stencil_width(i);
                        box.lower()(j) -= d_stencil_width(j);
                        box.upper()(j) += d_stencil_width(j);
                        stencil_boxes.appendItem(SideGeometry<NDIM>::toSideBox(box, axis));
                    }
                }
            }

            // Intersect the overlap boxes with the stencil boxes.
            for (BoxList<NDIM>::Iterator it1(box_geom_overlap_boxes); it1; it1++)
            {
                BoxList<NDIM> overlap_boxes(stencil_boxes);
                overlap_boxes.intersectBoxes(it1());
                for (BoxList<NDIM>::Iterator it2(overlap_boxes); it2; it2++)
                {
                    const Box<NDIM>& overlap_box = it2();
                    if (!overlap_box.empty()) dst_boxes[axis].appendItem(overlap_box);
                }
            }
        }
    }
    return new SideOverlap<NDIM>(dst_boxes.data(), src_offset);
} // calculateOverlap
Exemplo n.º 6
0
void resetTransformation() {
	ColorCube.setIdentity();
}
Exemplo n.º 7
0
void RigidBody2DSim::boxCircleNarrowPhaseCollision( const unsigned idx_crcl, const unsigned idx_box, const CircleGeometry& circle, const BoxGeometry& box, const VectorXs& q0, const VectorXs& q1, const VectorXs& v, std::vector<std::unique_ptr<Constraint>>& active_set ) const
{
  if( isKinematicallyScripted( idx_crcl ) )
  {
    std::cerr << "Kinematic circle vs. box collisions not yet supported." << std::endl;
    std::exit( EXIT_FAILURE );
  }

  // Note: Detection is at q1...
  const Vector2s x0_t1{ q1.segment<2>( 3 * idx_crcl ) };
  const Vector2s x1_t1{ q1.segment<2>( 3 * idx_box ) };
  const scalar theta1_t1{ q1( 3 * idx_box + 2 ) };
  Vector2s n;
  Vector2s p;
  const bool is_active{ CircleBoxTools::isActive( x0_t1, circle.r(), x1_t1, theta1_t1, box.r(), n, p ) };

  // ... but constraint construction is at q0 to conserve angular momentum
  if( is_active )
  {
    if( !isKinematicallyScripted( idx_box ) )
    {
      if( idx_crcl < idx_box )
      {
        active_set.emplace_back( new BodyBodyConstraint{ idx_crcl, idx_box, p, n, q0 } );
      }
      else
      {
        active_set.emplace_back( new BodyBodyConstraint{ idx_box, idx_crcl, p, -n, q0 } );
      }
    }
    else
    {
      const Vector2s x{ q0.segment<2>( 3 * idx_box ) };
      const Vector2s vel{ v.segment<2>( 3 * idx_box ) };
      const scalar omega{ v( 3 * idx_box + 2 ) };
      active_set.emplace_back( new KinematicObjectCircleConstraint{ idx_crcl, circle.r(), n, idx_box, x, vel, omega } );
    }
  }
}
Exemplo n.º 8
0
//----------------------------------------------------------------------------
void render() {

	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
	

	// update camera rotation and height
	double angle = t * speed;
	double rotationCenterX = 0.0;
	double rotationCenterZ = 0.0;

	double camX = rotationCenterX + camRadius*cos(DegreesToRadians * 90 + angle);
	double camZ = rotationCenterZ + camRadius*sin(DegreesToRadians * 90 + angle);
	vec4 camPos = vec4(camX, camY, camZ, 1.0);
	vec4 camTarget = vec4(0.0, 0.0, 0.0, 1.0);
	vec4 camUp = vec4(0.0, 1.0, 0.0, 0.0);

	camera.LookAt(camPos, camTarget, camUp);

	// update light rotation and height
	double lightX = rotationCenterX + lightRadius*cos(DegreesToRadians * lightAngle);
	double lightZ = rotationCenterZ + lightRadius*sin(DegreesToRadians * lightAngle);


	// update MVP
	camera.updateMatrix();
	ColorCube.updateMatrix();
	scene.updateMatrix();

	mat4 MVP = camera.projViewMatrix * scene.compositeMatrix * ColorCube.compositeMatrix;

	// send model view projection matrix to shader
	GLuint u_MVP = glGetUniformLocation(program, "u_MVP");
	glUniformMatrix4fv(u_MVP, 1, GL_TRUE, MVP); // mat.h is row major, so use GL_TRUE to transpsoe t

	// send model view matrix to shader
	mat4 MV = camera.viewMatrix * scene.compositeMatrix * ColorCube.compositeMatrix;
	GLuint u_MV = glGetUniformLocation(program, "u_MV");
	glUniformMatrix4fv(u_MV, 1, GL_TRUE, MV); // mat.h is row major, so use GL_TRUE to transpsoe t


	// send light position to shader
	vec4 lightPos = vec4(lightX, lightHeight, lightZ, 1.0);
	GLuint u_lightPos = glGetUniformLocation(program, "u_lightPos");
	glUniform4fv(u_lightPos, 1, lightPos); // mat.h is row major, so use GL_TRUE to transpsoe t


	// send material option to shader
	GLuint u_material = glGetUniformLocation(program, "u_material");
	glUniform1i(u_material, materialOption); 

	// send shader option to shader
	GLuint u_shadingModel = glGetUniformLocation(program, "u_shadingModel");
	glUniform1i(u_shadingModel, shaderOption);

	// bind vertex array object
	//glBindVertexArray(ColorCube.vao.id);

	/*glBindBuffer(GL_VERTEX_ARRAY, ColorCube.vao.vertVBO);

	glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ColorCube.vao.EBO);
*/
//glDrawElements(GL_TRIANGLES, ColorCube.NUM_FACES*3, GL_UNSIGNED_INT, 0); // Draw the cube's faces
//glDrawArrays(GL_TRIANGLES, 0, ColorCube.NUM_VERTS*3); // Draw the cube's faces


	glBindBuffer(GL_VERTEX_ARRAY, vao);
	glDrawArrays(GL_TRIANGLES, 0, mesh.size()*3);
}