Пример #1
0
/// Makes a button and its four different state bitmaps
/// @param eUp               Background for when button is Up.
/// @param eDown             Background for when button is Down.
/// @param eHilite           Background for when button is Hilit.
/// @param eStandardUp       Foreground when enabled, up.
/// @param eStandardDown     Foregrounde when enabled, down.
/// @param eDisabled         Foreground when disabled.
/// @param id                Windows Id.
/// @param placement         Placement position
/// @param processdownevents true iff button handles down events.
/// @param size              Size of the background.
AButton * ToolBar::MakeButton(teBmps eUp,
                              teBmps eDown,
                              teBmps eHilite,
                              teBmps eStandardUp,
                              teBmps eStandardDown,
                              teBmps eDisabled,
                              wxWindowID id,
                              wxPoint placement,
                              bool processdownevents,
                              wxSize size)
{
   int xoff = (size.GetWidth() - theTheme.Image(eStandardUp).GetWidth())/2;
   int yoff = (size.GetHeight() - theTheme.Image(eStandardUp).GetHeight())/2;

   typedef std::unique_ptr<wxImage> wxImagePtr;
   wxImagePtr up2        (OverlayImage(eUp,     eStandardUp, xoff, yoff));
   wxImagePtr hilite2    (OverlayImage(eHilite, eStandardUp, xoff, yoff));
   wxImagePtr down2      (OverlayImage(eDown,   eStandardDown, xoff + 1, yoff + 1));
   wxImagePtr disable2   (OverlayImage(eUp,     eDisabled, xoff, yoff));

   AButton * button =
      new AButton(this, id, placement, size, *up2, *hilite2, *down2,
            *disable2, processdownevents);

   return button;
}
Пример #2
0
static int test_dynamic_memory(int argc, char ** argv)
{
    std::shared_ptr<int> p1 = std::make_shared<int>(8);
    *p1 = 16;
    //	cout << *p1 << endl;

    //	auto p3 = shared_ptr_routine();
    //  std::shared_ptr<Unit> p4(p3.get());	//自身的拷贝才会增加引用计数
    //  p3.reset();
    //  cout << p3.use_count() << endl;
    //  p4.reset();

    //  Unit* pu = new Unit();
    //  shared_ptr_process(std::shared_ptr<Unit>(pu));	//只有一个引用

    std::shared_ptr<Unit> p4;

    //  std::unique_ptr<Unit> up(new Unit());
    //  p4.reset(up.release());

    char *cp = new char[0];		//off-the-end pointer
    char *cp2 = new char[0];
    int *ip = new int[0];
    //cout << *cp << endl;

    delete[] cp;
    delete[] cp2;
    delete[] ip;

    std::unique_ptr<Unit[]> up2(new Unit[3]);
    auto &u = up2[0];
    up2.reset();

    std::allocator<Unit> a;
    Unit* aup = a.allocate(3);
    a.construct(aup);
    a.destroy(aup);
    a.deallocate(aup, 3);

    std::vector<int> v(20);
    std::allocator<int> a2;
    auto aup2 = a2.allocate(v.size() * 2);
    auto p2 = std::uninitialized_copy(v.begin(), v.end(), aup2);

#if __cplusplus > 201103L
    auto size1 = std::uninitialized_fill_n(p2, v.size(), 40) - aup2;
    cout << size1 << endl;
#endif


    std::shared_ptr<int> p3(new int{ 8 });
    cout << *p3 << endl;

    test_text_query();

    test_manipulator();

    return 0;
}
Пример #3
0
    void fzMath_mat4LookAt(const fzPoint3& eye, const fzPoint3& center, const fzPoint3& up, float *output)
    {     
        FZ_ASSERT(output != NULL, "Output pointer cannot be NULL.");

        fzPoint3 f(center);
        f.x -= eye.x;
        f.y -= eye.y;
        f.z -= eye.z;
        f.normalize();

        fzPoint3 up2(up);
        up2.normalize();

        fzPoint3 s(f.getCrossed(up2));
        s.normalize();
        
        fzPoint3 u(s.getCrossed(f));
        //s.normalize();
        u.normalize();
        
        fzMath_mat4Identity(output);
        
        
        output[0] = s.x;
        output[4] = s.y;
        output[8] = s.z;
        
        output[1] = u.x;
        output[5] = u.y;
        output[9] = u.z;
        
        output[2] = -f.x;
        output[6] = -f.y;
        output[10] = -f.z;
        

        
        /*
        fzMat4 translationMatrix;
        fzAffineTransform translate(FZAffineTransformIdentity);
        translate.translate(-eye.x, -eye.y);
        translate.setZ(-eye.y);
         */
        
        /*
        fzMath_mat4Multiply(<#const fzFloat *mIn1#>, <#const fzFloat *mIn2#>, <#fzFloat *mOut#>)
        fzMath_mat4Multiply(output, translate, output);
        */
        
        // kmMat4 translate;
        // kmMat4Translation(&translate, -pEye->x, -pEye->y, -pEye->z);
        // kmMat4Multiply(pOut, pOut, &translate);
    }
