Jypeli  5
The simple game programming library
PhysicsGame.cs
Siirry tämän tiedoston dokumentaatioon.
1 #region MIT License
2 /*
3  * Copyright (c) 2009 University of Jyväskylä, Department of Mathematical
4  * Information Technology.
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a copy
7  * of this software and associated documentation files (the "Software"), to deal
8  * in the Software without restriction, including without limitation the rights
9  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10  * copies of the Software, and to permit persons to whom the Software is
11  * furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included in
14  * all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22  * THE SOFTWARE.
23  */
24 #endregion
25 
26 /*
27  * Authors: Tero Jäntti, Tomi Karppinen, Janne Nikkanen.
28  */
29 
30 using System;
31 using Physics2DDotNet;
32 using Physics2DDotNet.PhysicsLogics;
33 using Physics2DDotNet.Joints;
34 using Physics2DDotNet.Solvers;
35 using AdvanceMath;
36 using System.Collections.Generic;
37 using Physics2DDotNet.Ignorers;
38 
39 namespace Jypeli
40 {
46  {
47  private GravityField gravityfield;
48  private Vector gravity = Vector.Zero;
49 
50  static internal Dictionary<int, ObjectIgnorer> IgnoreGroups = null;
51 
55  public Vector Gravity
56  {
57  get
58  {
59  return gravity;
60  }
61  set
62  {
63  gravity = value;
64  updatePhysicsConstants();
65  }
66  }
67 
71  public PhysicsGame()
72  : this( 1 )
73  {
74  }
75 
80  public PhysicsGame( int device )
81  : base( device )
82  {
83  phsEngine.BroadPhase = new Physics2DDotNet.Detectors.SelectiveSweepDetector();
84  //phsEngine.BroadPhase = new Physics2DDotNet.Detectors.SpatialHashDetector();
85 
86  SequentialImpulsesSolver phsSolver = new SequentialImpulsesSolver();
87  phsSolver.Iterations = 12;
88  phsSolver.SplitImpulse = true;
89  //phsSolver.BiasFactor = 0.7;
90  phsSolver.BiasFactor = 0.0;
91  //phsSolver.AllowedPenetration = 0.1;
92  phsSolver.AllowedPenetration = 0.01;
93  phsEngine.Solver = (CollisionSolver)phsSolver;
94  }
95 
96  private void updatePhysicsConstants()
97  {
98  if ( gravityfield != null ) gravityfield.Lifetime.IsExpired = true;
99 
100  if ( gravity != Vector.Zero )
101  {
102  gravityfield = new GravityField( new Vector2D( gravity.X, gravity.Y ), new Lifespan() );
103  phsEngine.AddLogic( gravityfield );
104  }
105  }
106  }
107 }
PhysicsGame()
Alustaa uuden fysiikkapelin.
Definition: PhysicsGame.cs:71
Vector Gravity
Painovoima. Voimavektori, joka vaikuttaa kaikkiin ei-staattisiin kappaleisiin.
Definition: PhysicsGame.cs:56
static readonly Vector Zero
Nollavektori.
Definition: Vector.cs:61
double Y
Definition: Vector.cs:275
double X
Definition: Vector.cs:274
Kantaluokka fysiikkapeleille.
PhysicsGame(int device)
Alustaa uuden fysiikkapelin.
Definition: PhysicsGame.cs:80
2D-vektori.
Definition: Vector.cs:56
Peli, jossa on fysiikan laskenta mukana. Peliin lisätyt
Definition: PhysicsGame.cs:45