本文整理汇总了C#中Box2D.Vec2类的典型用法代码示例。如果您正苦于以下问题:C# Vec2类的具体用法?C# Vec2怎么用?C# Vec2使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Vec2类属于Box2D命名空间,在下文中一共展示了Vec2类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: RopeTest
public RopeTest()
{
const int N = 40;
Vec2[] vertices = new Vec2[N];
float [] masses = new float [N];
for (int i = 0; i < N; ++i)
{
vertices[i].Set(0.0f, 20.0f - 0.25f * i);
masses[i] = 1.0f;
}
masses[0] = 0.0f;
masses[1] = 0.0f;
RopeDef def = new RopeDef();
def.vertices = new List<Vec2>(vertices);
def.count = N;
def.gravity.Set(0.0f, -10.0f);
def.masses = new List<float>(masses);
def.damping = 0.1f;
def.k2 = 1.0f;
def.k3 = 0.5f;
m_rope.Initialize(def);
m_angle = 0.0f;
m_rope.SetAngle(m_angle);
}
开发者ID:CloneDeath,项目名称:Box2D.Net,代码行数:28,代码来源:Rope.cs
示例2: Test
public Test(){
Vec2 gravity = new Vec2();
gravity.Set(0.0f, -10.0f);
m_world = new World(gravity);
m_bomb = null;
m_textLine = 30;
m_mouseJoint = null;
m_pointCount = 0;
m_debugDraw = new DebugDraw();
m_destructionListener = new TestDestructionListener();
m_destructionListener.test = this;
m_world.SetDestructionListener(m_destructionListener);
m_world.SetContactListener(this);
m_world.SetDebugDraw(m_debugDraw);
m_bombSpawning = false;
m_stepCount = 0;
BodyDef bodyDef = new BodyDef();
m_groundBody = m_world.CreateBody(bodyDef);
m_maxProfile = new Profile();
m_totalProfile = new Profile();
}
开发者ID:CloneDeath,项目名称:Box2D.Net,代码行数:26,代码来源:Test.cs
示例3: Initialize
/// Initialize the bodies, anchors, and reference angle using a world
/// anchor point.
// Point-to-point constraint
// C = p2 - p1
// Cdot = v2 - v1
// = v2 + cross(w2, r2) - v1 - cross(w1, r1)
// J = [-I -r1_skew I r2_skew ]
// Identity used:
// w k % (rx i + ry j) = w * (-ry i + rx j)
// Angle constraint
// C = angle2 - angle1 - referenceAngle
// Cdot = w2 - w1
// J = [0 0 -1 0 0 1]
// K = invI1 + invI2
public void Initialize(Body bA, Body bB, Vec2 anchor) {
bodyA = bA;
bodyB = bB;
localAnchorA = bodyA.GetLocalPoint(anchor);
localAnchorB = bodyB.GetLocalPoint(anchor);
referenceAngle = bodyB.GetAngle() - bodyA.GetAngle();
}
开发者ID:CloneDeath,项目名称:Box2D.Net,代码行数:22,代码来源:WeldJointDef.cs
示例4: DrawSolidCircle
public override void DrawSolidCircle(Vec2 center, float radius, Vec2 axis, Color color) {
float k_segments = 16.0f;
float k_increment = 2.0f * (float)System.Math.PI / k_segments;
float theta = 0.0f;
GL.Color3(0.5f * color.R, 0.5f * color.G, 0.5f * color.B);
GL.Disable(EnableCap.Texture2D);
GL.Begin(BeginMode.TriangleFan);
for (int i = 0; i < k_segments; ++i) {
Vec2 v = center + radius * new Vec2((float)System.Math.Cos(theta), (float)System.Math.Sin(theta));
GL.Vertex2(v.X, v.Y);
theta += k_increment;
}
GL.End();
theta = 0.0f;
GL.Color4(color.R, color.G, color.B, 1.0f);
GL.Begin(BeginMode.LineLoop);
for (int i = 0; i < k_segments; ++i) {
Vec2 v = center + radius * new Vec2((float)System.Math.Cos(theta), (float)System.Math.Sin(theta));
GL.Vertex2(v.X, v.Y);
theta += k_increment;
}
GL.End();
Vec2 p = center + radius * axis;
GL.Begin(BeginMode.Lines);
GL.Vertex2(center.X, center.Y);
GL.Vertex2(p.X, p.Y);
GL.End();
GL.Enable(EnableCap.Texture2D);
}
开发者ID:CloneDeath,项目名称:Box2D.Net,代码行数:31,代码来源:DebugDraw.cs
示例5: SetTarget
/// Use this to update the target point.
public void SetTarget(Vec2 target){
if (m_bodyB.IsAwake() == false)
{
m_bodyB.SetAwake(true);
}
m_targetA = target;
}
开发者ID:CloneDeath,项目名称:Box2D.Net,代码行数:8,代码来源:MouseJoint.cs
示例6: Initialize
/// Initialize the bodies, anchors, axis, and reference angle using the world
/// anchor and world axis.
// Linear constraint (point-to-line)
// d = pB - pA = xB + rB - xA - rA
// C = dot(ay, d)
// Cdot = dot(d, cross(wA, ay)) + dot(ay, vB + cross(wB, rB) - vA - cross(wA, rA))
// = -dot(ay, vA) - dot(cross(d + rA, ay), wA) + dot(ay, vB) + dot(cross(rB, ay), vB)
// J = [-ay, -cross(d + rA, ay), ay, cross(rB, ay)]
// Spring linear constraint
// C = dot(ax, d)
// Cdot = = -dot(ax, vA) - dot(cross(d + rA, ax), wA) + dot(ax, vB) + dot(cross(rB, ax), vB)
// J = [-ax -cross(d+rA, ax) ax cross(rB, ax)]
// Motor rotational constraint
// Cdot = wB - wA
// J = [0 0 -1 0 0 1]
public void Initialize(Body bA, Body bB, Vec2 anchor, Vec2 axis) {
bodyA = bA;
bodyB = bB;
localAnchorA = bodyA.GetLocalPoint(anchor);
localAnchorB = bodyB.GetLocalPoint(anchor);
localAxisA = bodyA.GetLocalVector(axis);
}
开发者ID:CloneDeath,项目名称:Box2D.Net,代码行数:24,代码来源:WheelJointDef.cs
示例7: Step
public override void Step(TestSettings settings)
{
Manifold manifold;
Collision.CollidePolygons(out manifold, m_polygonA, m_transformA, m_polygonB, m_transformB);
WorldManifold worldManifold = new WorldManifold();
worldManifold.Initialize(manifold, m_transformA, m_polygonA.m_radius, m_transformB, m_polygonB.m_radius);
m_debugDraw.DrawString("point count = {0}", manifold.points.Count());
{
Color color = Color.FromArgb(225, 225, 225);
Vec2[] v = new Vec2[Settings._maxPolygonVertices];
for (int i = 0; i < m_polygonA.m_count; ++i)
{
v[i] = Utilities.Mul(m_transformA, m_polygonA.m_vertices[i]);
}
m_debugDraw.DrawPolygon(v, m_polygonA.m_count, color);
for (int i = 0; i < m_polygonB.m_count; ++i)
{
v[i] = Utilities.Mul(m_transformB, m_polygonB.m_vertices[i]);
}
m_debugDraw.DrawPolygon(v, m_polygonB.m_count, color);
}
for (int i = 0; i < manifold.points.Count(); ++i)
{
m_debugDraw.DrawPoint(worldManifold.points[i], 4.0f, Color.FromArgb(225, 75, 75));
}
}
开发者ID:CloneDeath,项目名称:Box2D.Net,代码行数:32,代码来源:PolyCollision.cs
示例8: SetLinearOffset
/// Set/get the target linear offset, in frame A, in meters.
public void SetLinearOffset(Vec2 linearOffset){
if (linearOffset.X != m_linearOffset.X || linearOffset.Y != m_linearOffset.Y)
{
m_bodyA.SetAwake(true);
m_bodyB.SetAwake(true);
m_linearOffset = linearOffset;
}
}
开发者ID:CloneDeath,项目名称:Box2D.Net,代码行数:9,代码来源:MotorJoint.cs
示例9: Initialize
/// Initialize the bodies, anchors, and length using the world
/// anchors.
// 1-D constrained system
// m (v2 - v1) = lambda
// v2 + (beta/h) * x1 + gamma * lambda = 0, gamma has units of inverse mass.
// x2 = x1 + h * v2
// 1-D mass-damper-spring system
// m (v2 - v1) + h * d * v2 + h * k *
// C = norm(p2 - p1) - L
// u = (p2 - p1) / norm(p2 - p1)
// Cdot = dot(u, v2 + cross(w2, r2) - v1 - cross(w1, r1))
// J = [-u -cross(r1, u) u cross(r2, u)]
// K = J * invM * JT
// = invMass1 + invI1 * cross(r1, u)^2 + invMass2 + invI2 * cross(r2, u)^2
public void Initialize(Body b1, Body b2,
Vec2 anchor1, Vec2 anchor2) {
bodyA = b1;
bodyB = b2;
localAnchorA = bodyA.GetLocalPoint(anchor1);
localAnchorB = bodyB.GetLocalPoint(anchor2);
Vec2 d = anchor2 - anchor1;
length = d.Length();
}
开发者ID:CloneDeath,项目名称:Box2D.Net,代码行数:25,代码来源:DistanceJointDef.cs
示例10: RopeDef
public class RopeDef { //was struct
public RopeDef() {
vertices = new List<Vec2>();
count = 0;
masses = new List<float>();
gravity = new Vec2(0, 0);
damping = 0.1f;
k2 = 0.9f;
k3 = 0.1f;
}
开发者ID:CloneDeath,项目名称:Box2D.Net,代码行数:10,代码来源:RopeDef.cs
示例11: ReportFixture
public override float ReportFixture(Fixture fixture, Vec2 point,
Vec2 normal, float fraction)
{
m_fixture = fixture;
m_point = point;
m_normal = normal;
return fraction;
}
开发者ID:CloneDeath,项目名称:Box2D.Net,代码行数:9,代码来源:EdgeShapes.cs
示例12: DrawPolygon
public override void DrawPolygon(Vec2[] vertices, int vertexCount, Color color) {
GL.Color3(color.R, color.G, color.B);
GL.Disable(EnableCap.Texture2D);
GL.Begin(BeginMode.LineLoop);
for (int i = 0; i < vertexCount; ++i) {
GL.Vertex2(vertices[i].X, vertices[i].Y);
}
GL.End();
GL.Enable(EnableCap.Texture2D);
}
开发者ID:CloneDeath,项目名称:Box2D.Net,代码行数:10,代码来源:DebugDraw.cs
示例13: DrawSegment
public override void DrawSegment(Vec2 p1, Vec2 p2, Color color) {
GL.Color3(color.R, color.G, color.B);
GL.Disable(EnableCap.Texture2D);
GL.Begin(BeginMode.Lines);
{
GL.Vertex2(p1.X, p1.Y);
GL.Vertex2(p2.X, p2.Y);
}
GL.End();
GL.Enable(EnableCap.Texture2D);
}
开发者ID:CloneDeath,项目名称:Box2D.Net,代码行数:11,代码来源:DebugDraw.cs
示例14: Solve22
/// Solve A * x = b, where b is a column vector. This is more efficient
/// than computing the inverse in one-shot cases. Solve only the upper
/// 2-by-2 matrix equation.
public Vec2 Solve22(Vec2 b) {
float a11 = ex.X, a12 = ey.X, a21 = ex.Y, a22 = ey.Y;
float det = a11 * a22 - a12 * a21;
if (det != 0.0f) {
det = 1.0f / det;
}
Vec2 x;
x.X = det * (a22 * b.X - a12 * b.Y);
x.Y = det * (a11 * b.Y - a21 * b.X);
return x;
}
开发者ID:CloneDeath,项目名称:Box2D.Net,代码行数:14,代码来源:Mat33.cs
示例15: GetSupport
/// Get the supporting vertex index in the given direction.
public int GetSupport(Vec2 d){
int bestIndex = 0;
float bestValue = Utilities.Dot(m_vertices[0], d);
for (int i = 1; i < m_vertices.Count(); ++i) {
float value = Utilities.Dot(m_vertices[i], d);
if (value > bestValue) {
bestIndex = i;
bestValue = value;
}
}
return bestIndex;
}
开发者ID:CloneDeath,项目名称:Box2D.Net,代码行数:14,代码来源:DistanceProxy.cs
示例16: GravityTest
public GravityTest() {
// Define the gravity vector.
Vec2 gravity = new Vec2(0.0f, 10.0f);
// Construct a world object, which will hold and simulate the rigid bodies.
m_world.SetGravity(gravity);
// Define the ground body.
BodyDef groundBodyDef = new BodyDef();
groundBodyDef.Position.Set(0.0f, 20.0f);
// Call the body factory which allocates memory for the ground body
// from a pool and creates the ground box shape (also from a pool).
// The body is also added to the world.
Body groundBody = m_world.CreateBody(groundBodyDef);
// Define the ground box shape.
PolygonShape groundBox = new PolygonShape();
// The extents are the half-widths of the box.
groundBox.SetAsBox(50.0f, 10.0f);
groundBox.Density = 0;
// Add the ground fixture to the ground body.
groundBody.CreateFixture(groundBox);
// Define the dynamic body. We set its position and call the body factory.
BodyDef bodyDef = new BodyDef();
bodyDef.type = BodyType._dynamicBody;
bodyDef.Position = new Vec2(0.0f, 4.0f);
Body body = m_world.CreateBody(bodyDef);
// Define another box shape for our dynamic body.
PolygonShape dynamicBox = new PolygonShape();
dynamicBox.SetAsBox(1.0f, 1.0f);
// Define the dynamic body fixture.
FixtureDef fixtureDef = new FixtureDef();
fixtureDef.shape = dynamicBox;
// Set the box Density to be non-zero, so it will be dynamic.
fixtureDef.Density = 1.0f;
// Override the default friction.
fixtureDef.friction = 0.3f;
// Add the shape to the body.
body.CreateFixture(fixtureDef);
}
开发者ID:CloneDeath,项目名称:Box2D.Net,代码行数:49,代码来源:GravityTest.cs
示例17: DrawCircle
public override void DrawCircle(Vec2 center, float radius, Color color) {
float k_segments = 16.0f;
float k_increment = 2.0f * (float)System.Math.PI / k_segments;
float theta = 0.0f;
GL.Color3(color.R, color.G, color.B);
GL.Disable(EnableCap.Texture2D);
GL.Begin(BeginMode.LineLoop);
for (int i = 0; i < k_segments; ++i) {
Vec2 v = center + radius * new Vec2((float)System.Math.Cos(theta), (float)System.Math.Sin(theta));
GL.Vertex2(v.X, v.Y);
theta += k_increment;
}
GL.End();
GL.Enable(EnableCap.Texture2D);
}
开发者ID:CloneDeath,项目名称:Box2D.Net,代码行数:15,代码来源:DebugDraw.cs
示例18: BodyDef
/// This constructor sets the body definition default values.
public BodyDef() {
UserData = null;
Position = new Vec2(0.0f, 0.0f);
angle = 0.0f;
linearVelocity = new Vec2(0.0f, 0.0f);
angularVelocity = 0.0f;
linearDamping = 0.0f;
angularDamping = 0.0f;
allowSleep = true;
awake = true;
fixedRotation = false;
bullet = false;
type = BodyType._staticBody;
active = true;
gravityScale = 1.0f;
}
开发者ID:CloneDeath,项目名称:Box2D.Net,代码行数:17,代码来源:BodyDef.cs
示例19: Initialize
/// Initialize the bodies, anchors, lengths, max lengths, and ratio using the world anchors.
// Pulley:
// length1 = norm(p1 - s1)
// length2 = norm(p2 - s2)
// C0 = (length1 + ratio * length2)_initial
// C = C0 - (length1 + ratio * length2)
// u1 = (p1 - s1) / norm(p1 - s1)
// u2 = (p2 - s2) / norm(p2 - s2)
// Cdot = -dot(u1, v1 + cross(w1, r1)) - ratio * dot(u2, v2 + cross(w2, r2))
// J = -[u1 cross(r1, u1) ratio * u2 ratio * cross(r2, u2)]
// K = J * invM * JT
// = invMass1 + invI1 * cross(r1, u1)^2 + ratio^2 * (invMass2 + invI2 * cross(r2, u2)^2)
public void Initialize(Body bA, Body bB,
Vec2 groundA, Vec2 groundB,
Vec2 anchorA, Vec2 anchorB,
float r) {
bodyA = bA;
bodyB = bB;
groundAnchorA = groundA;
groundAnchorB = groundB;
localAnchorA = bodyA.GetLocalPoint(anchorA);
localAnchorB = bodyB.GetLocalPoint(anchorB);
Vec2 dA = anchorA - groundA;
lengthA = dA.Length();
Vec2 dB = anchorB - groundB;
lengthB = dB.Length();
ratio = r;
Utilities.Assert(ratio > Single.Epsilon);
}
开发者ID:CloneDeath,项目名称:Box2D.Net,代码行数:29,代码来源:PulleyJointDef.cs
示例20: Generate
public void Generate()
{
Vec2 lowerBound = new Vec2(-8.0f, -8.0f);
Vec2 upperBound = new Vec2(8.0f, 8.0f);
for (int i = 0; i < e_count; ++i)
{
float x = 10.0f * RandomFloat();
float y = 10.0f * RandomFloat();
// Clamp onto a square to help create collinearities.
// This will stress the convex hull algorithm.
Vec2 v = new Vec2(x, y);
v = Utilities.Clamp(v, lowerBound, upperBound);
m_points[i] = v;
}
}
开发者ID:CloneDeath,项目名称:Box2D.Net,代码行数:17,代码来源:ConvexHull.cs
注:本文中的Box2D.Vec2类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论