glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(eye.fovy, (float)eye.width/(float)eye.height, 0.1, 100000);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
gluLookAt(eye.eye[0], eye.eye[1], eye.eye[2],
eye.center[0], eye.center[1], eye.center[2],
eye.up[0], eye.up[1], eye.up[2]);
eye.calcuratePosition(beforePoint,beforeMouse[0],beforeMouse[1]);
eye.calcuratePosition(nowPoint,x,y);
eye.rotateEye(beforePoint,nowPoint);
void Eye::calcuratePosition(double result[3],int x,int y)
{
x -= this->width/2;
y -= this->height/2;
printf("%d,%d\n",x,y);
double rate = (2.0 * 50.0 * tan(PI/180*this->fovy/2))/height;
printf("%lf\n",rate);
double rateX = x * rate;
double rateY = y * rate;
for (int i = 0;i < 3; i++){
result[i] = 50.0 * this->center[i] + rateX * this->left[i] + rateY * this->up[i];
}
}
void Eye::rotateEye(double start[3],double end[3])
{
double axis[3];
double radius;
vectorNormarise(start);
vectorNormarise(end);
exteriorProduct(start ,end, axis);
vectorNormarise(axis);
radius = acos(innerrProduct(start ,end));
printf("%lf,%lf,%lf\n",start[0],start[1],start[2]);
printf("%lf,%lf,%lf\n",end[0],end[1],end[2]);
printf("%lf,%lf,%lf,%lf\n",axis[0],axis[1],axis[2],radius);
rotateVector(axis,radius,center);
rotateVector(axis,radius,up);
rotateVector(axis,radius,left);
}
void Eye::rotateBy(double axis[3],double radius)
{
rotateVector(axis,radius,center);
rotateVector(axis,radius,up);
rotateVector(axis,radius,left);
printf("%lf,%lf,%lf\n",center[0],center[1],center[2]);
printf("%lf,%lf,%lf\n",up[0],up[1],up[2]);
printf("%lf,%lf,%lf\n",up[0],up[1],up[2]);
}
void exteriorProduct(double vec1[3],double vec2[3],double resullt[3])
{
resullt[0] = vec1[1] * vec2[2] - vec1[2] * vec2[1];
resullt[1] = vec1[2] * vec2[0] - vec1[0] * vec2[2];
resullt[2] = vec1[0] * vec2[1] - vec1[1] * vec2[0];
}
double vectorSize(double vec[3])
{
return sqrt(vec[0]*vec[0]+vec[1]*vec[1]+vec[2]*vec[2]);
}
void vectorNormarise(double vec1[3])
{
double size = vectorSize(vec1);
vec1[0] /= size;
vec1[1] /= size;
vec1[2] /= size;
}
double innerrProduct(double vec1[3],double vec2[3])
{
return vec1[0]*vec2[0]+vec1[1]*vec2[1]+vec1[2]*vec2[2];
}
void rotateVector(double axis[3],double radius, double vec[3])
{
double matrix[3][3];
matrix[0][0] = axis[0] * axis[0] * (1 - cos(radius)) + cos(radius);
matrix[0][1] = axis[0] * axis[1] * (1 - cos(radius)) - axis[2] * sin(radius);
matrix[0][2] = axis[2] * axis[0] * (1 - cos(radius)) + axis[1] * sin(radius);
matrix[1][0] = axis[0] * axis[1] * (1 - cos(radius)) + axis[2] * sin(radius);
matrix[1][1] = axis[1] * axis[1] * (1 - cos(radius)) + cos(radius);
matrix[1][2] = axis[1] * axis[2] * (1 - cos(radius)) - axis[0] * sin(radius);
matrix[2][0] = axis[2] * axis[0] * (1 - cos(radius)) - axis[1] * sin(radius);
matrix[2][1] = axis[1] * axis[2] * (1 - cos(radius)) + axis[0] * sin(radius);
matrix[2][2] = axis[2] * axis[2] * (1 - cos(radius)) + cos(radius);
double tmp[3];
for (int i = 0;i < 3;i++){
tmp[i] = vec[i];
}
for (int i = 0;i < 3;i++){
vec[i] = tmp[0] * matrix[i][0] + tmp[1] * matrix[i][1] + tmp[2] * matrix[i][2];
}
}
2014年3月12日水曜日
三角形分割
for(int i=0;i<this->target.size();i++){
this->points[i]->x = this->target[i]->x;
this->points[i]->y = this->target[i]->y;
}
count = this->target.size();
for(int i=0;i<this->target.size();i++){
this->target[i]->calcuRad(&startPoint,
this->target[this->target[i]->prevNum],
this->target[this->target[i]->nextNum]);
if(this->target[i]->radian == 0.0){
this->target[i]->life =false;
this->target[this->target[i]->prevNum]->nextNum = this->target[i]->nextNum;
this->target[this->target[i]->nextNum]->prevNum = this->target[i]->prevNum;
count--;
}
//fprintf(hoge,"%d,%d\n",(int)this->target[i]->x,(int)this->target[i]->y);
}
//fclose(hoge);
int peke;
while(count>2){
for(int i=0;i<this->target.size();i++){
if(this->target[i]->radian > 0 && this->target[i]->life){
Teto *teto = this->createFrom(i);
if (this->tetoOK(teto) && !this->otherPointsInTeto(teto))
{
this->tetos.push_back(teto);
this->drawTeto(teto,tetosImg);
this->target[this->target[i]->nextNum]->prevNum = this->target[i]->prevNum;
this->target[this->target[i]->nextNum]->calcuRad(&startPoint,
this->target[this->target[this->target[i]->nextNum]->prevNum],
this->target[this->target[this->target[i]->nextNum]->nextNum]);
this->target[this->target[i]->prevNum]->nextNum = this->target[i]->nextNum;
this->target[this->target[i]->prevNum]->calcuRad(&startPoint,
this->target[this->target[this->target[i]->prevNum]->prevNum],
this->target[this->target[this->target[i]->prevNum]->nextNum]);
this->target[i]->life = false;
count--;
char c = (char)cvWaitKey ( 1 );
cvShowImage("tetosImg",tetosImg);
i++;
}
}
}
}
this->points[i]->x = this->target[i]->x;
this->points[i]->y = this->target[i]->y;
}
count = this->target.size();
for(int i=0;i<this->target.size();i++){
this->target[i]->calcuRad(&startPoint,
this->target[this->target[i]->prevNum],
this->target[this->target[i]->nextNum]);
if(this->target[i]->radian == 0.0){
this->target[i]->life =false;
this->target[this->target[i]->prevNum]->nextNum = this->target[i]->nextNum;
this->target[this->target[i]->nextNum]->prevNum = this->target[i]->prevNum;
count--;
}
//fprintf(hoge,"%d,%d\n",(int)this->target[i]->x,(int)this->target[i]->y);
}
//fclose(hoge);
int peke;
while(count>2){
for(int i=0;i<this->target.size();i++){
if(this->target[i]->radian > 0 && this->target[i]->life){
Teto *teto = this->createFrom(i);
if (this->tetoOK(teto) && !this->otherPointsInTeto(teto))
{
this->tetos.push_back(teto);
this->drawTeto(teto,tetosImg);
this->target[this->target[i]->nextNum]->prevNum = this->target[i]->prevNum;
this->target[this->target[i]->nextNum]->calcuRad(&startPoint,
this->target[this->target[this->target[i]->nextNum]->prevNum],
this->target[this->target[this->target[i]->nextNum]->nextNum]);
this->target[this->target[i]->prevNum]->nextNum = this->target[i]->nextNum;
this->target[this->target[i]->prevNum]->calcuRad(&startPoint,
this->target[this->target[this->target[i]->prevNum]->prevNum],
this->target[this->target[this->target[i]->prevNum]->nextNum]);
this->target[i]->life = false;
count--;
char c = (char)cvWaitKey ( 1 );
cvShowImage("tetosImg",tetosImg);
i++;
}
}
}
}
STLファイルの読み込み
/*fp = fopen("cube-binary.stl", "r");
Solid *solid = new Solid();
this->solids.push_back(solid);
fread(solid->name, sizeof(char), 80, fp);
printf("%s\n",solid->name);
unsigned int faceNum ;
fread(&faceNum, sizeof(unsigned int), 1, fp);
printf("%d\n",faceNum);
for (int i=0;i<faceNum;i++){
float tmp;
Face *face = new Face();
solid->faces.push_back(face);
for (int j=0;j<3;j++){
fread(&tmp, sizeof(float), 1, fp);
printf("%lf\n",tmp);
face->normal[j] = tmp;
}
for (int k=0;k<3;k++){
for (int j=0;j<3;j++){
fread(&tmp, sizeof(float), 1, fp);
printf("%lf\n",tmp);
face->vertex[j].push_back(tmp);
}
}
char tmpChar[2];
fread(tmpChar, sizeof(char), 2, fp);
}*/
//fp = fopen("cube-ascii.stl", "r");
fp = fopen("kyata001.stl", "r");
while (fscanf(fp,"%s", &s) != -1) {
printf("%s,", s);
if (strcmp(s,"solid") == 0){
Solid *solid = new Solid();
this->solids.push_back(solid);
if (fscanf(fp,"%s", &solid->name) != -1){
//printf("%s,", solid->name);
while (fscanf(fp,"%s", &s) != -1 && fscanf(fp,"%s", &s2) != -1) {
//printf("%s,%s,", s,s2);
if (strcmp(s,"facet") == 0 && strcmp(s2,"normal") == 0){
Face *face = new Face();
for (int i = 0;i<3;i++){
fscanf(fp,"%lf", &face->normal[i]);
}
if (fscanf(fp,"%s", &s) != -1 && fscanf(fp,"%s", &s2) != -1) {
//printf("%s,%s,", s,s2);
if (strcmp(s,"outer") == 0 && strcmp(s2,"loop") == 0){
bool flag = true;
while (fscanf(fp,"%s", &s) != -1) {
//printf("%s,", s);
if (strcmp(s,"vertex") == 0 ){
for (int i = 0;i<3;i++){
double vertex;
fscanf(fp,"%lf", &vertex);
face->vertex[i].push_back(vertex);
}
}else if (strcmp(s,"endloop") == 0){
//printf("OKloop,");
solid->faces.push_back(face);
break;
}
}
}
}
if (fscanf(fp,"%s", &s) != -1) {
if (strcmp(s,"endfacet") == 0 ){
//printf("OKface");
}
}
}
}
}
}
}
Solid *solid = new Solid();
this->solids.push_back(solid);
fread(solid->name, sizeof(char), 80, fp);
printf("%s\n",solid->name);
unsigned int faceNum ;
fread(&faceNum, sizeof(unsigned int), 1, fp);
printf("%d\n",faceNum);
for (int i=0;i<faceNum;i++){
float tmp;
Face *face = new Face();
solid->faces.push_back(face);
for (int j=0;j<3;j++){
fread(&tmp, sizeof(float), 1, fp);
printf("%lf\n",tmp);
face->normal[j] = tmp;
}
for (int k=0;k<3;k++){
for (int j=0;j<3;j++){
fread(&tmp, sizeof(float), 1, fp);
printf("%lf\n",tmp);
face->vertex[j].push_back(tmp);
}
}
char tmpChar[2];
fread(tmpChar, sizeof(char), 2, fp);
}*/
//fp = fopen("cube-ascii.stl", "r");
fp = fopen("kyata001.stl", "r");
while (fscanf(fp,"%s", &s) != -1) {
printf("%s,", s);
if (strcmp(s,"solid") == 0){
Solid *solid = new Solid();
this->solids.push_back(solid);
if (fscanf(fp,"%s", &solid->name) != -1){
//printf("%s,", solid->name);
while (fscanf(fp,"%s", &s) != -1 && fscanf(fp,"%s", &s2) != -1) {
//printf("%s,%s,", s,s2);
if (strcmp(s,"facet") == 0 && strcmp(s2,"normal") == 0){
Face *face = new Face();
for (int i = 0;i<3;i++){
fscanf(fp,"%lf", &face->normal[i]);
}
if (fscanf(fp,"%s", &s) != -1 && fscanf(fp,"%s", &s2) != -1) {
//printf("%s,%s,", s,s2);
if (strcmp(s,"outer") == 0 && strcmp(s2,"loop") == 0){
bool flag = true;
while (fscanf(fp,"%s", &s) != -1) {
//printf("%s,", s);
if (strcmp(s,"vertex") == 0 ){
for (int i = 0;i<3;i++){
double vertex;
fscanf(fp,"%lf", &vertex);
face->vertex[i].push_back(vertex);
}
}else if (strcmp(s,"endloop") == 0){
//printf("OKloop,");
solid->faces.push_back(face);
break;
}
}
}
}
if (fscanf(fp,"%s", &s) != -1) {
if (strcmp(s,"endfacet") == 0 ){
//printf("OKface");
}
}
}
}
}
}
}
2014年3月4日火曜日
たき火
14,3;13,3;14,3;16,3;14,3;13,3;14,3;16,3;18,3;17,3;16,3;16,3;17,12;16,3;14,3;14,3;14,3;13,3;11,3;11,3;11,3;14,3;13,3;16,3;17,3;18,12;17,9;16,3;15,3;16,3;17,6;16,3;14,3;14,3;16,3;14,12;11,3;11,3;11,3;13,3;14,3;14,3;11,3;11,3;16,3;16,3;17,3;17,3;18,12;
http://ototama.com/music/folksong/score.php?id=152
http://ototama.com/music/folksong/score.php?id=152
メダカの学校
18,6;17,6;16,9;16,3;17,6;17,3;18,3;17,12;16,6;14,6;13,9;13,3;14,18;-1,6;13,9;13,3;13,3;11,3;13,3;14,3;13,3;14,3;16,3;16,3;16,6;-1,6;13,9;13,3;13,3;11,3;13,3;14,3;13,3;14,3;16,3;16,3;16,6;-1,6;17,6;17,3;18,3;17,3;14,3;16,3;17,3;18,3;18,3;18,3;18,3;18,12
http://ototama.com/music/folksong/score.php?id=166
http://ototama.com/music/folksong/score.php?id=166
チューリップ
18,4;17,4;16,8;18,4;17,4;16,8;14,4;16,4;17,4;18,4;17,4;16,4;17,8;18,4;17,4;16,8;18,4;17,4;16,8;14,4;16,4;17,4;18,4;17,4;16,4;18,8;14,4;14,4;16,4;14,4;13,4;13,4;14,8;16,4;16,4;17,4;17,4;18,12;-1,4;
ぞうさん
16,9;17,3;18,6;16,9;17,3;18,6;15,9;14,3;13,3;11,3;13,3;13,3;14,3;15,3;14,6;11,12;13,6;10,3;11,3;13,6;15,6;14,9;13,3;17,3;18,3;15,18;;
きよしこの夜
14,9;13,3;14,6;16,18;14,9;13,3;14,6;16,12;-1,6;10,12;10,6;12,18;11,12;11,6;14,12;-1,6;13,12;13,6;11,9;12,3;13,6;14,9;13,3;14,6;16,12;-1,6;13,12;13,6;11,9;12,3;13,6;14,9;13,3;14,6;16,12;-1,6;10,12;10,6;8,9;10,3;12,6;11,18;9,12;-1,6;11,6;14,6;16,6;14,9;15,3;17,6;18,24;-1,6;
http://ototama.com/music/folksong/score.php?id=231
http://ototama.com/music/folksong/score.php?id=231
2014年3月3日月曜日
IplImageの画素値へのアクセス
for (int y = 0; y < dstImage->height; y++) {
for (int x = 0; x < dstImage->width; x++) {
dstImage->imageData[dstImage->widthStep * y + x * 4 + 3] = grayscaleImage->imageData[grayscaleImage->widthStep * y + x];
}
}
IplImage *base = cvLoadImage ("IMG_2128.JPG", CV_LOAD_IMAGE_ANYCOLOR);
IplImage *src_img = cvLoadImage ("IMG_2129.JPG", CV_LOAD_IMAGE_ANYCOLOR);
uchar p,p2;
for (int y = 0; y < base->height; y++) {
for (int x = 0; x < base->width; x++) {
for (int i=0;i<3;i++){
p = base->imageData[base->widthStep * y + x * base->nChannels + i];
p2 = src_img->imageData[src_img->widthStep * y + x * src_img->nChannels + i];
if((255-p)*0.8>0.0){
if ((255-p)*0.8 > 255-p2){
src_img->imageData[src_img->widthStep * y + x * src_img->nChannels + i] = 255;
}else{
src_img->imageData[src_img->widthStep * y + x * src_img->nChannels + i] +=
(255-p)*0.8;
}
}
}
}
}
IplImage *base = cvLoadImage ("IMG_2128.JPG", CV_LOAD_IMAGE_ANYCOLOR);
IplImage *src_img = cvLoadImage ("IMG_2129.JPG", CV_LOAD_IMAGE_ANYCOLOR);
uchar p,p2;
for (int y = 0; y < base->height; y++) {
for (int x = 0; x < base->width; x++) {
for (int i=0;i<3;i++){
p = base->imageData[base->widthStep * y + x * base->nChannels + i];
p2 = src_img->imageData[src_img->widthStep * y + x * src_img->nChannels + i];
if((255-p)*0.8>0.0){
if ((255-p)*0.8 > 255-p2){
src_img->imageData[src_img->widthStep * y + x * src_img->nChannels + i] = 255;
}else{
src_img->imageData[src_img->widthStep * y + x * src_img->nChannels + i] +=
(255-p)*0.8;
}
}
}
}
}
お正月
15,12;14,6;15,3;14,3;13,6;11,6;13,12;14,6;14,6;15,6;14,6;13,13;-1,6;15,3;15,3;17,3;17,3;18,3;18,3;18,6;15,3;15,3;14,3;14,3;13,12;13,3;13,3;14,6;15,3;15,3;15,3;15,3;14,3;14,3;13,3;13,3;11,12;15,12;14,6;15,3;14,3;13,6;11,6;13,6;13,6;14,6;14,6;13,6;14,6;15,18;-1,4
http://ototama.com/music/folksong/score.php?id=139
http://ototama.com/music/folksong/score.php?id=139
方角センサ
systemVersion = [[[UIDevice currentDevice] systemVersion] floatValue];
// 周波数(Hz)
int frequency = 10;
// インスタンスの生成
manager = [[CMMotionManager alloc] init];
// CMDeviceMotionの開始
[self startCMDeviceMotion:frequency];
- (void)startCMDeviceMotion:(int)frequency
{
// センサーの有無を確認
if (manager.deviceMotionAvailable) {
// 更新間隔の指定
manager.deviceMotionUpdateInterval = 1 / frequency; // 秒
// ハンドラ
CMDeviceMotionHandler handler = ^(CMDeviceMotion *motion, NSError *error) {
/* magnetometer */
if (5.0 < systemVersion && manager.magnetometerAvailable) {
// "磁北"か"真北"からの角度。Y軸方向を起点にするため、(x, y)を渡す
double radian = atan2(motion.magneticField.field.x, motion.magneticField.field.y);
}
/* CMAttitude */
roll = motion.attitude.roll;
pitch = motion.attitude.pitch;
yaw = motion.attitude.yaw;
rotationMatrix = motion.attitude.rotationMatrix;
double tmp[3];
double PI = 3.14159283;
tmp[0] =0.0;
tmp[1] = 0.0;
tmp[2] = -1.0;
center[0] = rotationMatrix.m11 * tmp[0] + rotationMatrix.m21 * tmp[1] +rotationMatrix.m31 * tmp[2];
center[1] = rotationMatrix.m12 * tmp[0] + rotationMatrix.m22 * tmp[1] +rotationMatrix.m32 * tmp[2];
center[2] = rotationMatrix.m13 * tmp[0] + rotationMatrix.m23 * tmp[1] +rotationMatrix.m33 * tmp[2];
for (int i=0;i<3;i++){
center[i] = round(center[i]*100)/100.0;
}
NSLog(@"center=%lf,%lf,%lf",center[0],center[1],center[2]);
tmp[0] = 0.0;
tmp[1] = 1.0;
tmp[2] = 0.0;
up[0] = rotationMatrix.m11 * tmp[0] + rotationMatrix.m21 * tmp[1] +rotationMatrix.m31 * tmp[2];
up[1] = rotationMatrix.m12 * tmp[0] + rotationMatrix.m22 * tmp[1] +rotationMatrix.m32 * tmp[2];
up[2] = rotationMatrix.m13 * tmp[0] + rotationMatrix.m23 * tmp[1] +rotationMatrix.m33 * tmp[2];
for (int i=0;i<3;i++){
up[i] = round(up[i]*100)/100.0;
}
NSLog(@"up=%lf,%lf,%lf",up[0],up[1],up[2]);
};
// DeviceMotionの開始
if (5.0 < systemVersion) {
[manager startDeviceMotionUpdatesUsingReferenceFrame:CMAttitudeReferenceFrameXTrueNorthZVertical toQueue:[NSOperationQueue currentQueue] withHandler:handler];
} else {
[manager startDeviceMotionUpdatesToQueue:[NSOperationQueue currentQueue] withHandler:handler];
}
}
}
ぞうさん
15,9;17,3;18,6;15,9;17,3;18,6;15,9;14,3;13,3;11,3;13,3;13,3;14,3;15,3;14,6;11,9;13,6;10,3;11,3;13,6;15,6;14,9;13,3;17,3;18,3;15,18
http://ototama.com/music/folksong/score.php?id=151
http://ototama.com/music/folksong/score.php?id=151
チューリップ
18,4;17,4;16,8;18,4;17,4;16,8;14,4;16,4;17,4;18,4;17,4;16,4;17,8;18,4;17,4;16,8;18,4;17,4;16,8;14,4;16,4;17,4;18,4;17,4;16,4;18,8;14,4;14,4;16,4;14,4;13,4;13,4;14,8;16,4;16,4;17,4;17,4;18,12;-1,4;-1,1
http://ototama.com/music/folksong/score.php?id=155
http://ototama.com/music/folksong/score.php?id=155
うれしいひなまつり
14,4;14,4;14,4;15,4;14,4;14,4;11,4;13,4;14,4;14,4;13,4;13,4;14,12;-1,4;16,4;16,4;16,4;17,4;16,4;16,4;14,4;16,4;17,4;17,4;16,4;17,4;18,12;-1,4;11,8;11,4;10,4;11,4;13,2;14,2;16,4;16,4;14,4;14,4;11,4;13,4;14,12;-1,4;16,8;17,4;18,4;17,4;16,4;14,4;11,4;13,4;14,4;16,4;17,4;18,12;-1,4
http://ototama.com/music/folksong/score.php?id=169
http://ototama.com/music/folksong/score.php?id=169
赤とんぼ
18,3;15,3;15,9;14,3;13,3;11,3;8,3;10,3;11,6;10,3;15,3;15,6;14,6;13,12;-1,6;13,3;10,3;11,9;10,3;8,3;10,3;11,3;10,3;11,3;13,3;11,3;13,3;15,3;13,3;14,3;15,3;15,12;-1,6
http://ototama.com/music/folksong/score.php?id=130
http://ototama.com/music/folksong/score.php?id=130
タッチ位置と画像の位置を合わせる
UITapGestureRecognizer* pan = (UITapGestureRecognizer*) sender;
CGPoint location = [pan locationInView:self.view];
NSLog(@"pan x=%f, y=%f", location.x, location.y);
started =true;
areaValue = [[AreaValue alloc] init];
areaValue->x = location.x/self.view.frame.size.width*480;
areaValue->y = location.y/self.view.frame.size.height*640;
登録:
投稿 (Atom)