Más contenido relacionado
La actualidad más candente (19)
Más de Atsushi Tadokoro (20)
Sbaw090630
- 8. #pragma once
#include "ofMain.h"
#include "ofxAccelerometer.h"
#include "ofxMultiTouch.h"
#define NUM 10
class testApp : public ofSimpleApp, public ofxMultiTouchListener {
public:
void setup();
void update();
void draw();
void exit();
...( )...
ofPoint pos[NUM];
};
- 9. #include "testApp.h"
void testApp::setup(){
ofSetColor(0, 0, 255);
ofBackground(0, 0, 0);
ofSetBackgroundAuto(true);
ofSetFrameRate(60);
//
ofxMultiTouch.addListener(this);
//
for(int i=0; i<NUM; i++){
pos[i].x = -100;
pos[i].y = -100;
}
}
void testApp::update(){
}
void testApp::draw(){
for(int i=0; i<NUM; i++){
ofCircle(pos[i].x, pos[i].y, 40);
}
}
- 10. void testApp::exit() {
}
//
void testApp::mouseMoved(int x, int y){
}
void testApp::mouseDragged(int x, int y, int button){
printf("mouseDragged: %i, %i %in", x, y, button);
pos[0].x = x;
pos[0].y = y;
}
void testApp::mousePressed(int x, int y, int button){
printf("mousePressed: %i, %i %in", x, y, button);
pos[0].x = x;
pos[0].y = y;
}
void testApp::mouseReleased(){
}
void testApp::mouseReleased(int x, int y, int button){
printf("mouseReleased: %i, %i %in", x, y, button);
pos[0].x = -100;
- 11. pos[0].y = -100;
}
//
void testApp::touchDown(float x, float y, int touchId, ofxMultiTouchCustomData
*data){
printf("touchDown: %i, %i %in", x, y, touchId);
pos[touchId].x = x;
pos[touchId].y = y;
}
void testApp::touchMoved(float x, float y, int touchId, ofxMultiTouchCustomData
*data){
printf("touchMoved: %i, %i %in", x, y, touchId);
pos[touchId].x = x;
pos[touchId].y = y;
}
void testApp::touchUp(float x, float y, int touchId, ofxMultiTouchCustomData
*data){
printf("touchUp: %i, %i %in", x, y, touchId);
pos[touchId].x = -100;
pos[touchId].y = -100;
}
void testApp::touchDoubleTap(float x, float y, int touchId,
ofxMultiTouchCustomData *data){
}
- 15. #pragma once
#include "ofMain.h"
#include "ofxAccelerometer.h"
#include "ofxMultiTouch.h"
class testApp : public ofSimpleApp, public ofxMultiTouchListener {
public:
void setup();
void update();
void draw();
void exit();
...( )...
ofPoint accel;
};
- 16. #include "testApp.h"
void testApp::setup(){
ofBackground(0, 0, 0);
ofSetBackgroundAuto(true);
ofSetFrameRate(60);
//
ofxAccelerometer.setup();
}
void testApp::update(){
//x,y,z
accel.x = ofxAccelerometer.getForce().x;
accel.y = ofxAccelerometer.getForce().y;
accel.z = ofxAccelerometer.getForce().z;
//
printf("get force: %f, %f, %f n", accel.x, accel.y, accel.z);
}
- 17. void testApp::draw(){
//
float rectScale = 200.0;
ofSetColor(255, 0, 0);
ofRect(0, ofGetHeight()/2, ofGetWidth()/3,
accel.x * rectScale);
ofSetColor(0, 255, 0);
ofRect(ofGetWidth()/3, ofGetHeight()/2,
ofGetWidth()/3, accel.y * rectScale);
ofSetColor(0, 0, 255);
ofRect(ofGetWidth()/3*2, ofGetHeight()/2,
ofGetWidth()/3, accel.z * rectScale);
}
...( )...
- 20. #pragma once
#include "ofMain.h"
#include "ofxAccelerometer.h"
#include "ofxMultiTouch.h"
#include "Spot.h"
class testApp : public ofSimpleApp, public ofxMultiTouchListener {
public:
void setup();
void update();
void draw();
void exit();
...( )...
private:
Spot** sp; //Spot sp (**)
int numSpot; // Spot
};
- 21. #include "testApp.h"
#include "Spot.h"
#define NUM_POINT 5
void testApp::setup(){
ofBackground(0, 0, 0);
ofSetBackgroundAuto(true);
ofSetFrameRate(60);
// //
ofEnableAlphaBlending();
//
ofSetBackgroundAuto(false);
//
ofxAccelerometer.setup();
//
ofxMultiTouch.addListener(this);
//
numSpot = 400;
//
sp = new Spot*[numSpot];
for(int i = 0; i < numSpot; i++){
ofPoint _pos, _velocity;
_pos.x = ofRandom(0, ofGetWidth());
_pos.y = ofRandom(0, ofGetHeight());
- 22. _velocity.x = 0;
_velocity.y = 0;
float _diameter = ofRandom(1, 10);
//
sp[i] = new Spot(_pos, _velocity, _diameter);
//
sp[i]->gravity = 0.05;
//
sp[i]->friction = 0.99;
}
}
void testApp::update(){
ofSetColor(0, 0, 0, 31);
ofRect(0, 0, ofGetWidth(), ofGetHeight());
for(int i = 0; i < numSpot; i++){
sp[i]->update();
}
}
void testApp::draw(){
for(int i = 0; i < numSpot; i++){
sp[i]->display();
}
}
- 23. void testApp::exit() {
}
void testApp::mouseMoved(int x, int y){
}
void testApp::mouseDragged(int x, int y, int button){
for(int i=0; i<numSpot; i++){
if(i % NUM_POINT == 0){
sp[i]->touched = true;
sp[i]->moveTo(x, y);
}
}
}
void testApp::mousePressed(int x, int y, int button){
for(int i=0; i<numSpot; i++){
if(i % NUM_POINT == 0){
sp[i]->touched = true;
sp[i]->moveTo(x, y);
}
}
}
void testApp::mouseReleased(){
}
- 24. void testApp::mouseReleased(int x, int y, int button){
for(int i=0; i<numSpot; i++){
if(i % NUM_POINT == 0){
sp[i]->touched = false;
}
}
}
void testApp::touchDown(float x, float y, int touchId, ofxMultiTouchCustomData *data){
for(int i=0; i<numSpot; i++){
if(i % NUM_POINT == touchId){
sp[i]->touched = true;
sp[i]->moveTo(x, y);
}
}
}
void testApp::touchMoved(float x, float y, int touchId, ofxMultiTouchCustomData *data)
{
for(int i=0; i<numSpot; i++){
if(i % NUM_POINT == touchId){
sp[i]->touched = true;
sp[i]->moveTo(x, y);
}
}
}
- 25. void testApp::touchUp(float x, float y, int touchId, ofxMultiTouchCustomData *data){
for(int i=0; i<numSpot; i++){
if(i % NUM_POINT == touchId){
sp[i]->touched = false;
}
}
}
- 26. #ifndef _OF_SPOT
#define _OF_SPOT
#include "ofMain.h"
#include "ofxMultiTouch.h"
#include "ofxAccelerometer.h"
class Spot {
public:
Spot(ofPoint pos, ofPoint velocity, float diameter);
void update();
void display();
void moveTo(float x, float y);
ofPoint pos;
ofPoint velocity;
float diameter;
float gravity;
float friction;
bool touched;
};
#endif
- 27. #include "Spot.h"
Spot::Spot(ofPoint _pos, ofPoint _velocity, float _diameter)
{
pos = _pos;
velocity = _velocity;
diameter = _diameter;
touched = false;
}
void Spot::update()
{
if(!touched){
velocity *= friction;
velocity.x += gravity * ofxAccelerometer.getForce().x;
velocity.y -= gravity * ofxAccelerometer.getForce().y;
pos.x += velocity.x * diameter;
pos.y += velocity.y * diameter;
if(pos.x < diameter){
velocity.x *= -1;
pos.x = diameter;
}
if(pos.x > ofGetWidth() - diameter){
velocity.x *= -1;
pos.x = ofGetWidth() - diameter;
}
- 28. if(pos.y < diameter){
velocity.y *= -1;
pos.y = diameter;
}
if(pos.y > ofGetHeight()-diameter){
velocity.y *= -1;
pos.y = ofGetHeight()-diameter;
}
}
}
void Spot::display()
{
ofSetColor(0, 127, 255, 200);
ofCircle(pos.x, pos.y, diameter);
}
void Spot::moveTo(float x, float y)
{
pos.x = x;
pos.y = y;
velocity.x = ofRandom(-1, 1);
velocity.y = ofRandom(-1, 1);
}