hi all,
I’m going to view 3d points in my view.
The problem is that is the curve is too small.
I want this view to be moved to the middle and make it bigger/zoom.
Can anybody plz help me with this.
#include <GL/glew.h>
#include <GLFW/glfw3.h>
#include <iostream>
#define SCREEN_WIDTH 1064
#define SCREEN_HEIGHT 780
void keyCallback(GLFWwindow* window, int key, int scancode, int action, int mods);
GLfloat rotationX = 0.0f;
GLfloat rotationY = 0.0f;
int main(void)
{
GLFWwindow* window;
// Initialize the library
if (!glfwInit())
{
return -1;
}
// Create a windowed mode window and its OpenGL context
window = glfwCreateWindow(SCREEN_WIDTH, SCREEN_HEIGHT, "Hello World", NULL, NULL);
glfwSetKeyCallback(window, keyCallback);
glfwSetInputMode(window, GLFW_STICKY_KEYS, 1);
int screenWidth, screenHeight;
glfwGetFramebufferSize(window, &screenWidth, &screenHeight);
if (!window)
{
glfwTerminate();
return -1;
}
// Make the window's context current
glfwMakeContextCurrent(window);
glViewport(0.0f, 0.0f, SCREEN_WIDTH, SCREEN_HEIGHT); // specifies the part of the window to which OpenGL will draw (in pixels), convert from normalised to pixels
glMatrixMode(GL_PROJECTION); // projection matrix defines the properties of the camera that views the objects in the world coordinate frame. Here you typically set the zoom factor, aspect ratio and the near and far clipping planes
glLoadIdentity(); // replace the current matrix with the identity matrix and starts us a fresh because matrix transforms such as glOrpho and glRotate cumulate, basically puts us at (0, 0, 0)
glOrtho(0, SCREEN_WIDTH, 0, SCREEN_HEIGHT, 0, 1000); // essentially set coordinate system
glMatrixMode(GL_MODELVIEW); // (default matrix mode) modelview matrix defines how your objects are transformed (meaning translation, rotation and scaling) in your world
glLoadIdentity(); // same as above comment
GLfloat halfScreenWidth = SCREEN_WIDTH / 2;
GLfloat halfScreenHeight = SCREEN_HEIGHT / 2;
GLfloat lineVertices[] =
{
0.880204 , 60.1862 , 4.91689,
0.966022 , 60.1704 ,4.72757,
1.03989 , 60.1549 , 4.53326,
1.10158 , 60.1399 , 4.33471,
1.15083 , 60.1254 , 4.13268,
1.18746 , 60.1115 , 3.92793,
1.21133 , 60.0985 , 3.72125,
1.22234 , 60.0863 , 3.51345,
1.22047 , 60.0751 , 3.3053,
1.2057 , 60.0648 , 3.09763,
1.1781 , 60.0554 , 2.89122,
1.13777 , 60.0471 , 2.68687,
1.08487 , 60.0398 , 2.48537,
1.01959 , 60.0334 , 2.2875,
};
// Loop until the user closes the window
while (!glfwWindowShouldClose(window))
{
glClear(GL_COLOR_BUFFER_BIT);
glPushMatrix();
//glTranslatef(halfScreenWidth, halfScreenHeight, -500);
glRotatef(rotationX, 1, 0, 0);
glRotatef(rotationY, 0, 1, 0);
//glTranslatef(-halfScreenWidth, -halfScreenHeight, 500);
glPointSize(1000);
glEnableClientState(GL_VERTEX_ARRAY);
glVertexPointer(3, GL_FLOAT, 0, lineVertices);
glDrawArrays(GL_LINE_STRIP, 0, 49);
glDisableClientState(GL_VERTEX_ARRAY);
glPopMatrix();
// Swap front and back buffers
glfwSwapBuffers(window);
// Poll for and process events
glfwPollEvents();
}
glfwTerminate();
return 0;
}
void keyCallback(GLFWwindow* window, int key, int scancode, int action, int mods)
{
std::cout << key << std::endl;
const GLfloat rotationSpeed = 10;
// actions are GLFW_PRESS, GLFW_RELEASE or GLFW_REPEAT
if (action == GLFW_PRESS || action == GLFW_REPEAT)
{
switch (key)
{
case GLFW_KEY_UP:
rotationX -= rotationSpeed;
break;
case GLFW_KEY_DOWN:
rotationX += rotationSpeed;
break;
case GLFW_KEY_RIGHT:
rotationY += rotationSpeed;
break;
case GLFW_KEY_LEFT:
rotationY -= rotationSpeed;
break;
}
}
}
There are 49 points