Skip to content

Commit d4f2e0c

Browse files
committed
Add all classes
1 parent 513f069 commit d4f2e0c

File tree

58 files changed

+382647
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+382647
-0
lines changed

core/pom.xml

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<modelVersion>4.0.0</modelVersion>
6+
7+
<parent>
8+
<groupId>com.github.introfog.pie</groupId>
9+
<artifactId>root</artifactId>
10+
<version>1.0</version>
11+
</parent>
12+
13+
<artifactId>core</artifactId>
14+
<packaging>jar</packaging>
15+
16+
<properties>
17+
<junit.version>4.13</junit.version>
18+
<slf4j.version>1.7.30</slf4j.version>
19+
<logback.version>1.2.3</logback.version>
20+
</properties>
21+
22+
<dependencies>
23+
<dependency>
24+
<groupId>com.github.introfog.pie</groupId>
25+
<artifactId>test</artifactId>
26+
<version>1.0</version>
27+
<scope>test</scope>
28+
</dependency>
29+
<dependency>
30+
<groupId>junit</groupId>
31+
<artifactId>junit</artifactId>
32+
<version>${junit.version}</version>
33+
<scope>test</scope>
34+
</dependency>
35+
<dependency>
36+
<groupId>org.slf4j</groupId>
37+
<artifactId>slf4j-api</artifactId>
38+
<version>${slf4j.version}</version>
39+
</dependency>
40+
<dependency>
41+
<groupId>ch.qos.logback</groupId>
42+
<artifactId>logback-classic</artifactId>
43+
<version>${logback.version}</version>
44+
</dependency>
45+
</dependencies>
46+
47+
</project>
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
/*
2+
Copyright 2020 Dmitry Chubrick
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
package com.github.introfog.pie.core;
17+
18+
import com.github.introfog.pie.core.math.Vector2f;
19+
20+
import java.util.Objects;
21+
22+
public class Body {
23+
public float density;
24+
public float restitution;
25+
public float invertMass;
26+
public float staticFriction;
27+
public float dynamicFriction;
28+
/** Orientation in radians. */
29+
public float orientation;
30+
public float angularVelocity;
31+
public float torque;
32+
public float invertInertia;
33+
public Vector2f position;
34+
public Vector2f force;
35+
public Vector2f velocity;
36+
37+
public Body(float positionX, float positionY, float density, float restitution) {
38+
this.density = density;
39+
this.restitution = restitution;
40+
41+
staticFriction = 0.5f;
42+
dynamicFriction = 0.3f;
43+
torque = 0f;
44+
45+
force = new Vector2f(0f, 0f);
46+
velocity = new Vector2f(0f, 0f);
47+
position = new Vector2f(positionX, positionY);
48+
}
49+
50+
@Override
51+
public boolean equals(Object o) {
52+
if (this == o) {
53+
return true;
54+
}
55+
if (o == null || getClass() != o.getClass()) {
56+
return false;
57+
}
58+
Body body = (Body) o;
59+
return Float.compare(body.density, density) == 0 &&
60+
Float.compare(body.restitution, restitution) == 0 &&
61+
position.equals(body.position);
62+
}
63+
64+
@Override
65+
public int hashCode() {
66+
return Objects.hash(density, restitution, position);
67+
}
68+
}
Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
/*
2+
Copyright 2020 Dmitry Chubrick
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
package com.github.introfog.pie.core;
17+
18+
import com.github.introfog.pie.core.collisions.broadphase.AbstractBroadPhase;
19+
import com.github.introfog.pie.core.collisions.broadphase.BruteForceMethod;
20+
import com.github.introfog.pie.core.math.Vector2f;
21+
22+
public class Context {
23+
private float fixedDeltaTime;
24+
private float deadLoopBorder;
25+
private float epsilon;
26+
private float correctPositionPercent;
27+
private float minBorderSlop;
28+
private Vector2f gravity;
29+
private AbstractBroadPhase broadPhase;
30+
31+
public Context() {
32+
fixedDeltaTime = 1f / 60f;
33+
deadLoopBorder = fixedDeltaTime * 20f;
34+
epsilon = 0.0001f;
35+
correctPositionPercent = 0.5f;
36+
minBorderSlop = 0.1f;
37+
// Earth value is (0f, 9.807f)
38+
gravity = new Vector2f(0f, 50f);
39+
broadPhase = new BruteForceMethod();
40+
}
41+
42+
public Context(Context other) {
43+
this.fixedDeltaTime = other.fixedDeltaTime;
44+
this.deadLoopBorder = other.deadLoopBorder;
45+
this.epsilon = other.epsilon;
46+
this.correctPositionPercent = other.correctPositionPercent;
47+
this.minBorderSlop = other.minBorderSlop;
48+
this.gravity = other.gravity;
49+
this.broadPhase = other.broadPhase;
50+
}
51+
52+
public float getDeadLoopBorder() {
53+
return deadLoopBorder;
54+
}
55+
56+
public Context setDeadLoopBorder(float deadLoopBorder) {
57+
this.deadLoopBorder = deadLoopBorder;
58+
return this;
59+
}
60+
61+
public float getFixedDeltaTime() {
62+
return fixedDeltaTime;
63+
}
64+
65+
public Context setFixedDeltaTime(float fixedDeltaTime) {
66+
this.fixedDeltaTime = fixedDeltaTime;
67+
return this;
68+
}
69+
70+
public float getEpsilon() {
71+
return epsilon;
72+
}
73+
74+
public Context setEpsilon(float epsilon) {
75+
this.epsilon = epsilon;
76+
return this;
77+
}
78+
79+
public float getCorrectPositionPercent() {
80+
return correctPositionPercent;
81+
}
82+
83+
public Context setCorrectPositionPercent(float correctPositionPercent) {
84+
this.correctPositionPercent = correctPositionPercent;
85+
return this;
86+
}
87+
88+
public float getMinBorderSlop() {
89+
return minBorderSlop;
90+
}
91+
92+
public Context setMinBorderSlop(float minBorderSlop) {
93+
this.minBorderSlop = minBorderSlop;
94+
return this;
95+
}
96+
97+
public Vector2f getGravity() {
98+
return gravity;
99+
}
100+
101+
public Context setGravity(Vector2f gravity) {
102+
this.gravity = new Vector2f(gravity);
103+
return this;
104+
}
105+
106+
public AbstractBroadPhase getBroadPhase() {
107+
return broadPhase;
108+
}
109+
110+
public Context setBroadPhase(AbstractBroadPhase broadPhase) {
111+
this.broadPhase = broadPhase;
112+
return this;
113+
}
114+
115+
public float getResting() {
116+
return Vector2f.mul(gravity, fixedDeltaTime).lengthWithoutSqrt() + epsilon;
117+
}
118+
}

0 commit comments

Comments
 (0)