View Full Version : how to move view

q13918

07-30-2014, 12:53 PM

Hello,

I am open gl beginner , first day to learn about it.

i have been using google for few hours to find out command for view adjusting but no help so far.

I have c++ glew3 installed and it works ,however i would like to change view point or camera so keypress could change values around but how to connect it to opengl view?

Moving left right and up down would be enough

q13918

07-31-2014, 02:00 AM

It appears there is command glViewport(0, 0, width, height); and that allows to change position of all objects in single line.

Is there a webpage where i could learn opengl coding commands ?

I have only glfw3 library but i find it vary hard to google materials.

What command is needed to move further and closer?

Agent D

07-31-2014, 02:42 AM

this should be a good starting point (http://www.opengl-tutorial.org/)

I recomend to also read up on at least some basics of linear algebra

In OpenGL(R), there is no such thing as a camera. Instead of "moving the camera" you "move the world" which is basically the same thing.

Primitives (triangles, points and lines) are defined by vertices (the corner points) in homogenous coordinates (an additional scaling component at

the end of the vector).

Towards the end of the rendering pipeline, the homogenous coordinates are "converted" to cartesian coordinates (divide through the 4th component).

Everything that is inside a unit-sized cube is "flattened" onto the 2D screen drawing area. The viewport command only regulates the mapping

of unit cube XY coordinates to screen XY coordinates.

Typically you want to work with 3 coordinate systems in your applications:

A model coordinate system. Each 3D model has its own. The origin is typically the center of the model.

A world coordinate system. It has a global origin. All models are positionend and rotated relative to this.

A view coordinate system. The origin is a fictional camera, which (typically) looks down the negative Z axis of this coordinate system.

This effect can be achieved solely by vector-matrix multiplication:

The vertex positions are defined in model coordinates. A transformation matrix can transform them to points in world coordinates.

The world coordinates can be transformed to view coordinates by yet another transformation matrix

Perspective projection can be achieved by using another special transformation matrix, combined with division of the 4th component of the resulting positions.

And at the end of the day, it all ends up in a unit cube and gets flattened onto the screen. No concept of a camera needed.

Typically, the model-to-world and world-to-view matrices are combined to a single model-view matrix.

q13918

07-31-2014, 04:00 AM

Thanks , i understand opengl better today , it draws shapes based on specs for every frame , there is no 3d, all is drawn in 2d and complex math in gpu gives effect of depth.

glScalef(z1, z1, 0); appears to do zoom aligned to center

Agent D

07-31-2014, 06:22 AM

The screen is a 2D surface and shapes drawn on the screen are inherently two dimensional. Everything else is in 3 dimension!

Your model data is 3D, your scene is 3D the operations performed on the data (translation, rotation, scale, etc...) happen in three dimensions.

glScalef(z1, z1, 0) does not perform "zoom" (unless you only draw 2D stuff). It generates a matrix that scales vectors multiplied with it. Setting the third component to 0 will result in a matrix that throws away the third dimension, flattening your geometry into a plane. Please start reading on the tutorial link I gave you, it should explain everything in the first few chapters. (http://www.opengl-tutorial.org/)

q13918

07-31-2014, 10:52 AM

Thanks for additional info , i thought every frame needs to be redrawn based on location,angles and draw happens on 2d with objects angled by gpu to give 3d effect.

I am trying to make graph on opengl that displays bar and line chart.

Does opengl have some sort of matrix system with cordinates or i have to do all drawing on axes +-1 and increase offset to draw next bar?

for example 1600 resoultion window 0.0012499 appears to be good offset to separate 1pixel bars if i divide 2/1600 0.00125 is correct but that causes empty pixels between.

if i draw 1600 1pixel vertical lines from -1 to +1 with 0.0012499 offset then 1600 pixel is empty but no spaces between others.

if i draw 1600 1pixel vertical lines from -1 to +1 with 0.00125 offset then many free space between bars and gpu wont align to correct pixels.

Is this right way to align bars for chart so pixels get correct positions?

this is simple draw on 1600x800 window that draws all lines next to eachother but one line gets overdrawn and missing if 0.00125 then many missing.

par1 = 0;

for (int i = 0; i < 1600; i++){

glBegin(GL_LINES);

glColor3f(1.0f, 0.0f, 0.0f);

glVertex2f(-1.f+par1, high);

glVertex2f(-1.f+par1, low);

glEnd();

axis1 = (2/resolution)+pixelroom;

par1 += 0.0012499; // 2/1600 = 0.00125 to move bars right and all screen is it correct way to align to pixels?

counter += 1;

}

Sorry for my english.

Powered by vBulletin® Version 4.2.3 Copyright © 2018 vBulletin Solutions, Inc. All rights reserved.