comparison engine/core/view/camera.cpp @ 155:29309cd5e240

fix searching for instances in a rect - old code had false positives
author spq@33b003aa-7bff-0310-803a-e67f0ece8222
date Sun, 12 Oct 2008 19:23:10 +0000
parents 47979f9dce55
children 56ac89189bc4
comparison
equal deleted inserted replaced
154:d29593182f40 155:29309cd5e240
335 if ((vc.dimensions.intersects(screen_rect))) { 335 if ((vc.dimensions.intersects(screen_rect))) {
336 assert(vc.image); 336 assert(vc.image);
337 Uint8 r, g, b, a; 337 Uint8 r, g, b, a;
338 for(int xx = screen_rect.x; xx < screen_rect.x + screen_rect.w; xx++) { 338 for(int xx = screen_rect.x; xx < screen_rect.x + screen_rect.w; xx++) {
339 for(int yy = screen_rect.y; yy < screen_rect.y + screen_rect.h; yy++) { 339 for(int yy = screen_rect.y; yy < screen_rect.y + screen_rect.h; yy++) {
340 int x = xx - vc.dimensions.x; 340 if ((vc.dimensions.contains(Point(xx, yy)))) {
341 int y = yy - vc.dimensions.y; 341 int x = xx - vc.dimensions.x;
342 if (m_zoom != 1.0) { 342 int y = yy - vc.dimensions.y;
343 double fx = static_cast<double>(x); 343 if (m_zoom != 1.0) {
344 double fy = static_cast<double>(y); 344 double fx = static_cast<double>(x);
345 double fow = static_cast<double>(vc.image->getWidth()); 345 double fy = static_cast<double>(y);
346 double foh = static_cast<double>(vc.image->getHeight()); 346 double fow = static_cast<double>(vc.image->getWidth());
347 double fsw = static_cast<double>(vc.dimensions.w); 347 double foh = static_cast<double>(vc.image->getHeight());
348 double fsh = static_cast<double>(vc.dimensions.h); 348 double fsw = static_cast<double>(vc.dimensions.w);
349 x = static_cast<int>(round(fx / fsw * fow)); 349 double fsh = static_cast<double>(vc.dimensions.h);
350 y = static_cast<int>(round(fy / fsh * foh)); 350 x = static_cast<int>(round(fx / fsw * fow));
351 } 351 y = static_cast<int>(round(fy / fsh * foh));
352 vc.image->getPixelRGBA(x, y, &r, &g, &b, &a); 352 }
353 // instance is hit with mouse if not totally transparent 353 vc.image->getPixelRGBA(x, y, &r, &g, &b, &a);
354 if (a != 0) { 354 // instance is hit with mouse if not totally transparent
355 instances.push_back(i); 355 if (a != 0) {
356 goto found_non_transparent_pixel; 356 instances.push_back(i);
357 goto found_non_transparent_pixel;
358 }
357 } 359 }
358 } 360 }
359 } 361 }
360 found_non_transparent_pixel:; 362 found_non_transparent_pixel:;
361 } 363 }