int main() { tw::vec3f position(1.0f, 0.0f, -2.0f); tw::vec3f axis(0.0f, 1.0f, 0.0f); float32_t angle = tw::radians(45.0f); tw::vec3f scale(1.0f, 1.0f, 1.0f); tw::mat4f translationMat = tw::translation(position); tw::quatf rotationQuat = tw::rotation(axis, angle); tw::mat4f scalingMat = tw::scaling(scale); tw::mat4f model = translationMat * tw::mat4_cast(rotationQuat) * scalingMat; tw::vec3f cameraPosition(0.0f, 0.0f, 1.0f); tw::vec3f cameraCenter(0.0f, 0.0f, 0.0f); tw::vec3f cameraUp(0.0f, 1.0f, 0.0f); tw::mat4f view = tw::lookAt(cameraPosition, cameraCenter, cameraUp); tw::mat4f mv = view * model; tw::vec4f p(1.0f, 0.0f, 0.0f, 1.0f); p = mv * p; std::cout << p.x << " " << p.y << " " << p.z << " " << p.w << std::endl; std::cin.get(); return 0; }
void Mg3dScene::setCameraCenter(const QVector3D & pos) { if(pos != cameraCenter()) { camera()->setCenter(pos); updateGLContent(); Q_EMIT cameraCenterChanged(pos); } }
int main(int argc, char** argv) { try { int cudaDevice; std::string lsystemFile; int screenWidth; int screenHeight; CmdOptions cmdOptions(argc, argv); cmdOptions.read("device", cudaDevice, 0); cmdOptions.read<std::string>("lsystemFile", lsystemFile, ""); cmdOptions.read("screenWidth", screenWidth, DEFAULT_SCREEN_WIDTH); cmdOptions.read("screenHeight", screenHeight, DEFAULT_SCREEN_HEIGHT); if (lsystemFile == "") { printUsage(); exit(EXIT_FAILURE); } Framework::GLWindow window("LSystem", screenWidth, screenHeight, true, false); if (gl3wInit()) { throw std::runtime_error("gl3wInit() failed"); } cudaDeviceProp deviceProperties; cudaGetDeviceProperties(&deviceProperties, cudaDevice); cudaSetDevice(cudaDevice); LSystem lsystem(lsystemFile); /********************************/ /* CENTER L-SYSTEM ON SCREEN */ /********************************/ float width = lsystem.getBounds().extents().x; float height = lsystem.getBounds().extents().y; float screenDiagonal = sqrt(pow(width, 2) + pow(height, 2) + 1); float distance = min((screenDiagonal / 2.0f) / tan(HALF_FOV_RAD), ZFAR); float aspectRatio = screenWidth / (float)screenHeight; math::float3 cameraCenter(lsystem.getBounds().center().x, lsystem.getBounds().center().y, -distance); math::float3 cameraForward = cameraCenter + math::float3(0, 0, -1); math::float3 cameraUp(0, 1, 0); ////////////////////////////////////////////////////////////////////////// SimpleCamera camera(FOV_RAD, aspectRatio, ZNEAR, ZFAR, cameraCenter, cameraForward, cameraUp); LSystemRenderer renderer(window, lsystem, camera); window.attach(&renderer); FirstPersonCameraNavigator navigator(&camera); LSystemInputHandler inputHandler(renderer, navigator); window.attach(static_cast<Framework::MouseInputHandler*>(&inputHandler)); window.attach(static_cast<Framework::KeyboardInputHandler*>(&inputHandler)); Framework::run(renderer, &inputHandler); return 0; } catch (std::exception& e) { std::cout << "Error: " << e.what() << std::endl; } catch (...) { std::cout << "Unknown error" << std::endl; } // DEBUG: system("pause"); return -1; }