Skip to content

Commit 65af03f

Browse files
author
monkstone
committed
add constrain functionality
1 parent 48e715a commit 65af03f

File tree

7 files changed

+51
-8
lines changed

7 files changed

+51
-8
lines changed

arcball.gemspec

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
1+
# -*- encoding: utf-8 -*-
2+
lib = File.expand_path('../lib', __FILE__)
3+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4+
require 'arcball/version'
15
Gem::Specification.new do |s|
26
s.name = 'arcball'
3-
s.version = '0.0.1'
7+
s.version = ArcBall::VERSION
48
s.licenses = ['GPL-3.0']
59
s.has_rdoc = false
610
s.extra_rdoc_files = ['README.md', 'LICENSE.md']
@@ -16,4 +20,3 @@ Gem::Specification.new do |s|
1620
s.platform='java'
1721
s.rubygems_version = %q{2.5.2}
1822
end
19-

lib/arcball.jar

390 Bytes
Binary file not shown.

lib/arcball/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# encoding: utf-8
22
# frozen_string_literal: true
33
module ArcBall
4-
VERSION = '0.0.1'.freeze
4+
VERSION = '0.0.2'.freeze
55
end

pom.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
require 'fileutils'
22
project 'arcball', 'https://github.com/ruby-processing/ArcBall' do
33
model_version '4.0.0'
4-
id 'arcball:arcball', '0.0.1'
4+
id 'arcball:arcball', '0.0.2'
55
packaging 'jar'
66
description 'arcball for arcball'
77
organization 'ruby-processing', 'https://ruby-processing.github.io'

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ DO NOT MODIFIY - GENERATED CODE
1111
<modelVersion>4.0.0</modelVersion>
1212
<groupId>arcball</groupId>
1313
<artifactId>arcball</artifactId>
14-
<version>0.0.1</version>
14+
<version>0.0.2</version>
1515
<name>arcball</name>
1616
<description>arcball for arcball</description>
1717
<url>https://github.com/ruby-processing/ArcBall</url>

src/monkstone/arcball/Arcball.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,21 @@ public Arcball(PApplet parent) {
100100
camera = true;
101101
this.axis = Constrain.FREE; // no constraints...
102102
}
103+
104+
/**
105+
* Default centered arcball and half width or half height whichever smaller
106+
*
107+
* @param parent PApplet
108+
* @param axis Constrain
109+
*
110+
*/
111+
public Arcball(PApplet parent, Constrain axis) {
112+
// this(parent, axis, parent.width / 2.0f, parent.height / 2.0f, Math.min(parent.width, parent.height) * 0.5f);
113+
this(parent, 0f, 0f, Math.min(parent.width, parent.height) * 0.8f);
114+
parent.camera(parent.width / 2.0f, parent.height / 2.0f, (parent.height * DEPTH), 0, 0, 0, 0, 1.0f, 0);
115+
camera = true;
116+
this.axis = axis; // custom constrain...
117+
}
103118

104119
/**
105120
* mouse event to register

src/monkstone/arcball/Rarcball.java

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,17 @@
1111
* but WITHOUT ANY WARRANTY; without even the implied warranty of
1212
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1313
* GNU General Public License for more details.
14-
*
14+
*
1515
* You should have received a copy of the GNU General Public License
1616
* along with this program. If not, see http://www.gnu.org/licenses.
1717
*/
18-
1918
package monkstone.arcball;
2019

2120
import org.jruby.Ruby;
2221
import org.jruby.RubyClass;
2322
import org.jruby.RubyModule;
2423
import org.jruby.RubyObject;
24+
import org.jruby.RubySymbol;
2525
import org.jruby.anno.JRubyClass;
2626
import org.jruby.anno.JRubyMethod;
2727
import org.jruby.runtime.Arity;
@@ -83,6 +83,31 @@ public static void init(ThreadContext context, IRubyObject self, IRubyObject arg
8383
if (count == 1) {
8484
PApplet parent = (PApplet) args[0].toJava(PApplet.class);
8585
new Arcball(parent).setActive(true);
86-
}
86+
}
87+
}
88+
89+
/**
90+
*
91+
* @param context
92+
* @param self
93+
* @param args optional (no args jx = 0, jy = 0)
94+
*/
95+
@JRubyMethod(name = "constrain", meta = true, rest = true, required = 1, optional = 1)
96+
97+
public static void constrain(ThreadContext context, IRubyObject self, IRubyObject args[]) {
98+
int count = Arity.checkArgumentCount(context.getRuntime(), args, 1, 2);
99+
RubySymbol zaxis = RubySymbol.newSymbol(context.getRuntime(), "zaxis");
100+
RubySymbol xaxis = RubySymbol.newSymbol(context.getRuntime(), "xaxis");
101+
PApplet parent = (PApplet) args[0].toJava(PApplet.class);
102+
if (count == 2) {
103+
if (xaxis == args[1]) {
104+
new Arcball(parent, Constrain.XAXIS).setActive(true);
105+
}
106+
if (zaxis == args[1]) {
107+
new Arcball(parent, Constrain.ZAXIS).setActive(true);
108+
}
109+
} else {
110+
new Arcball(parent, Constrain.YAXIS).setActive(true);
111+
}
87112
}
88113
}

0 commit comments

Comments
 (0)