本文整理汇总了C++中tdogl::Camera::offsetOrientation方法的典型用法代码示例。如果您正苦于以下问题:C++ Camera::offsetOrientation方法的具体用法?C++ Camera::offsetOrientation怎么用?C++ Camera::offsetOrientation使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tdogl::Camera
的用法示例。
在下文中一共展示了Camera::offsetOrientation方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Update
void Update(float secondsElapsed, GLFWwindow* window) {
const GLfloat degreesPerSecond = 180.0f;
//const GLfloat degreesPerSecond = 0.0f;
gDegreesRotated += secondsElapsed * degreesPerSecond;
while (gDegreesRotated > 360.0f) gDegreesRotated -= 360.0f;
gInstances.front().transform = glm::rotate(glm::mat4(), gDegreesRotated, glm::vec3(0, 1, 0));
//move position of camera based on WASD keys
const float moveSpeed = 4.0; //units per second
if (glfwGetKey(window, 'S')) {
gCamera.offsetPosition(secondsElapsed * moveSpeed * -gCamera.forward());
}
else if (glfwGetKey(window, 'W')) {
gCamera.offsetPosition(secondsElapsed * moveSpeed * gCamera.forward());
}
if (glfwGetKey(window, 'A')) {
gCamera.offsetPosition(secondsElapsed * moveSpeed * -gCamera.right());
}
else if (glfwGetKey(window, 'D')) {
gCamera.offsetPosition(secondsElapsed * moveSpeed * gCamera.right());
}
if (glfwGetKey(window, 'Z')) {
gCamera.offsetPosition(secondsElapsed * moveSpeed * -glm::vec3(0, 1, 0));
}
else if (glfwGetKey(window, 'X')) {
gCamera.offsetPosition(secondsElapsed * moveSpeed * glm::vec3(0, 1, 0));
}
//move light
if (glfwGetKey(window, '1'))
gLight.position = gCamera.position();
// change light color
if (glfwGetKey(window, '2'))
gLight.intensities = glm::vec3(1, 0, 0); //red
else if (glfwGetKey(window, '3'))
gLight.intensities = glm::vec3(0, 1, 0); //green
else if (glfwGetKey(window, '4'))
gLight.intensities = glm::vec3(1, 1, 1); //white
//rotate camera based on mouse movement
const float mouseSensitivity = 0.1f;
double mouseX, mouseY;
glfwGetCursorPos(window, &mouseX, &mouseY);
gCamera.offsetOrientation(mouseSensitivity * (float)mouseY, mouseSensitivity * (float)mouseX);
glfwSetCursorPos(window, 0, 0); //reset the mouse, so it doesn't go out of the window
const float zoomSensitivity = -0.2f;
float fieldOfView = gCamera.fieldOfView() + zoomSensitivity * (float)gScrollY;
if (fieldOfView < 5.0f) fieldOfView = 5.0f;
if (fieldOfView > 130.0f) fieldOfView = 130.0f;
gCamera.setFieldOfView(fieldOfView);
gScrollY = 0;
}
示例2: Update
// update the scene based on the time elapsed since last update
static void Update(float secondsElapsed) {
//rotate the first instance in `gInstances`
const GLfloat degreesPerSecond = 180.0f;
gDegreesRotated += secondsElapsed * degreesPerSecond;
while(gDegreesRotated > 360.0f) gDegreesRotated -= 360.0f;
gInstances.front().transform = glm::rotate(glm::mat4(), gDegreesRotated, glm::vec3(0,1,0));
//move position of camera based on WASD keys, and XZ keys for up and down
const float moveSpeed = 4.0; //units per second
if(glfwGetKey('S')){
gCamera.offsetPosition(secondsElapsed * moveSpeed * -gCamera.forward());
} else if(glfwGetKey('W')){
gCamera.offsetPosition(secondsElapsed * moveSpeed * gCamera.forward());
}
if(glfwGetKey('A')){
gCamera.offsetPosition(secondsElapsed * moveSpeed * -gCamera.right());
} else if(glfwGetKey('D')){
gCamera.offsetPosition(secondsElapsed * moveSpeed * gCamera.right());
}
if(glfwGetKey('Z')){
gCamera.offsetPosition(secondsElapsed * moveSpeed * -glm::vec3(0,1,0));
} else if(glfwGetKey('X')){
gCamera.offsetPosition(secondsElapsed * moveSpeed * glm::vec3(0,1,0));
}
//move light
if(glfwGetKey('1'))
gLight.position = gCamera.position();
// change light color
if(glfwGetKey('2'))
gLight.intensities = glm::vec3(1,0,0); //red
else if(glfwGetKey('3'))
gLight.intensities = glm::vec3(0,1,0); //green
else if(glfwGetKey('4'))
gLight.intensities = glm::vec3(1,1,1); //white
//rotate camera based on mouse movement
const float mouseSensitivity = 0.1f;
int mouseX, mouseY;
glfwGetMousePos(&mouseX, &mouseY);
gCamera.offsetOrientation(mouseSensitivity * mouseY, mouseSensitivity * mouseX);
glfwSetMousePos(0, 0); //reset the mouse, so it doesn't go out of the window
//increase or decrease field of view based on mouse wheel
const float zoomSensitivity = -0.2f;
float fieldOfView = gCamera.fieldOfView() + zoomSensitivity * (float)glfwGetMouseWheel();
if(fieldOfView < 5.0f) fieldOfView = 5.0f;
if(fieldOfView > 130.0f) fieldOfView = 130.0f;
gCamera.setFieldOfView(fieldOfView);
glfwSetMouseWheel(0);
}
示例3: Update
// update the scene based on the time elapsed since last update
void Update(float secondsElapsed) {
const GLfloat degreesPerSecond = 180.0f;
gDegreesRotated += secondsElapsed * degreesPerSecond;
while(gDegreesRotated > 360.0f) gDegreesRotated -= 360.0f;
// Move position of camera base on WASD keys
const float moveSpeed = 3.0; // Units per second;
if(glfwGetKey(gWindow, 'S'))
{
gCamera.offsetPosition(secondsElapsed * moveSpeed * -gCamera.forward());
}else if(glfwGetKey(gWindow, 'W'))
{
gCamera.offsetPosition(secondsElapsed * moveSpeed * gCamera.forward());
}
if(glfwGetKey(gWindow, 'A'))
{
gCamera.offsetPosition(secondsElapsed * moveSpeed * gCamera.right());
}else if(glfwGetKey(gWindow, 'D'))
{
gCamera.offsetPosition(secondsElapsed * moveSpeed * -gCamera.right());
}
if(glfwGetKey(gWindow, 'Z'))
{
gCamera.offsetPosition(secondsElapsed * moveSpeed * -gCamera.up());
}else if(glfwGetKey(gWindow, 'X'))
{
gCamera.offsetPosition(secondsElapsed * moveSpeed * gCamera.up());
}
//rotate camera based on mouse movement
const float mouseSensitivity = 0.1f;
double mouseX, mouseY;
glfwGetCursorPos(gWindow, &mouseX, &mouseY);
gCamera.offsetOrientation(mouseSensitivity * (float)mouseY, mouseSensitivity * (float)mouseX);
glfwSetCursorPos(gWindow, 0, 0); //reset the mouse, so it doesn't go out of the window
//increase or decrease field of view based on mouse wheel
const float zoomSensitivity = -0.2f;
float fieldOfView = gCamera.fieldOfView() + zoomSensitivity * (float)gScrollY;
if(fieldOfView < 5.0f) fieldOfView = 5.0f;
if(fieldOfView > 130.0f) fieldOfView = 130.0f;
gCamera.setFieldOfView(fieldOfView);
gScrollY = 0;
}
示例4: Update
// update the scene based on the time elapsed since last update
static void Update(float secondsElapsed) {
//rotate the first instance in `gInstances`
const GLfloat degreesPerSecond = 180.0f;
gDegreesRotated += secondsElapsed * degreesPerSecond;
while(gDegreesRotated > 360.0f) gDegreesRotated -= 360.0f;
gInstances.front().transform = glm::rotate(glm::mat4(), glm::radians(gDegreesRotated), glm::vec3(0,1,0));
//move position of camera based on WASD keys, and XZ keys for up and down
const float moveSpeed = 2.0; //units per second
if(glfwGetKey(gWindow, 'S')){
gCamera.offsetPosition(secondsElapsed * moveSpeed * -gCamera.forward());
} else if(glfwGetKey(gWindow, 'W')){
gCamera.offsetPosition(secondsElapsed * moveSpeed * gCamera.forward());
}
if(glfwGetKey(gWindow, 'A')){
gCamera.offsetPosition(secondsElapsed * moveSpeed * -gCamera.right());
} else if(glfwGetKey(gWindow, 'D')){
gCamera.offsetPosition(secondsElapsed * moveSpeed * gCamera.right());
}
if(glfwGetKey(gWindow, 'Z')){
gCamera.offsetPosition(secondsElapsed * moveSpeed * -glm::vec3(0,1,0));
} else if(glfwGetKey(gWindow, 'X')){
gCamera.offsetPosition(secondsElapsed * moveSpeed * glm::vec3(0,1,0));
}
//rotate camera based on mouse movement
const float mouseSensitivity = 0.1f;
double mouseX, mouseY;
glfwGetCursorPos(gWindow, &mouseX, &mouseY);
gCamera.offsetOrientation(mouseSensitivity * (float)mouseY, mouseSensitivity * (float)mouseX);
glfwSetCursorPos(gWindow, 0, 0); //reset the mouse, so it doesn't go out of the window
//increase or decrease field of view based on mouse wheel
const float zoomSensitivity = -0.2f;
float fieldOfView = gCamera.fieldOfView() + zoomSensitivity * (float)gScrollY;
if(fieldOfView < 5.0f) fieldOfView = 5.0f;
if(fieldOfView > 130.0f) fieldOfView = 130.0f;
gCamera.setFieldOfView(fieldOfView);
gScrollY = 0;
}
示例5: Update
// update the scene based on the time elapsed since last update
void Update(float secondsElapsed) {
//rotate the cube
const GLfloat degreesPerSecond = 180.0f;
gDegreesRotated += secondsElapsed * degreesPerSecond;
while(gDegreesRotated > 360.0f) gDegreesRotated -= 360.0f;
//move position of camera based on WASD keys, and XZ keys for up and down
const float moveSpeed = 2.0; //units per second
if(glfwGetKey('S')){
gCamera.offsetPosition(secondsElapsed * moveSpeed * -gCamera.forward());
} else if(glfwGetKey('W')){
gCamera.offsetPosition(secondsElapsed * moveSpeed * gCamera.forward());
}
if(glfwGetKey('A')){
gCamera.offsetPosition(secondsElapsed * moveSpeed * -gCamera.right());
} else if(glfwGetKey('D')){
gCamera.offsetPosition(secondsElapsed * moveSpeed * gCamera.right());
}
if(glfwGetKey('Z')){
gCamera.offsetPosition(secondsElapsed * moveSpeed * -glm::vec3(0,1,0));
} else if(glfwGetKey('X')){
gCamera.offsetPosition(secondsElapsed * moveSpeed * glm::vec3(0,1,0));
}
//rotate camera based on mouse movement
const float mouseSensitivity = 0.1;
int mouseX, mouseY;
glfwGetMousePos(&mouseX, &mouseY);
gCamera.offsetOrientation(mouseSensitivity * mouseY, mouseSensitivity * mouseX);
glfwSetMousePos(0, 0); //reset the mouse, so it doesn't go out of the window
//increase or decrease field of view based on mouse wheel
const float zoomSensitivity = -0.2;
float fieldOfView = gCamera.fieldOfView() + zoomSensitivity * (float)glfwGetMouseWheel();
if(fieldOfView < 5.0f) fieldOfView = 5.0f;
if(fieldOfView > 130.0f) fieldOfView = 130.0f;
gCamera.setFieldOfView(fieldOfView);
glfwSetMouseWheel(0);
}
示例6: Update
//rotated and add keyboard and mouse callback
void Update(float secondsElapsed) {
//change the axis that rotated
if (glfwGetKey('7')){
Axis =glm::vec3(1,0,0);
}
if (glfwGetKey('8')){
Axis =glm::vec3(0,0,1);
}
if (glfwGetKey('9')){
Axis =glm::vec3(0,1,0);
}
//press "T" to stop rotate
GLfloat degreesPerSecond = 20.0f;
if (glfwGetKey('T')){
degreesPerSecond = 0.0f;
}
gDegreesRotated += secondsElapsed * degreesPerSecond;
while (gDegreesRotated > 360.0f) gDegreesRotated -= 360.0f;
const float moveSpeed = 3.0;
if (glfwGetKey('S')) {
gCamera.offsetPositon(secondsElapsed * moveSpeed * -gCamera.forward());
} else if (glfwGetKey('W')){
gCamera.offsetPositon(secondsElapsed * moveSpeed * gCamera.forward());
} else if (glfwGetKey('A')) {
gCamera.offsetPositon(secondsElapsed * moveSpeed * -gCamera.right());
} else if (glfwGetKey('D')) {
gCamera.offsetPositon(secondsElapsed * moveSpeed * gCamera.right());
}
if (glfwGetKey('Z')) {
gCamera.offsetPositon(secondsElapsed* moveSpeed * -glm::vec3(0,1,0));
} else if (glfwGetKey('X')) {
gCamera.offsetPositon(secondsElapsed * moveSpeed * glm::vec3(0,1,0));
}
// change light color
if(glfwGetKey('1'))
gLight.intensities = glm::vec3(0.8, 0.3, 0.0); //red
else if(glfwGetKey('2'))
gLight.intensities = glm::vec3(0.0, 0.8, 0.2); //green
else if (glfwGetKey('3'))
gLight.intensities = glm::vec3(0.1, 0.3, 0.8);
else if(glfwGetKey('4'))
gLight.intensities = glm::vec3(1,1,1); //white
//mouse movement with camera
const float mouseSensitivity = 0.1;
int mouseX, mouseY;
glfwGetMousePos(&mouseX, &mouseY);
gCamera.offsetOrientation(mouseSensitivity* mouseY, mouseSensitivity* mouseX);
glfwSetMousePos(0,0);
//mouse wheel with field of view
const float zoomSensitivity = -0.8;
float fieldOfView = gCamera.fieldOfView() + zoomSensitivity *(float)glfwGetMouseWheel();
if(fieldOfView < 5.0f) fieldOfView = 5.0f;
if(fieldOfView > 130.0f) fieldOfView = 130.0f;
gCamera.setFieldOfView(fieldOfView);
if (glfwGetMouseButton(0)) //press left button to reset the Fov;
gCamera.setFieldOfView(50.0f);
glfwSetMouseWheel(0);
}
示例7: main
int main(void)
{
GLFWwindow* window;
/* Initialize the library */
if (!glfwInit())
return -1;
/* Create a windowed mode window and its OpenGL context */
window = glfwCreateWindow(800, 600, "Hello World", NULL, NULL);
if (!window)
{
glfwTerminate();
return -1;
}
glfwSetScrollCallback(window, OnScroll);
// GLFW settings
glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_DISABLED);
glfwSetCursorPos(window, 0, 0);
/* Make the window's context current */
glfwMakeContextCurrent(window);
if (glewInit() != GLEW_OK)
{
glfwTerminate();
return -1;
}
// print out some info about the graphics drivers
std::cout << "OpenGL version: " << glGetString(GL_VERSION) << std::endl;
std::cout << "GLSL version: " << glGetString(GL_SHADING_LANGUAGE_VERSION) << std::endl;
std::cout << "Vendor: " << glGetString(GL_VENDOR) << std::endl;
std::cout << "Renderer: " << glGetString(GL_RENDERER) << std::endl;
// OpenGL settings
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LESS);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
LoadWoodenCrateAsset();
CreateInstances();
//glClearColor(0.196078431372549f, 0.3137254901960784f, 0.5882352941176471f, 1);
glClearColor(0.0f, 0.0f, 0.0f, 1);
gCamera.setPosition(glm::vec3(3.8, 1, 11));
gCamera.offsetOrientation(10, 0);
gCamera.setViewportAspectRatio(800.0f / 600.0f);
gCamera.setNearAndFarPlanes(0.5f, 100.0f);
double lastTime = glfwGetTime();
while (!glfwWindowShouldClose(window))
{
/* Poll for and process events */
glfwPollEvents();
double thisTime = glfwGetTime();
Update((float)(thisTime - lastTime), window);
lastTime = thisTime;
Render(window);
// check for errors
GLenum error = glGetError();
if (error != GL_NO_ERROR)
std::cerr << "OpenGL Error " << error << std::endl;
//exit program if escape key is pressed
if (glfwGetKey(window, GLFW_KEY_ESCAPE))
glfwSetWindowShouldClose(window, GL_TRUE);
}
glfwTerminate();
return 0;
}