void JvCamera::render(JvSprite* ObjectP) { if (checkInCamera(ObjectP)) { CCSprite* pixels = ObjectP->getPixels(); if (pixels == NULL) return; unsigned int rx = ObjectP->getCaf()*ObjectP->frameWidth; unsigned int ry = 0; // printf("%d\n",rx); unsigned int w = (unsigned int)pixels->getTexture()->getContentSize().width; if(rx >= w) { ry = (unsigned int)(rx/w)*ObjectP->frameHeight; rx %= w; } DRAWVH drawvh = NGE_FLIP_NONE; if(ObjectP->facing==FACELEFT) { drawvh=NGE_FLIP_H; } else if (ObjectP->facing==FACEDOWN) { drawvh=NGE_FLIP_V; } else if (ObjectP->facing==FACELEFT && ObjectP->facing==FACEDOWN) { drawvh=NGE_FLIP_HV; } JvPoint objPoint(ObjectP->x,ObjectP->y); JvPoint spoint = toScreenPoint(objPoint); spoint.x = (ObjectP->scrollFactor.x==0)?ObjectP->x:(ObjectP->scrollFactor.x*spoint.x); spoint.y = (ObjectP->scrollFactor.y==0)?ObjectP->y:(ObjectP->scrollFactor.y*spoint.y); int drawmask = ObjectP->getMask(); draw(pixels,rx,ry,ObjectP->frameWidth,ObjectP->frameHeight, spoint.x-ObjectP->offset.x,spoint.y-ObjectP->offset.y,ObjectP->getScale(),ObjectP->getScale(), ObjectP->angle,drawvh,drawmask); // RenderQuad(pixels,rx,ry,ObjectP->frameWidth,ObjectP->frameHeight, // spoint.x-ObjectP->offset.x,spoint.y-ObjectP->offset.y,ObjectP->getScale(),ObjectP->getScale(), // ObjectP->angle,drawmask); } }
bool SceneObject::containsPoint( const Point3F& point ) { // If it's not in the AABB, then it can't be in the OBB either, // so early out. if( !mWorldBox.isContained( point ) ) return false; // Transform point into object space and test it against // our object space bounding box. Point3F objPoint( 0, 0, 0 ); getWorldTransform().mulP( point, &objPoint ); objPoint.convolveInverse( getScale() ); return ( mObjBox.isContained( objPoint ) ); }
bool JvCamera::checkInCamera(JvObject* ObjectP) { JvPoint objPoint(ObjectP->x,ObjectP->y); JvPoint spoint = toScreenPoint(objPoint); spoint.x *= ObjectP->scrollFactor.x; spoint.y *= ObjectP->scrollFactor.y; if ( spoint.x + ObjectP->width<0 || spoint.x > width || spoint.y > height || spoint.y + ObjectP->height < 0 ) { return false; } return true; }
void Input::computeProjectionMat() { if (m_outImg3d.empty()) throw Exception("3d image invalid"); std::vector<std::vector<float> > objPoints; std::vector<std::vector<float> > imgPoints; int count = 6; // create point correspondences with random points objPoints.reserve(count); imgPoints.reserve(count); int maxNumIters = count * 20; int numIters = 0; do { if (numIters > maxNumIters) throw Exception("could not compute projection matrix"); numIters++; float val1 = rand() / (float)RAND_MAX; float val2 = rand() / (float)RAND_MAX; int x = (int)(val1 * m_outImg3d.cols); int y = (int)(val2 * m_outImg3d.rows); if (x < 0 || x >= m_outImg3d.cols || y < 0 || y >= m_outImg3d.rows) continue; const float* row = m_outImg3d.ptr<float>(y); std::vector<float> imgPoint(3); imgPoint[0] = (float)x; imgPoint[1] = (float)y; imgPoint[2] = 1.0f; std::vector<float> objPoint(4); objPoint[0] = row[x * 3 + 0]; objPoint[1] = row[x * 3 + 1]; objPoint[2] = row[x * 3 + 2]; objPoint[3] = 1.0f; if (objPoint[2] > 0) { objPoints.push_back(objPoint); imgPoints.push_back(imgPoint); } } while ((int)objPoints.size() < count); // reconstruction from given point correspondences // (see http://de.wikipedia.org/wiki/Projektionsmatrix#Berechnung_der_Projektionsmatrix_aus_Punktkorrespondenzen) // create Matrix A cv::Mat matA(2 * count, 12, CV_32FC1); for (int i = 0, j = 0; i < 2 * count; i+=2, j++) { // cols // first row matA.ptr<float>(i)[0] = objPoints[j][0]; matA.ptr<float>(i)[1] = objPoints[j][1]; matA.ptr<float>(i)[2] = objPoints[j][2]; matA.ptr<float>(i)[3] = objPoints[j][3]; matA.ptr<float>(i)[4] = matA.ptr<float>(i)[5] = matA.ptr<float>(i)[6] = matA.ptr<float>(i)[7] = 0; matA.ptr<float>(i)[8] = - imgPoints[j][0] * objPoints[j][0]; matA.ptr<float>(i)[9] = - imgPoints[j][0] * objPoints[j][1]; matA.ptr<float>(i)[10] = - imgPoints[j][0] * objPoints[j][2]; matA.ptr<float>(i)[11] = - imgPoints[j][0] * objPoints[j][3]; // second row matA.ptr<float>(i+1)[0] = matA.ptr<float>(i+1)[1] = matA.ptr<float>(i+1)[2] = matA.ptr<float>(i+1)[3] = 0; matA.ptr<float>(i+1)[4] = objPoints[j][0]; matA.ptr<float>(i+1)[5] = objPoints[j][1]; matA.ptr<float>(i+1)[6] = objPoints[j][2]; matA.ptr<float>(i+1)[7] = objPoints[j][3]; matA.ptr<float>(i+1)[8] = - imgPoints[j][1] * objPoints[j][0]; matA.ptr<float>(i+1)[9] = - imgPoints[j][1] * objPoints[j][1]; matA.ptr<float>(i+1)[10] = - imgPoints[j][1] * objPoints[j][2]; matA.ptr<float>(i+1)[11] = - imgPoints[j][1] * objPoints[j][3]; } // solve using SVD cv::Mat w; cv::Mat u; cv::Mat vt; cv::SVD mySVD; mySVD.compute(matA, w, u, vt); // create matrix m_projMat = cv::Mat(3, 4, CV_32FC1); for (int i = 0; i < vt.rows; i++) { m_projMat.ptr<float>(0)[i] = vt.ptr<float>(vt.cols - 1)[i] / vt.ptr<float>(vt.cols - 1)[vt.rows - 1]; } // normalize projection matrix float sum = m_projMat.ptr<float>(2)[0] + m_projMat.ptr<float>(2)[1] + m_projMat.ptr<float>(2)[2]; m_projMat = m_projMat * (1.0f / sum); // decompose cv::decomposeProjectionMatrix(m_projMat, m_matCamera, m_matRot, m_matTrans); }