本文整理汇总了C++中Locator::get3DPoint方法的典型用法代码示例。如果您正苦于以下问题:C++ Locator::get3DPoint方法的具体用法?C++ Locator::get3DPoint怎么用?C++ Locator::get3DPoint使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Locator
的用法示例。
在下文中一共展示了Locator::get3DPoint方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
//.........这里部分代码省略.........
0.5f, -0.5f, 0.5f,
-0.5f, -0.5f, 0.5f,
-0.5f, -0.5f, -0.5f,
-0.5f, 0.5f, -0.5f,
0.5f, 0.5f, -0.5f,
0.5f, 0.5f, 0.5f,
0.5f, 0.5f, 0.5f,
-0.5f, 0.5f, 0.5f,
-0.5f, 0.5f, -0.5f,
};
GLuint VBO, VAO;
glGenVertexArrays(1, &VAO);
glGenBuffers(1, &VBO);
glBindVertexArray(VAO);
glBindBuffer(GL_ARRAY_BUFFER, VBO);
glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);
// Position attribute
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 3 * sizeof(GLfloat), (GLvoid*)0);
glEnableVertexAttribArray(0);
glBindVertexArray(0); // Unbind VAO
// Game loop
while (!glfwWindowShouldClose(window))
{
vector<double> point = loc.get3DPoint();
if (true){
cout << "(" << point[0] << " , " << point[1] << " , " << point[2] << ")" << endl;
GLfloat xScale = -(point[0]) / 50;
GLfloat yScale = -(point[1]) / 50;
GLfloat zScale = (800-(point[2])) / 50 ;
//inputPos = camera.Position + (xScale * camera.Right)
inputPos = camera.Position + (zScale*camera.Front) + (xScale * camera.Right) - (yScale * camera.Up);
}
else{
inputPos = glm::vec3(0.0f, 0.0f, 0.0f);
}
GLfloat currentFrame = glfwGetTime();
deltaTime = currentFrame - lastFrame;
lastFrame = currentFrame;
// Check if any events have been activiated (key pressed, mouse moved etc.) and call corresponding response functions
glfwPollEvents();
Do_Movement();
// Render
// Clear the colorbuffer
glClearColor(0.2f, 0.3f, 0.3f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
// Activate shader
ourShader.Use();
// Create transformations
glm::mat4 model;
glm::mat4 view;
glm::mat4 projection;
model = glm::translate(model, inputPos);
view = camera.GetViewMatrix();
// Note: currently we set the projection matrix each frame, but since the projection matrix rarely changes it's often best practice to set it outside the main loop only once.
projection = glm::perspective(45.0f, (GLfloat)WIDTH / (GLfloat)HEIGHT, 0.1f, 100.0f);
// Get their uniform location
GLint modelLoc = glGetUniformLocation(ourShader.Program, "model");
GLint viewLoc = glGetUniformLocation(ourShader.Program, "view");
GLint projLoc = glGetUniformLocation(ourShader.Program, "projection");
// Pass them to the shaders
glUniformMatrix4fv(modelLoc, 1, GL_FALSE, glm::value_ptr(model));
glUniformMatrix4fv(viewLoc, 1, GL_FALSE, glm::value_ptr(view));
glUniformMatrix4fv(projLoc, 1, GL_FALSE, glm::value_ptr(projection));
// Draw container
glBindVertexArray(VAO);
glDrawArrays(GL_TRIANGLES, 0, 36);
glBindVertexArray(0);
// Swap the screen buffers
glfwSwapBuffers(window);
}
// Properly de-allocate all resources once they've outlived their purpose
glDeleteVertexArrays(1, &VAO);
glDeleteBuffers(1, &VBO);
// Terminate GLFW, clearing any resources allocated by GLFW.
glfwTerminate();
return 0;
}
示例2: main
int main() {
/*namedWindow("Left Camera", WINDOW_AUTOSIZE);
namedWindow("Right Camera", WINDOW_AUTOSIZE);
int cam1 = -1;
int cam2 = -1;
vector<vector<int>> perms;
int numCams = 0;
for (int i = 0;; i++) {
VideoCapture cam(i);
if (cam.isOpened()) {
numCams++;
}
else {
break;
}
}
for (int i = 0; i < numCams - 1; i++) {
for (int j = i + 1; j < numCams; j++) {
vector<int> v1 = { i, j };
vector<int> v2 = { j, i };
perms.push_back(v1);
perms.push_back(v2);
}
}
for (int i = 0; cam1 < 0 || cam2 < 0; i++) {
if (i = perms.size) {
i = 0;
}
Mat img1;
Mat img2;
VideoCapture cam1(perms[i][0]);
VideoCapture cam2(perms[i][1]);
int key = -1;
while (waitKey(0)) {
cam1.read(img1);
cam2.read(img2);
imshow("Left Camera", img1);
imshow("Right Camera", img2)
}
}*/
RECT desktop;
const HWND hDesktop = GetDesktopWindow();
int width = 0;
int height = 0;
GetWindowRect(hDesktop, &desktop);
width = (int)desktop.right;
int adjustedWidth = (int)(width*1.5);
height = (int)desktop.bottom;
int adjustedHeight = (int)(height*1.5);
Locator locator = Locator();
int screenx = 0;
int screeny = 0;
vector<vector<double>> frames;
bool click = false;
int i=0;
bool makeMove = true;
while (true) {
vector<double> point = locator.get3DPoint();
//cout << "(" << point[0] << " , " << point[1] << " , " << point[2] << ")" << endl;
double xwidth = 2 * (point[2] - 164.75) * tan(28.35 / 180 * PI);
double ywidth = 1.2 * point[2] * tan(34 * PI / 180);
double zDiff = 0;
if (frames.size()==10){
zDiff = frames[0][2] - frames[9][2];
}
if (((point[0] == 0 && point[1] == 0 && point[2] == 0)||zDiff>=50)&&i>10) {
if (!frames.empty()){
if (!click){
click = true;
if (makeMove) {
leftclick(frames[0][0], frames[0][1]);
}
i = 0;
}
}
}
else{
if (click){
click = false;
}
screenx = (int)(((1 - (point[0] + xwidth / 2) / xwidth)* adjustedWidth) - adjustedWidth*.25);
screeny = (int)(((1 - (point[1] + ywidth / 2) / ywidth) * adjustedHeight) - adjustedHeight*.25);
//cout << "(" << screenx << " , " << screeny << ")" << endl;
if (makeMove) {
SetCursorPos(screenx, screeny);
}
//.........这里部分代码省略.........