inline LL triarea(plane::iterator x){
		LL res=0;
		if (x!=t.begin()) res+=traparea(pre(x),x);
		if (next(x)!=t.end()) res+=traparea(x,next(x));
		if (x!=t.begin() && next(x)!=t.end()) res+=traparea(next(x),pre(x));
		return res;
	}
Example #2
0
Camera Camera::reflected(const plane& pl) const
{
    Camera result(*this);

    vec3 s = normalize(reflect(side(), pl.normal()));
    vec3 u = normalize(reflect(up(), pl.normal()));
    vec3 d = normalize(reflect(direction(), pl.normal()));
    vec3 p = pl.reflect(position());

    mat4 mv = _modelViewMatrix;
    mv[0][0] = s.x;
    mv[0][1] = u.x;
    mv[0][2] = d.x;
    mv[1][0] = s.y;
    mv[1][1] = u.y;
    mv[1][2] = d.y;
    mv[2][0] = s.z;
    mv[2][1] = u.z;
    mv[2][2] = d.z;
    mv[3] = vec4(-mv.rotationMultiply(p), mv[3][3]);

    result.unlockUpVector();
    result.setModelViewMatrix(mv);

    return result;
}
	inline int contain(int x,int y){
		plane :: iterator S=t.begin() , T=pre(t.end()) ;
		if (x<S->first || x>T->first) return 0;
		if (x==S->first) return y<=S->second;
		if (x==T->first) return y<=T->second;
		plane::iterator it=t.lower_bound(x) , p=pre(it);
		int x1=p->first , y1=p->second , x2=it->first , y2=it->second;
		return (LL)(y-y1)*(x2-x1) <= (LL)(y2-y1)*(x-x1);
	}
