本文整理汇总了C++中tdogl::Camera::offsetPosition方法的典型用法代码示例。如果您正苦于以下问题:C++ Camera::offsetPosition方法的具体用法?C++ Camera::offsetPosition怎么用?C++ Camera::offsetPosition使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tdogl::Camera
的用法示例。
在下文中一共展示了Camera::offsetPosition方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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);
}