Пример #4
0
// "dual" edge-drop problems
// cylinder: zero diam edge/ellipse, r-radius cylinder, find r-offset == cl  (ITO surface XY-slice is a circle)
// sphere: zero diam cylinder. ellipse around edge, find offset == cl (ITO surface slice is ellipse) (?)
// toroid: radius2 diam edge, radius1 cylinder, find radius1-offset-ellipse=cl (ITO surf slice is offset ellipse) (this is the offset-ellipse problem)
// cone: ??? (how is this an ellipse??)
bool MillingCutter::singleEdgeDrop(CLPoint& cl, const Point& p1, const Point& p2, double d) const {    
    Point v = p2 - p1; // vector along edge, from p1 -> p2
    Point vxy( v.x, v.y, 0.0);
    vxy.xyNormalize(); // normalized XY edge vector
    // figure out u-coordinates of p1 and p2 (i.e. x-coord in the rotated system)
    Point sc = cl.xyClosestPoint( p1, p2 );   
    assert( ( (cl-sc).xyNorm() - d ) < 1E-6 );
    // edge endpoints in the new coordinate system, in these coordinates, CL is at origo
    Point up1( (p1-sc).dot(vxy) , d, p1.z); // d, distance to line, is the y-coord in the rotated system
    Point up2( (p2-sc).dot(vxy) , d, p2.z);
    CC_CLZ_Pair contact = this->singleEdgeDropCanonical( up1, up2 ); // the subclass handles this
    CCPoint cc_tmp( sc + contact.first * vxy, EDGE); // translate back into original coord-system
    cc_tmp.z_projectOntoEdge(p1,p2);
    return cl.liftZ_if_InsidePoints( contact.second , cc_tmp , p1, p2);
}
Пример #5
0
int main()
{
    
    
    
    
    {
        std::vector<std::shared_ptr<a>> v1 ;
        std::shared_ptr<a> up1( new a ) ;
    std::shared_ptr<a> up2( new a ) ;
     v1.push_back( up1 ) ;
     v1.push_back( up2 ) ;
    }
    std::cout << "Boo\n" ;
    
}
Пример #6
0
    void fzMath_mat4LookAt(const fzPoint3& eye, const fzPoint3& center, const fzPoint3& up, float *output)
    {     
        FZ_ASSERT(output != NULL, "Output pointer cannot be NULL.");

        fzPoint3 f(center);
        f -= eye;
        f.normalize();

        fzPoint3 up2(up);
        up2.normalize();

        fzPoint3 s = f.getCrossed(up2);
        s.normalize();
        
        fzPoint3 u(s.getCrossed(f));
        // u.normalize();
        //s.normalize();
        
        fzMath_mat4Identity(output);
        
        output[0] = s.x;  //1
        output[4] = s.y;
        output[8] = s.z;
        
        output[1] = u.x;
        output[5] = u.y; // 1
        output[9] = u.z;
        
        output[2] = -f.x;
        output[6] = -f.y;
        output[10] = -f.z; // 1
    

        float x = -eye.x; //mat[12]
        float y = -eye.y; //mat[13]
        float z = -eye.z; //mat[14]


        float mat[4];
        mat[0] = output[0] * x + output[4] * y + output[8] * z + output[12];
        mat[1] = output[1] * x + output[5] * y + output[9] * z + output[13];
        mat[2] = output[2] * x + output[6] * y + output[10] * z + output[14];
        mat[3] = output[3] * x + output[7] * y + output[11] * z + output[15];
        
        
        memcpy(&output[12], mat, sizeof(float)*4);        
    }