Example #4
0
//Intersecao entre dois planos
pair<pt3, pt3> plane_intersect(plane u, plane v){
    pt3 p1 = u.n * u.d();
    pt3 uv = cross(u.n, v.n);
    pt3 uvu = cross(uv, u.n);
    
    if (!cmp(dot(v.n, uvu))) return mp(pt3(inf, inf), pt3(inf, inf)); //planos paralelos
    pt3 p2 = p1 - uvu * (dot(v.n, p1) - v.d()) / dot(v.n, uvu);
    return mp(p2, p2 + uv);
}
Example #5
0
bool et::intersect::rayPlane(const ray3d& r, const plane& p, vec3* intersection_pt)
{
	float d = dot(r.direction, p.normal());
	if (d < 0.0f)
	{
		if (intersection_pt)
			*intersection_pt = r.origin + r.direction * dot(p.normal(), p.planePoint() - r.origin) / d;
		return true;
	}
	return false;
}
Example #6
0
void setByplane(plane plane) {
	glLoadIdentity();
	plane->updateV();plane->doth2();
	float td=plane->thetha*toDg,ad=plane->alpha*toDg;
	glRotatef(-90,1,0,0);
	glRotatef(-plane->tht*toDg, 0.0f, 1.0f, 0.0f);
	glRotatef(-td,1,0,0);
	glRotatef(-ad, 0.0f, 1.0f, 0.0f);
	glTranslatef(-plane->cx,-plane->cy,-plane->cz); 

}
Example #7
0
image_buf
combine( const plane &p, const plane &p2, const plane &p3 )
{
	// is this really a constraint? sometimes...
	// but what about 4:2:0?
	precondition( p.dims() == p2.dims() && p.dims() == p3.dims(), "plane dimensions should match to combine to an image" );
	engine::dimensions id = p.dims();
	id.z = 3;
	id.w = 0;
	return image_buf( "i.combine_ppp", id, p, p2, p3 );
}
Example #8
0
bool isZero(plane x, plane y) {
    if (!(x.vect(y) == 0 && x.scalar(y) < 0)) return false;
    point yy;
    if (y.a == 0) {
        yy.x = 0.0;
        yy.y = -y.c / (double)y.b;
    } else {
        yy.x = -y.c / (double)y.a;
        yy.y = 0.0;
    }
    return (x.a * yy.x + x.b * yy.y + x.c) <= 0;
}
Example #9
0
plane convolve_vert( const plane &p, const std::vector<float> &k )
{
	if ( k.size() == 3 )
	{
		if ( base::equal( k[0], k[2] ) )
			return plane( "p.sep_conv3_mirror_v", p.dims(), p, k[0], k[1] );

		return plane( "p.sep_conv3_v", p.dims(), p, k[0], k[1], k[2] );
	}

	precondition( k.size() % 2 != 0, "non-odd-sized kernel {0}", k.size() );
	return plane( "p.sep_conv_v", p.dims(), p, k );
}
int cross(const line &l, const plane &pl,
          point &res) {
  ld d = sp(pl.n, l.v);
  if (sgn(d) == 0) {
    return (pl.side(l.p) == 0) ? 2 : 0;
  }
  ld t = (-sp(pl.n, l.p) - pl.d) / d;
  res = l.p + l.v * t;
  #ifdef DEBUG
  assert(pl.side(res) == 0);
  #endif
  return 1;
}
Example #11
0
bool et::intersect::segmentPlane(const segment3d& s, const plane& p, vec3* intersection_pt)
{
	vec3 ds = s.end - s.start;
	float d = dot(ds, p.normal());
	if (d >= 0.0f) return false;

	float t = dot(p.normal(), p.planePoint() - s.start) / d;
	if ((t < 0.0f) || (t > 1.0f)) return false;

	if (intersection_pt)
		*intersection_pt = s.start + t * ds;

	return true;
}
void timer(int v){
	//update planes position
	planeView.update();

	//set roll angles accoring to rate set by button press
	rollAngle = rollRate;
	pitchAngle = pitchRate;

	//compute roll and pitch
	planeView.Roll(rollAngle);
	planeView.Pitch(pitchAngle);

	glutPostRedisplay(); // trigger display function by sending redraw into message queue
	glutTimerFunc(1000 / nFPS, timer, v);
}
void render()
{
	fr.SetCameraPos(Camera.getPos());
	glm::mat4 view = Camera.getView();
	glm::mat4 projection = Camera.getProjection();
    glClearColor( 0.f, 0.f, 0.0f, 0.f );
	glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);

	fr.render(view, projection);
	
    glEnable(GL_BLEND);
	glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
	pr.render(view,projection);
	pr2.render(view,projection);
	pr3.render(view,projection);
	glDisable(GL_BLEND);

	GBuffer::BindForWriting();
	glDepthMask(GL_TRUE);
	glEnable(GL_DEPTH_TEST);
	glDepthFunc(GL_LESS);

	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
	glClearColor( 0.f, 0.f, 0.0f, 0.f );

	

    Plane.render(view,projection);
    
	glDisable(GL_DEPTH_TEST);

	GBuffer::DefaultBuffer();

	return;
}
Example #14
0
// Cut edge with plane. Return true and set weight to fraction between
// edge-start and edge-end
bool Foam::geomCellLooper::cutEdge
(
    const plane& cutPlane,
    const label edgeI,
    scalar& weight
) const
{
    const pointField& pts = mesh().points();

    const edge& e = mesh().edges()[edgeI];

    scalar s = cutPlane.normalIntersect(pts[e.start()], e.vec(pts));

    if ((s > -pointEqualTol_) && (s < 1 + pointEqualTol_))
    {
        weight = s;

        return true;
    }
    else
    {
        // Make sure we don't use this value
        weight = -GREAT;

        return false;
    }
}
//--------------------------------------------------------------------------------------
// Release D3D11 resources created in OnD3D11CreateDevice 
//--------------------------------------------------------------------------------------
void CALLBACK OnD3D11DestroyDevice( void* pUserContext )
{
    g_DialogResourceManager.OnD3D11DestroyDevice();
    g_D3DSettingsDlg.OnD3D11DestroyDevice();
    //CDXUTDirectionWidget::StaticOnD3D11DestroyDevice();
    DXUTGetGlobalResourceCache().OnDestroyDevice();
	test.destroy();
	tessplane.destroy();
	lightsphere.destroy();
	tesscube.destroy();
	fuse.destroy();
	deboard.destroy();
	board1.destroy();
	geo_alien.destroy();
	FirePart.destroy();
    SAFE_DELETE( g_pTxtHelper );
	SAFE_RELEASE(g_DepthState);
    //g_Mesh11.Destroy();
    //            
    //SAFE_RELEASE( g_pVertexLayout11 );
    //SAFE_RELEASE( g_pVertexBuffer );
    //SAFE_RELEASE( g_pIndexBuffer );
    //SAFE_RELEASE( g_pVertexShader );
    //SAFE_RELEASE( g_pPixelShader );
    //SAFE_RELEASE( g_pSamLinear );

 /*   SAFE_RELEASE( g_pcbVSPerObject );
    SAFE_RELEASE( g_pcbPSPerObject );
    SAFE_RELEASE( g_pcbPSPerFrame );*/
}
Example #16
0
    bool triangle<T,color_type>::intersects(const plane<T,color_type>& p) const
    {
        T unused;
        const point3<T>& pp = plane<T,color_type>::get_origin();
        point3<T> pu = plane<T,color_type>::get_origin() + plane<T,color_type>::get_u_vector();
        point3<T> pv = plane<T,color_type>::get_origin() + plane<T,color_type>::get_v_vector();

        if (p.quick_intersection( unit_line3<T>(pp, pu), 0, unused ) ||
            p.quick_intersection( unit_line3<T>(pp, pv), 0, unused ) ||
            p.quick_intersection( unit_line3<T>(pu, pv), 0, unused ))
        {
            return true;
        }

        return false;
    }
