Skip to content

Commit b9d0ebf

Browse files
committed
adding files that have been (mysteriously) ignored by git
1 parent 3b1a12a commit b9d0ebf

17 files changed

Lines changed: 3385 additions & 0 deletions
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
/**
2+
*
3+
* LiquidFunProcessing | Copyright 2017 Thomas Diewald - www.thomasdiewald.com
4+
*
5+
* https://github.com/diwi/LiquidFunProcessing.git
6+
*
7+
* Box2d / LiquidFun Library for Processing.
8+
* MIT License: https://opensource.org/licenses/MIT
9+
*
10+
*/
11+
12+
13+
14+
package com.thomasdiewald.liquidfun.java;
15+
16+
import org.jbox2d.common.Vec2;
17+
import org.jbox2d.dynamics.World;
18+
import org.jbox2d.particle.ParticleDef;
19+
20+
21+
/**
22+
*
23+
* Custom Particle Emitter.<br>
24+
*
25+
* @author Thomas Diewald
26+
*
27+
*/
28+
public class DwParticleEmitter {
29+
30+
public World world;
31+
public DwViewportTransform transform;
32+
public ParticleDef pdef = new ParticleDef();
33+
34+
public float emit_dir = (float) (Math.PI * 0.5f);
35+
public float emit_vel = 20;
36+
public Vec2 emit_pos = new Vec2();
37+
38+
public float emit_dir_jitter = 0.2f; // [0, PI*2]
39+
public float emit_vel_jitter = 0.5f; // noise mult
40+
public float emit_pos_jitter = 0.4f; // spawn radius, world-space
41+
42+
43+
protected int counter = 0;
44+
45+
public DwParticleEmitter(World world, DwViewportTransform transform){
46+
this.world = world;
47+
this.transform = transform;
48+
}
49+
50+
51+
/**
52+
* inline Emitter-definition. <br>
53+
* Velocity and Position must be defined in screen-space dimensions.
54+
*/
55+
public void setInScreen(float pos_x, float pos_y, float vel, float dir_deg, int col_argb, int flags){
56+
emit_pos = transform.getScreen2box(pos_x, pos_y, emit_pos);
57+
emit_vel = vel / transform.screen_scale;
58+
emit_dir = dir_deg * DwUtils.TO_RAD;
59+
pdef.color.set(col_argb);
60+
pdef.flags = flags;
61+
}
62+
63+
/**
64+
* inline Emitter-definition. <br>
65+
* Velocity and Position must be defined in world-space dimensions.
66+
*/
67+
public void setInWorld(float pos_x, float pos_y, float vel, float dir_deg, int col_argb, int flags){
68+
emit_pos.set(pos_x, pos_y);
69+
emit_vel = vel;
70+
emit_dir = dir_deg * DwUtils.TO_RAD;
71+
pdef.color.set(col_argb);
72+
pdef.flags = flags;
73+
}
74+
75+
76+
77+
78+
79+
public void emitParticles(int count){
80+
for(int i = 0; i < count; i++){
81+
emitParticle();
82+
}
83+
}
84+
85+
public void emitParticle(){
86+
87+
// velocity (noise)
88+
float val1 = (float) (Math.sin(counter / 10f)) * 0.2f;
89+
float val2 = (float) (Math.cos(counter / 100f));
90+
float srandnoise = val1 * val2;
91+
92+
float rot_angle = emit_dir + srandnoise * emit_dir_jitter;
93+
float vel_mag = emit_vel + srandnoise * emit_vel_jitter;
94+
95+
float vel_x = (float) (Math.cos(rot_angle) * vel_mag);
96+
float vel_y = (float) (Math.sin(rot_angle) * vel_mag);
97+
98+
// position
99+
float[] jitter = DwUtils.sampleDisk_Halton(counter, 0.5f);
100+
101+
float pos_x = emit_pos.x + jitter[0] * emit_pos_jitter;
102+
float pos_y = emit_pos.y + jitter[1] * emit_pos_jitter;
103+
104+
// create Particle
105+
pdef.position.set(pos_x, pos_y);
106+
pdef.velocity.set(vel_x, vel_y);
107+
world.createParticle(pdef);
108+
109+
counter++;
110+
}
111+
112+
113+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/**
2+
*
3+
* LiquidFunProcessing | Copyright 2017 Thomas Diewald - www.thomasdiewald.com
4+
*
5+
* https://github.com/diwi/LiquidFunProcessing.git
6+
*
7+
* Box2d / LiquidFun Library for Processing.
8+
* MIT License: https://opensource.org/licenses/MIT
9+
*
10+
*/
11+
12+
package com.thomasdiewald.liquidfun.java.interaction;
13+
14+
import processing.event.KeyEvent;
15+
import processing.event.MouseEvent;
16+
17+
18+
/**
19+
* Interface for mouse interactions, mainly used by DwWorld to have some
20+
* default interaction handlers.
21+
*
22+
* @author Thomas Diewald
23+
*
24+
*/
25+
public interface DwInteractionEvent {
26+
27+
public void enable(boolean enable);
28+
public boolean isEnabled();
29+
30+
public boolean isActive();
31+
32+
public void setMouseButton(int button);
33+
public int getMouseButton();
34+
35+
public void mouseEvent(MouseEvent event);
36+
public void keyEvent(KeyEvent event);
37+
public void updateEvent();
38+
39+
public void setMouseOffset(int mouseX_off, int mouseY_off);
40+
}
Lines changed: 225 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,225 @@
1+
/**
2+
*
3+
* LiquidFunProcessing | Copyright 2017 Thomas Diewald - www.thomasdiewald.com
4+
*
5+
* https://github.com/diwi/LiquidFunProcessing.git
6+
*
7+
* Box2d / LiquidFun Library for Processing.
8+
* MIT License: https://opensource.org/licenses/MIT
9+
*
10+
*/
11+
12+
13+
package com.thomasdiewald.liquidfun.java.interaction;
14+
15+
import org.jbox2d.callbacks.QueryCallback;
16+
import org.jbox2d.collision.AABB;
17+
import org.jbox2d.common.Vec2;
18+
import org.jbox2d.dynamics.Body;
19+
import org.jbox2d.dynamics.BodyDef;
20+
import org.jbox2d.dynamics.BodyType;
21+
import org.jbox2d.dynamics.Fixture;
22+
import org.jbox2d.dynamics.World;
23+
import org.jbox2d.dynamics.joints.MouseJoint;
24+
import org.jbox2d.dynamics.joints.MouseJointDef;
25+
26+
import com.thomasdiewald.liquidfun.java.DwViewportTransform;
27+
28+
import processing.core.PConstants;
29+
import processing.event.KeyEvent;
30+
import processing.event.MouseEvent;
31+
32+
33+
/**
34+
*
35+
* @author Thomas Diewald
36+
*
37+
*/
38+
public class DwMouseDragBodies implements DwInteractionEvent, QueryCallback{
39+
40+
public World world;
41+
public DwViewportTransform vptransform;
42+
43+
public boolean active = false;
44+
public AABB aabb = new AABB();
45+
public Vec2 point = new Vec2();
46+
public Fixture fixture = null;
47+
public MouseJoint mouse_joint;
48+
49+
public final Vec2 mouse = new Vec2();
50+
public float mult_dragforce = 1000000f;
51+
public boolean enable_static_drag = false;
52+
53+
public int button = PConstants.LEFT;
54+
// public int button = PConstants.CENTER;
55+
// public int button = PConstants.RIGHT;
56+
57+
public DwMouseDragBodies(World world, DwViewportTransform vptransform){
58+
this.world = world;
59+
this.vptransform = vptransform;
60+
}
61+
62+
// public boolean query(Vec2 world_xy){
63+
// fixture = null;
64+
// point.set(world_xy);
65+
// aabb.lowerBound.set(point.x - 0.001f, point.y - 0.001f);
66+
// aabb.upperBound.set(point.x + 0.001f, point.y + 0.001f);
67+
// world.queryAABB(this, aabb);
68+
// return fixture != null;
69+
// }
70+
71+
public boolean query(float screen_x, float screen_y){
72+
vptransform.getScreen2box(screen_x, screen_y, mouse);
73+
fixture = null;
74+
point.set(mouse);
75+
aabb.lowerBound.set(point.x - 0.001f, point.y - 0.001f);
76+
aabb.upperBound.set(point.x + 0.001f, point.y + 0.001f);
77+
world.queryAABB(this, aabb);
78+
return fixture != null;
79+
}
80+
81+
82+
public void press(float screen_x, float screen_y) {
83+
if (query(screen_x, screen_y)) {
84+
Body body = fixture.getBody();
85+
MouseJointDef def = new MouseJointDef();
86+
def.bodyA = world.createBody(new BodyDef());
87+
def.bodyB = fixture.getBody();
88+
def.collideConnected = true;
89+
def.target.set(point);
90+
def.maxForce = mult_dragforce * body.getMass();
91+
mouse_joint = (MouseJoint) world.createJoint(def);
92+
body.setAwake(true);
93+
}
94+
active = (mouse_joint != null);
95+
}
96+
97+
98+
public void update(float screen_x, float screen_y) {
99+
if (active) {
100+
vptransform.getScreen2box(screen_x, screen_y, mouse);
101+
mouse_joint.setTarget(mouse);
102+
}
103+
}
104+
105+
106+
public void release(float screen_x, float screen_y) {
107+
if (active) {
108+
if(body_type_cpy != null){
109+
fixture.getBody().setType(body_type_cpy);
110+
body_type_cpy = null;
111+
}
112+
fixture = null;
113+
world.destroyJoint(mouse_joint);
114+
mouse_joint = null;
115+
}
116+
active = false;
117+
}
118+
119+
120+
121+
public boolean is_enabled = true;
122+
123+
@Override
124+
public void enable(boolean enable) {
125+
is_enabled = enable;
126+
}
127+
128+
@Override
129+
public boolean isEnabled() {
130+
return is_enabled;
131+
}
132+
133+
134+
135+
@Override
136+
public boolean isActive(){
137+
return active;
138+
}
139+
140+
@Override
141+
public void setMouseButton(int button){
142+
this.button = button;
143+
}
144+
145+
@Override
146+
public int getMouseButton(){
147+
return button;
148+
}
149+
150+
public BodyType body_type_cpy = null;
151+
152+
@Override
153+
public boolean reportFixture(Fixture argFixture) {
154+
Body body = argFixture.getBody();
155+
156+
// static bodies can be moved too, but need to set to dynamic for the
157+
// mousejoint to work.
158+
body_type_cpy = body.getType();
159+
if(enable_static_drag){
160+
body.setType(BodyType.DYNAMIC);
161+
}
162+
163+
if (body.getType() == BodyType.DYNAMIC)
164+
{
165+
if (argFixture.testPoint(point)) {
166+
fixture = argFixture;
167+
return false;
168+
}
169+
}
170+
return true;
171+
}
172+
173+
174+
int mouseX_off = 0;
175+
int mouseY_off = 0;
176+
int mouseX;
177+
int mouseY;
178+
179+
@Override
180+
public void mouseEvent(MouseEvent event){
181+
if(!is_enabled){
182+
return;
183+
}
184+
185+
mouseX = mouseX_off + event.getX();
186+
mouseY = mouseY_off + event.getY();
187+
if(event.getButton() == this.button){
188+
switch(event.getAction()){
189+
case MouseEvent.PRESS: press (mouseX, mouseY); break;
190+
case MouseEvent.RELEASE: release(mouseX, mouseY); break;
191+
}
192+
}
193+
}
194+
195+
public int key_combi = 0;
196+
public boolean key_combi_active = true;
197+
public boolean key_combi_enabled = true;
198+
199+
@Override
200+
public void keyEvent(KeyEvent event){
201+
switch(event.getAction()){
202+
case KeyEvent.PRESS:
203+
key_combi_active = false;
204+
break;
205+
case KeyEvent.RELEASE:
206+
key_combi_active = true;
207+
break;
208+
}
209+
}
210+
211+
@Override
212+
public void updateEvent(){
213+
update(mouseX, mouseY);
214+
}
215+
216+
@Override
217+
public void setMouseOffset(int mouseX_off, int mouseY_off){
218+
this.mouseX_off = mouseX_off;
219+
this.mouseY_off = mouseY_off;
220+
}
221+
222+
223+
224+
}
225+

0 commit comments

Comments
 (0)