Value of GLM Vector in setup() not the same in update()


I am not quite sure what I am doing wrong here. I am initializing some GLM vectors in my header file, setting values to them in my setup() function, and adding them together in my update() function. But when I log the vector’s x value at the start of the update function, it goes to zero.


vec2 location, velocity;


#include "ofApp.h"

void ofApp::setup(){
	vec2 location(100, 100);
	vec2 velocity(2.5, 5);
	ofLogNotice() << location.x << endl;


void ofApp::update(){
	ofLogNotice() << location.x << endl;

	location = location + velocity;

	if ((location.x > ofGetWidth()) || (location.x < 0)) {
		velocity.x = velocity.x * -1;
	if ((location.y > ofGetHeight()) || (location.y < 0)) {
		velocity.y = velocity.y * -1;


void ofApp::draw(){
	ofDrawCircle(location.x, location.y, 16, 16);

I would like the location vector to keep adding the velocity vector to make the location of the circle move. The console returns 100 for the log notice in the setup() but 0 for the location as a result of the update function. Why is this not working? Thanks

Well, in this case you a declaring another location variable in the scope of the setup function.

vec2 location(100, 100); //declares a variable
It should be an assignment instead
location = vec2(100,100);

1 Like


yes it works now, thanks for your speedy reply!