Example #17
0
int apeq(const plane &pl1, const plane &pl2, vfloat prec)
{
  pvecerror("int apeq(const plane &pl1, const plane &pl2, vfloat prec)");
  if( check_par( pl1.dir, pl2.dir, prec) == 0 ) return 0;
  if( apeq( pl1.piv , pl2.piv, prec) == 1) return 1;
  if( pl1.check_point_in(pl2.piv, prec) == 1 ) return 1;
  else return 0;
}
Example #18
0
plane
local_variance( const plane &p, int radius )
{
	if ( radius < 2 )
		return plane( "p.local_variance", p.dims(), p, radius );

	return local_variance( sum_area_table( p, 1 ), sum_area_table( p, 2 ), radius );
}
Example #19
0
image_buf
combine( const plane &p )
{
	engine::dimensions id = p.dims();
	id.z = 1;
	id.w = 0;
	return image_buf( "i.combine_p", id, p );
}
Example #20
0
int operator==(const plane &pl1, const plane &pl2)
{
  pvecerror("int operator==(const plane &pl1, const plane &pl2)");

  if( !(pl1.dir == pl2.dir || pl1.dir == -pl2.dir) ) return 0;
  if( pl1.piv == pl2.piv ) return 1;
  if( pl1.check_point_in(pl2.piv,0) == 1 ) return 1;
  else return 0;
}
Example #21
0
plane
local_mean( const plane &p, int radius )
{
	// worth the extra buffer?
	if ( radius < 2 )
		return plane( "p.local_mean", p.dims(), p, radius );

	return local_mean( sum_area_table( p, 1 ), radius );
}
int cross(const plane &p1, const plane &p2,
          line &res) {
  res.v = vp(p1.n, p2.n);
  if (res.v == point()) {
    if ( (p1.n * (p1.d / p1.n.dist2())) ==
         (p2.n * (p2.d / p2.n.dist2())) )
      return 2;
    else
      return 0;
  }
  plane p3;
  p3.n = res.v;
  p3.d = 0;
  bool ret = cross(p1, p2, p3, res.p);
  assert(ret);
  assert(p1.side(res.p) == 0);
  assert(p2.side(res.p) == 0);
  return 1;
}
Example #23
0
plane::plane(const plane& _plane)
	: object(_plane)
	, l1(_plane.L1())
	, l2(_plane.L2())
	, xw(_plane.XW())
	, uw(_plane.UW())
	, u1(_plane.U1())
	, u2(_plane.U2())
	, pa(_plane.PA())
	, pb(_plane.PB())
{
	
}
Example #24
0
// Cutting point of three planes
Foam::point Foam::plane::planePlaneIntersect
(
    const plane& plane2,
    const plane& plane3
) const
{
    FixedList<scalar, 4> coeffs1(planeCoeffs());
    FixedList<scalar, 4> coeffs2(plane2.planeCoeffs());
    FixedList<scalar, 4> coeffs3(plane3.planeCoeffs());

    tensor a
    (
        coeffs1[0],coeffs1[1],coeffs1[2],
        coeffs2[0],coeffs2[1],coeffs2[2],
        coeffs3[0],coeffs3[1],coeffs3[2]
    );

    vector b(coeffs1[3],coeffs2[3],coeffs3[3]);

    return (inv(a) & (-b));
}
Example #25
0
bool isPP(plane x, plane y) {
//	cout << x.a << " " << x.b << " " << x.c << " " << y.a <<" "<< y.b <<" " << y.c << endl;
    if (x.vect(y) != 0) return false;
    point yy;
    if (y.a == 0) {
        yy.x = 0.0;
        yy.y = -y.c / (double)y.b;
    } else {
        yy.x = -y.c / (double)y.a;
        yy.y = 0.0;
    }
    return (x.a * yy.x + x.b * yy.y + x.c) > 0;
}
bool cross(const plane& p1,const plane& p2,
           const plane& p3, point& res){
  ld d = det(p1.n,p2.n,p3.n);
  if (sgn(d) == 0) {
     return false;
  }
  point px(p1.n.x, p2.n.x, p3.n.x);
  point py(p1.n.y, p2.n.y, p3.n.y);
  point pz(p1.n.z, p2.n.z, p3.n.z);
  point p(-p1.d,-p2.d,-p3.d);
  res = point(
              det(p,py,pz)/d,
              det(px,p,pz)/d,
              det(px,py,p)/d
             );
  #ifdef DEBUG
  assert(p1.side(res) == 0);
  assert(p2.side(res) == 0);
  assert(p3.side(res) == 0);
  #endif
  return true;
}
Example #27
0
// Cutting point of three planes
Foam::point Foam::plane::planePlaneIntersect
(
    const plane& plane2,
    const plane& plane3
) const
{
    List<scalarList> pcs(3);
    pcs[0]= planeCoeffs();
    pcs[1]= plane2.planeCoeffs();
    pcs[2]= plane3.planeCoeffs();

    tensor a
    (
        pcs[0][0],pcs[0][1],pcs[0][2],
        pcs[1][0],pcs[1][1],pcs[1][2],
        pcs[2][0],pcs[2][1],pcs[2][2]
    );

    vector b(pcs[0][3],pcs[1][3],pcs[2][3]);

    return (inv(a) & (-b));
}
Example #28
0
void
plane::
xformOrtho4 ( const plane& planeIn, const matrix4& mat )
{
	vec3 ptOn ( vec3::NoInit );
	planeIn.closestPtIn ( ptOn, 0.0, 0.0, 0.0 );
	
	normal.xformVec4 ( planeIn.normal, mat );
	normal.normalize ();
	ptOn.xformPt4 ( ptOn, mat );
	
	// just like in setNormPt, but without redundant set of normal
	// setNormPt ( normal, ptOn )
	offset = normal.dot ( ptOn );
}
Example #29
0
straight plane::cross(const plane &pl) const 
{
  pvecerror("point plane::cross(plane &pl)");
  point plpiv=pl.Gpiv();
  vec pldir=pl.Gdir();
  vec a=dir || pldir; //direction of the overall straight lines
  if(length(a)==0)
  {
    if(plpiv == piv || check_par(pldir, dir, 0.0)!=0)
    {       // planes coinsides
      vecerror=3; return straight();
    }
    else
    {
//		cerr<<"plane::cross : straight is parallel to plane\n";
      vecerror=2; return straight();
    }
  }
  a=unit_vec(a);
  vec c=a || dir;  //perpend. for ov. str.
  straight st(piv,c);
  point pt=pl.cross(st);   //one point on ov. str.
  return straight(pt,a);     //overall straight
}
	void insert(int x,int y){
		if (t.find(x)!=t.end()){
			if (y<=t[x]) return;
			area-=triarea(t.lower_bound(x));
			t.erase(x);
		}
		plane::iterator it=t.insert(make_pair(x,y)).first;
		if (check(it)){
			t.erase(it);
			return;
		}
		area+=triarea(it);
		while (check(pre(it))){
			area-=triarea(pre(it));
			t.erase(pre(it));
		}
		while (check(next(it))){
			area-=triarea(next(it));
			t.erase(next(it));
		}
	}