Пример #7
0
bool Setup()
{
		D3DXVECTOR3 lightDirection(0.0f, 1.0f, 0.0f);

	TheTerrain = new Terrain(Device, "Faces.raw", 734,1024,20,1.0f);
	TheTerrain->genTexture(&lightDirection);
	TheTerrain->loadTexture("Faces.jpg");

	
		D3DXCreateFont(Device, 20, 0, FW_BOLD, 0, FALSE, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH | FF_DONTCARE, TEXT("Arial"), &m_font );
	//
	// Lights.
	//
	Barrels.init(Device, "barells/barrels.x");
	Dalek.init(Device, "dalek/dalek.x");
	tank.init(Device, "Oiltank/tank.x");
	Table.init(Device, "table/table.x");
	Ton.init(Device, "ton/ton3.x");
	Tree.init(Device, "trees/palm_tree_3.x");

	numbertrees = rand() % 100 - 1;

	for(int i = 0;  i < 10; i++)
		BoolTrash[i] = true;

	D3DXCreateSprite(Device, &spriteMap);
	D3DXCreateSprite(Device, &spritePlayer);
	for(int i = 0; i < 10; i++)
	{
		D3DXCreateSprite(Device, &spriteTrash[i]);
	}
	
	D3DXCreateTextureFromFile(Device, "Map.png", &texMap);
	srand(GetTickCount());

	TrashPositions[0].x = rand() % 360 - 180;
	TrashPositions[0].z = rand() % 360 - 180;
	float height = TheTerrain->getHeight(TrashPositions[0].x, TrashPositions[0].z);
	TrashPositions[0].y = height;

	TrashPositions[1].x = rand() % 360 - 180;
	TrashPositions[1].z = rand() % 360 - 180;
	height = TheTerrain->getHeight(TrashPositions[1].x, TrashPositions[1].z);
	TrashPositions[1].y = height;

	TrashPositions[2].x = rand() % 360 - 180;
	TrashPositions[2].z = rand() % 360 - 180;
	height = TheTerrain->getHeight(TrashPositions[2].x, TrashPositions[2].z);
	TrashPositions[2].y = height;

	TrashPositions[3].x = rand() % 360 - 180;
	TrashPositions[3].z = rand() % 360 - 180;
	height = TheTerrain->getHeight(TrashPositions[3].x, TrashPositions[3].z);
	TrashPositions[3].y = height;

	TrashPositions[4].x = rand() % 360 - 180;
	TrashPositions[4].z = rand() % 360 - 180;
	height = TheTerrain->getHeight(TrashPositions[4].x, TrashPositions[4].z);
	TrashPositions[4].y = height;

	TrashPositions[5].x = rand() % 360 - 180;
	TrashPositions[5].z = rand() % 360 - 180;
	height = TheTerrain->getHeight(TrashPositions[5].x, TrashPositions[5].z);
	TrashPositions[5].y = height;

	TrashPositions[6].x = rand() % 360 - 180;
	TrashPositions[6].z = rand() % 360 - 180;
	height = TheTerrain->getHeight(TrashPositions[6].x, TrashPositions[6].z);
	TrashPositions[6].y = height;

	TrashPositions[7].x = rand() % 360 - 180;
	TrashPositions[7].z = rand() % 360 - 180;
	height = TheTerrain->getHeight(TrashPositions[7].x, TrashPositions[7].z);
	TrashPositions[7].y = height;

	TrashPositions[8].x = rand() % 360 - 180;
	TrashPositions[8].z = rand() % 360 - 180;
	height = TheTerrain->getHeight(TrashPositions[8].x, TrashPositions[8].z);
	TrashPositions[8].y = height;

	TrashPositions[9].x = rand() % 360 - 180;
	TrashPositions[9].z = rand() % 360 - 180;
	height = TheTerrain->getHeight(TrashPositions[9].x, TrashPositions[9].z);
	TrashPositions[9].y = height;

	for(int i = 0; i < numbertrees; i++)
	{
		TreePositions[i].x = rand() % 360 - 180;
		TreePositions[i].z = rand() % 360 - 180;
		height = TheTerrain->getHeight(TreePositions[i].x, TreePositions[i].z);
		TreePositions[i].y = height;
	}

	D3DXVECTOR3 lightDir(0.707f, -0.707f, 0.707f);
	D3DXCOLOR color(1.0f, 1.0f, 1.0f, 1.0f);
	D3DLIGHT9 light = d3d::InitDirectionalLight(&lightDir, &color);

	Device->SetLight(0, &light);
	Device->LightEnable(0, true);

	Device->SetRenderState(D3DRS_NORMALIZENORMALS, true);
	Device->SetRenderState(D3DRS_SPECULARENABLE, true);

	//build skybox
	BuildSkybox(Device);

	//
	// Set Camera.
	//

	D3DXVECTOR3    pos(-0.0f, -197.0f, -0.0f);
	D3DXVECTOR3 target(0.0, 0.0f, 0.0f);
	D3DXVECTOR3     up(0.0f, 1.0f, 0.0f);

	D3DXMATRIX V;
	D3DXMatrixLookAtLH(&V, &pos, &target, &up);

	Device->SetTransform(D3DTS_VIEW, &V);

	D3DXVECTOR3    pos2(-0.0f, -10.0f, 0.0f);
	D3DXVECTOR3 target2(0.0, 0.0f, 0.0f);
	D3DXVECTOR3     up2(0.0f, 1.0f, 0.0f);

//	D3DXMATRIX V;
	D3DXMatrixLookAtLH(&mview, &pos2, &target2, &up2);

	//Device->SetTransform(D3DTS_VIEW, &mview);

	//
	// Set projection matrix.
	//
	D3DXMATRIX proj;
	D3DXMatrixPerspectiveFovLH(
			&proj,
			D3DX_PI / 4.0f, // 45 - degree
			(float)Width / (float)Height,
			1.0f,
			20001.0f);
	Device->SetTransform(D3DTS_PROJECTION, &proj);

	D3DXMatrixPerspectiveFovLH(&mprojection, D3DX_PI / 4.0f, (float)Width / (float)Height, 1.0f, 20001.0f);

	//Device->SetTransform(D3DTS_PROJECTION, &mprojection);

	return true;
}
Пример #8
0
// Checks if two sprites collide with each other
// By the nature of this project, s1 is always upright and located at 320,240
bool collision(Sprite s1, Sprite s2) {
	// Performs a quick check comparing radii
	if ((s1.position - s2.position).Magnitude() > s1.radius + s2.radius) {
		return false;
	}

	// Move everything to (0,0)
	Vector2 translate(s1.position);
	s1.position -= translate;
	s2.position -= translate;

	// Corners of s1
	double halfWidth1 = s1.size.x / 2;
	double halfHeight1 = s1.size.y / 2;
	Vector2 TR1 = s1.position + Vector2(halfWidth1, halfHeight1);
	Vector2 TL1 = s1.position + Vector2(-halfWidth1, halfHeight1);
	Vector2 BR1 = s1.position + Vector2(halfWidth1, -halfHeight1);
	Vector2 BL1 = s1.position + Vector2(-halfWidth1, -halfHeight1);
	std::vector<Vector2> s1corners = { TR1, TL1, BR1, BL1 };

	// Corners of s2
	double halfWidth2 = s2.size.x / 2;
	Vector2 right2(cos(s2.rotation) * halfWidth2, sin(s2.rotation) * halfWidth2);
	Vector2 left2 = -right2;
	double halfHeight2 = s2.size.y / 2;
	Vector2 up2(cos(s2.rotation + M_PI / 2) * halfHeight2, sin(s2.rotation + M_PI / 2) * halfHeight2);
	Vector2 down2 = -up2;
	Vector2 TR2 = s2.position + right2 + up2;
	Vector2 TL2 = s2.position + left2 + up2;
	Vector2 BR2 = s2.position + right2 + down2;
	Vector2 BL2 = s2.position + left2 + down2;
	std::vector<Vector2> s2corners = { TR2, TL2, BR2, BL2 };

	// Axes
	Vector2 axis1 = TR2 - TL2;
	Vector2 axis2 = TR2 - BR2;
	std::vector<Vector2> axes = { Vector2(1, 0), Vector2(0, 1), axis1, axis2 };

	for (auto axis : axes) {
		double min1 = s1corners[0].Dot(axis);
		double max1 = s1corners[0].Dot(axis);
		for (auto corner : s1corners) {
			Vector2 projection = corner.Project(axis);
			double scalar = projection.Dot(axis);
			if (scalar < min1) {
				min1 = scalar;
			}
			if (scalar > max1) {
				max1 = scalar;
			}
		}
		
		double min2 = s2corners[0].Dot(axis);
		double max2 = s2corners[0].Dot(axis);
		for (auto corner : s2corners) {
			Vector2 projection = corner.Project(axis);
			double scalar = projection.Dot(axis);
			if (scalar < min2) {
				min2 = scalar;
			}
			if (scalar > max2) {
				max2 = scalar;
			}
		}
		
		// Checks for no overlaps
		if (min2 >= max1 || max2 <= min1) {
			return false;
		}
	}

	return true;
}
Пример #9
0
// here we will redraw the scene according to the current state of the application.
void AppWindow::glutDisplay ()
 {
   // Clear the rendering window
   glClear ( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );

   // Build a cross with some lines (if not built yet):
   if ( _axis.changed ) // needs update
    { _axis.build(1.0f); // axis has radius 1.0
    }
   if (sunanim) {
	   sunx = 2 * (cos(2 * M_PI*sunxc / 360) + sin(2 * M_PI*sunxc / 360)); suny = 20.0f; sunz = 2 * (-sin(2 * M_PI*sunxz / 360) + cos(2 * M_PI*sunxz / 360));
   }
   else {
	   sunx = 0.0; suny = 1; sunz = -.5;
   }

   // Define our scene transformation:
   GsMat rx, ry, stransf, barrelroll, leftright, transf, updown, rightwing, leftwing, offsety, centerrwing, centerlwing, rl, rr, backR, backL, centerbackl, centerbackr, br, bl;
   GsMat rfrot, lfrot, rbrot, lbrot, rollyawpitch, ShadowT;
   rx.rotx ( _rotx );
   ry.roty ( _roty );
   stransf = rx*ry; // set the scene transformation matrix

   offsety.translation(GsVec(0.0f, -5.7f, 0.0f));

   //Rotate many degrees
   barrelroll.rotz(2 * M_PI * rotate / 360);
   leftright.roty(2 * M_PI * _turnlr / 360);
   updown.rotx(2 * M_PI * _turnud / 360);

   rollyawpitch = leftright*updown*barrelroll;

   //Translate front wings to center
   centerrwing.translation(GsVec(-0.1f,-0.15f,0.0f)); centerlwing.translation(GsVec(0.1f, -0.15f, 0.0f));
   //Translate front wings back to airplane
   rr.translation(GsVec(0.1f, 0.15f, 0.0f)); rl.translation(GsVec(-0.1f, 0.15f, 0.0f));
   //Translate back wings to center
   centerbackl.translation(GsVec(-0.05f, -0.2f, 0.0f)); centerbackr.translation(GsVec(0.05f, -0.2f, 0.0f));
   //Translate back wings to airplane
   bl.translation(GsVec(0.05f, 0.2f, 0.0f)); br.translation(GsVec(-0.05f, 0.2f, 0.0f));
   //Rotate front wings
   rightwing.rotz(2 * M_PI * _wingsflyR / 360); leftwing.rotz(2 * M_PI * -_wingsflyL / 360);
   //Rotate back wings
   backR.rotz(2 * M_PI * _backR / 360); backL.rotz(2 * M_PI * -_backL / 360);
   //Clean up draw function
   rfrot = rr*rightwing*centerrwing;
   lfrot = rl*leftwing*centerlwing;
   rbrot = br*backR*centerbackr;
   lbrot = bl*backL*centerbackl;

	//speed is fast
	GsVec P = GsVec(0.0f, 0.0f, speed);
	GsVec bd = leftright*updown*barrelroll*P;
	R = R + bd;
	transf.setrans(R);

	GsVec sbd = leftright*P;
	SR = SR + sbd;
	ShadowT.setrans(SR);

   // Define our projection transformation:
   // (see demo program in gltutors-projection.7z, we are replicating the same behavior here)
   GsMat camview, camview2, _birdseye, persp, sproj;

   GsVec eye(0,0,0), center(0,0,0), up(0,1,0);
   GsVec eye2(0, 10, 0), center2(0, 0, 0), up2(0, 0, 1);
   eye += R + leftright*updown*barrelroll*GsVec(0,0,2);
   center += R + GsVec(0, 0, 0);

   _sun.build(1.0f, sunx, suny, sunz);
   float ground[4] = { 0, 1, 0, 4.99 };
   float light[4] = { sunx, suny, sunz, 0 };
   float  dot;
   GsMat shadowMat;

   dot = ground[0] * light[0] +
	   ground[1] * light[1] +
	   ground[2] * light[2] +
	   ground[3] * light[3];
    
   shadowMat.setl1(dot - light[0] * ground[0], 0.0 - light[0] * ground[1], 0.0 - light[0] * ground[2], 0.0 - light[0] * ground[3]);
   shadowMat.setl2(0.0 - light[1] * ground[0], dot - light[1] * ground[1], 0.0 - light[1] * ground[2], 0.0 - light[1] * ground[3]);
   shadowMat.setl3(0.0 - light[2] * ground[0], 0.0 - light[2] * ground[1], dot - light[2] * ground[2], 0.0 - light[2] * ground[3]);
   shadowMat.setl4(0.0 - light[3] * ground[0], 0.0 - light[3] * ground[1], 0.0 - light[3] * ground[2], dot - light[3] * ground[3]);
   
   //shadowMat = shadowMat*ry*rx;
   camview.lookat ( eye, center, up ); // set our 4x4 "camera" matrix
   camview2.lookat(eye2, center2, up2);

   float aspect=1.0f, znear=0.1f, zfar=5000.0f;
   persp.perspective ( _fovy, aspect, znear, zfar ); // set our 4x4 perspective matrix

   // Our matrices are in "line-major" format, so vertices should be multiplied on the 
   // right side of a matrix multiplication, therefore in the expression below camview will
   // affect the vertex before persp, because v' = (persp*camview)*v = (persp)*(camview*v).
   if (camera) {
	   sproj = persp * camview; // set final scene projection
   }
   else {
	   sproj = persp * camview2;
   }

   //  Note however that when the shader receives a matrix it will store it in column-major 
   //  format, what will cause our values to be transposed, and we will then have in our 
   //  shaders vectors on the left side of a multiplication to a matrix.
   float col = 1;
   // Draw:
   //if ( _viewaxis ) _axis.draw ( stransf, sproj );
	_model.draw(stransf*transf*rollyawpitch, sproj, _light, 0);
	_model2.draw(stransf*transf*rollyawpitch*rfrot, sproj, _light, 0);
	_model3.draw(stransf*transf*rollyawpitch*lfrot, sproj, _light, 0);
	_model4.draw(stransf*transf*rollyawpitch, sproj, _light, 0);
	_model5.draw(stransf*transf*rollyawpitch*rbrot, sproj, _light, 0);
	_model6.draw(stransf*transf*rollyawpitch*lbrot, sproj, _light, 0);
	_floor.draw(stransf, sproj, _light, textures);
	_city.draw(stransf*offsety, sproj, _light, 0);
	_city.draw(stransf*shadowMat*offsety, sproj, _shadow, 0);
	//Shadow
	_model.draw(stransf*ShadowT*shadowMat*rollyawpitch, sproj, _shadow, 1);
	_model2.draw(stransf*ShadowT*shadowMat*rollyawpitch, sproj, _shadow, 1);
	_model3.draw(stransf*ShadowT*shadowMat*rollyawpitch, sproj, _shadow, 1);
	_model4.draw(stransf*ShadowT*shadowMat*rollyawpitch, sproj, _shadow, 1);
	_model5.draw(stransf*ShadowT*shadowMat*rollyawpitch, sproj, _shadow, 1);
	_model6.draw(stransf*ShadowT*shadowMat*rollyawpitch, sproj, _shadow, 1);
	_side.draw(stransf, sproj, _light, col, textures);
	_sun.draw(stransf, sproj);


   // Swap buffers and draw:
   glFlush();         // flush the pipeline (usually not necessary)
   glutSwapBuffers(); // we were drawing to the back buffer, now bring it to the front
}