Hello,
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.
ofApp.h
vec2 location, velocity;
ofApp.cpp
#include "ofApp.h"
//--------------------------------------------------------------
void ofApp::setup(){
ofLogToConsole();
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(){
ofSetColor(ofColor::black);
ofFill();
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