CodePudding user response:
Involved in mathematical modeling,,
Implement some detection function, rectangle, circle, triangle, objects can test whether intersect each other (collision detection), and returns the node/contact, such as
General games are simple bounding box box, and building box, box collision,
Lazy can try the next box2d,
Box2D is an object used to simulate 2 d rigid body in the c + + engine, zlib license is a free software license agreement, but not a copyleft,
For example: write a table tennis game, with 2 d physics engine is ok,
CodePudding user response:
My figure is like this:Through the basic drawing graphics the basic geometry, if the two geometries, how together?
CodePudding user response:
See you how to implement, data structure, a feasible method is:Low set a the base class for all graphical BaseGraph, all graphics are derived from this class,
Establishing various subclasses of graphics, such as straight line, arc class;
Low set up special nodes: merge node class, its internal can accommodate other graphics class,
Low with a container to place these nodes, in the window to redraw, delete selected in view of the first node (not visible nodes do not need to draw), and then implement re-paint,,
Pseudo code:
Public abstract class BaseGraph
{
Public Rectange localRect {get; The set; }=Vector2. Zero;//the coordinates relative to the parent node
Public Rectangle worldRect//view coordinate system coordinates,
{
The get {return LocalRectangleToWorldRectangle (localRect); }
The set {localRect=WorldRectangleToLocalRectangle (value); }
}
Public BaseGrpah Parent {get; The set; }=null;//parent node
Public abstract void ontouch ();//draw
Public Rectangle LocalRectangleToWorldRectangle (Rectangle rc);//local coordinate conversion coordinates for the world
Public Rectangle WorldRectangleToLocalRectangle (Rectangle rc);//the world coordinate is converted to a local coordinate
}
Public class Line: BaseGraph
{
Public overwrite void ontouch ()
{
DrawLine (worldRect worldRect. Left, top, worldRect. Right, worldRect, bottom);
}
}
. Other node...
Public class CombinNode: BaseGraph
{
ListChildrens.
Public void AddChildren (BaseGraph node)
{
Node. The parent=this;
Childrens. Add (node);
}
Public overrite void ontouch ()
{
The foreach (var node in childrens)
{
Node. Ontouch ();
}
}
}
//...
CodePudding user response:
To learn OpenGL, you can refer to OpenFlight, OSGCodePudding user response: