Skip to content

Commit

Permalink
First commit, added my stuf so far (camera), README, and gitignore
Browse files Browse the repository at this point in the history
  • Loading branch information
rwb11001 committed Nov 18, 2015
1 parent d21397d commit d93e888
Show file tree
Hide file tree
Showing 11 changed files with 22,152 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# vim stuff
.swp

# Ignore Build results
*.properties
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
# RangeSearch
A computational geometry project.
Binary file added kdtest/.Camera.pde.swp
Binary file not shown.
74 changes: 74 additions & 0 deletions kdtest/Camera.pde
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
class Camera {
float _x;
float _y;
float _scale;
float _angle;
float _oldX;
float _oldY;
float _oldAngle;
float _oldScale;

int _initMX;
int _initMY;

Camera() {
_x = 0.0;
_y = 0.0;
_scale = 1.0;
_angle = 4 * PI;
}

void update() {
translate(_x + width/2,_y + height/2);
rotate(_angle);
scale(_scale);
}

void mousePressed() {
_initMX = mouseX;
_initMY = mouseY;
_oldScale = _scale;
_oldX = _x;
_oldY = _y;
_oldAngle = _angle;
}

void mouseDragged() {
float difX = (float)(mouseX - _initMX);
float difY = (float)(mouseY - _initMY);

switch(G_mode) {
case 1:
difX /= (float)(width);
difY /= (float)(height);
_scale = epsilon + (1 - 4*(difX + difY)) * _oldScale;
break;
case 2:
difX *= _scale;
difY *= _scale;
_x = cos(_angle)*difX + sin(_angle)*difY + _oldX;
_y = -sin(_angle)*difX + cos(_angle)*difY + _oldY;
break;
case 3:
float initAngle = atan((_initMY - height/2)/(epsilon + _initMX - width/2));
float newAngle = atan((mouseY - height/2)/(epsilon + mouseX - width/2));
float delta = newAngle - initAngle;
_angle = _oldAngle + delta;
_x = cos(delta) * _oldX - sin(delta)*_oldY;
_y = sin(delta) * _oldX + sin(delta)*_oldY;
break;
}
}

void mouseReleased() {

}

Point transform(Point p) {
float px = (1/_scale)*(p._x - width/2);
float py = (1/_scale)*(p._y - height/2);
float x = cos(_angle)*px - sin(_angle)*py - _y;
float y = sin(_angle)*px + cos(_angle)*py - _x;
return new Point(x,y);
}
}
35 changes: 35 additions & 0 deletions kdtest/Console.pde
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
class Console {
int _textSize = 10;
int _bufferSize = 40;
int _xOffset = 20;
int _yOffset = 20;
ArrayList<String> _stringList;

Console() {
_stringList = new ArrayList<String> ();
}

void print(String s) {
_stringList.add(s);
}

void draw() {
pushStyle();
noStroke();
fill(0,0,0,150);
rect(0,0,400,_yOffset + (_bufferSize + 1) * _textSize);
fill(30,250,30);
textSize(_textSize);
int index = 0;
int c = 0;
if (_stringList.size() - _bufferSize > 0) {
index = (_stringList.size() - _bufferSize) - 1;
}
while(index < _stringList.size()) {
text(_stringList.get(index), _xOffset, _yOffset + c * _textSize);
index++;
c++;
}
popStyle();
}
}
34 changes: 34 additions & 0 deletions kdtest/Mode.pde
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
class Mode {
int _h = 30;
int _w = 60;
color c = color(256,256,256);

Mode () {

}

void draw() {
pushStyle();
fill(c);
rect(0,height,_w,height-_h);
fill(0);
textSize(30);
String s = new String();
switch(G_mode) {
case 1:
s = "SCALE";
break;
case 2:
s = "PAN";
break;
case 3:
s = "ROTATE";
break;
case 4:
s = "PLACE";
break;
}
text(s,10, height-_h);
popStyle();
}
}
9 changes: 9 additions & 0 deletions kdtest/Point.pde
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
class Point {
float _x;
float _y;

Point(float x0, float y0) {
_x = x0;
_y = y0;
}
}
86 changes: 86 additions & 0 deletions kdtest/kdtest.pde
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
Console con;
Camera cam;
Mode statusLine;

ArrayList<Point> pointList;

boolean drawCon;
float epsilon = 0.000001;
int G_mode;
// 1 = SCALE
// 2 = PAN
// 3 = ROTATE
// 4 = PLACE

void setup() {
size(800,800);
background(120);
stroke(256,256,256);
ellipseMode(CENTER);

con = new Console();
cam = new Camera();
statusLine = new Mode();

pointList = new ArrayList<Point>();

drawCon = false;
G_mode = 1;
}

void draw() {
background(120);

pushMatrix();
cam.update();
drawGnoman(200);
for(Point p: pointList) {
ellipse(p._x, p._y, 40,40);
}
popMatrix();

if(drawCon) con.draw();
statusLine.draw();
}

void keyPressed() {
switch(key) {
case 't':
con.print("t");
drawCon = !drawCon;
break;
case 'f':
G_mode = 1;
break;
case 'd':
G_mode = 2;
break;
case 's':
G_mode = 3;
break;
case 'a':
G_mode = 4;
break;
}
}

void drawGnoman(int r) {
line(-r,0,r,0);
line(0,-r,0,r);
}

void mousePressed() {
if(G_mode == 4) {
pointList.add(cam.transform(new Point(mouseX, mouseY)));
}
cam.mousePressed();
con.print("Pressed");
}

void mouseDragged() {
cam.mouseDragged();
}

void mouseReleased() {
cam.mouseReleased();
}
77 changes: 77 additions & 0 deletions kdtest/web-export/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
<!DOCTYPE html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>kdtest : Built with Processing and Processing.js</title>
<link rel="icon" type="image/x-icon" href="data:image/x-icon;base64,AAABAAEAEBAQAAEABAAoAQAAFgAAACgAAAAQAAAAIAAAAAEABAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAADAQAAVzABAEAjBQAaDwYAWjUGAGE6CQBrQQ0ATS8PAFhAJwBUQC8AbFI6AHVXPACBZk4A4NrWAPb19QAAAAAAAMmZmZmZmgAJIwAAAAAAcMIjPjA+PjAKpxIuMDMzMAm0Ii4zMzMACaIiLt3dMAAJtyIuIzPQAAm0Un5yM+IzKLRkfncy4iIotRF+dyLkIiq0QX53F+EiGrQUTkd34iIatEVu7u5iIVrBVVRBRFRVbAtGZGZla2uwAMu7u7u8vADAAwAAgAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAIABAADAAwAA" />
<meta name="Generator" content="Processing" />
<!-- - - - - - - - - - - - - - - - - - - - -
+
+ Wondering how this works?
+
+ Go to: http://processing.org/
+ and: http://processingjs.org/
+
+ - - - - - - - - - - - - - - - - - - - - -->
<style type="text/css">
body {
background-color: #333; color: #bbb; line-height: normal;
font-family: Lucida Grande, Lucida Sans, Arial, Helvetica Neue, Verdana, Geneva, sans-serif;
font-size: 11px; font-weight: normal; text-decoration: none;
line-height: 1.5em;
}
a img {
border: 0px solid transparent;
}
a, a:link, a:visited, a:active, a:hover {
color: #cdcdcd; text-decoration: underline;
}
h1 {
font-family: Arial, Helvetica Neue, Verdana, Geneva, sans-serif;
width: 100%; letter-spacing: 0.1em;
margin-bottom: 1em; font-size: 1.65em;
}
canvas {
display: block;
outline: 0px;
margin-bottom: 1.5em;
}
#content {
margin: 50px auto 0px auto; padding: 25px 25px 15px 25px;
width: 800px; min-width: 300px; overflow: auto;
border-left: 1px solid #444; border-top: 1px solid #444;
border-right: 1px solid #333; border-bottom: 1px solid #333;
background-color: #3d3d3d;
}
</style>
<!--[if lt IE 9]>
<script type="text/javascript">alert("Your browser does not support the canvas tag.");</script>
<![endif]-->
<script src="processing.js" type="text/javascript"></script>
<script type="text/javascript">
// convenience function to get the id attribute of generated sketch html element
function getProcessingSketchId () { return 'kdtest'; }
</script>

</head>
<body>
<div id="content">
<div>
<canvas id="kdtest" data-processing-sources="kdtest.pde"
width="800" height="800">
<p>Your browser does not support the canvas tag.</p>
<!-- Note: you can put any alternative content here. -->
</canvas>
<noscript>
<p>JavaScript is required to view the contents of this page.</p>
</noscript>
</div>
<h1>kdtest</h1>
<p id="description"></p>
<p id="sources">Source code: <a href="kdtest.pde">kdtest</a> </p>
<p>
Built with <a href="http://processing.org" title="Processing">Processing</a>
and <a href="http://processingjs.org" title="Processing.js">Processing.js</a>
</p>
</div>
</body>
</html>
Loading

0 comments on commit d93e888

Please sign in to comment.