bool Camera::initDefault() { auto size = Director::getInstance()->getWinSize(); //create default camera auto projection = Director::getInstance()->getProjection(); switch (projection) { case Director::Projection::_2D: { initOrthographic(size.width, size.height, -1024, 1024); setPosition3D(Vec3(0.0f, 0.0f, 0.0f)); setRotation3D(Vec3(0.f, 0.f, 0.f)); break; } case Director::Projection::_3D: { float zeye = Director::getInstance()->getZEye(); initPerspective(60, (GLfloat)size.width / size.height, 10, zeye + size.height / 2.0f); Vec3 eye(size.width/2, size.height/2.0f, zeye), center(size.width/2, size.height/2, 0.0f), up(0.0f, 1.0f, 0.0f); setPosition3D(eye); lookAt(center, up); break; } default: CCLOG("unrecognized projection"); break; } return true; }
Camera2D::Camera2D(::lucid::core::Reader &reader) { TYPE type; reader.read(&type, sizeof(TYPE)); if (TYPE_PERSPECTIVE == type) { float32_t fov = read<float32_t>(reader); float32_t aspect = read<float32_t>(reader); float32_t znear = read<float32_t>(reader); float32_t zfar = read<float32_t>(reader); initPerspective(fov, aspect, znear, zfar); } else { float32_t width = read<float32_t>(reader); float32_t height = read<float32_t>(reader); float32_t znear = read<float32_t>(reader); float32_t zfar = read<float32_t>(reader); initOrthographic(width, height, znear, zfar); } ::lucid::gal::Vector3 position = read<::lucid::gal::Vector3>(reader); ::lucid::gal::Vector3 target = read<::lucid::gal::Vector3>(reader); ::lucid::gal::Vector3 up = read<::lucid::gal::Vector3>(reader); look(position, target, up); }
Camera* Camera::createOrthographic(float zoomX, float zoomY, float nearPlane, float farPlane) { auto ret = new (std::nothrow) Camera(); if (ret) { ret->initOrthographic(zoomX, zoomY, nearPlane, farPlane); ret->autorelease(); return ret; } CC_SAFE_DELETE(ret); return nullptr; }