Using mouse position to control light

Hi all,

I am working on building a 3D scene and was wondering if there is a way to use mouseposition to change the lighting’s colour?

Many thanks

Inside ofApp::update(), you could for instance map the mouse position in x (or y) to a color value, and set the ambient color of your light to that color.

int r = ofMap(ofGetMouseX(), 0.0, ofGetWidth(), 0, 255);
int g = ofMap(ofGetMouseX(), 0.0, ofGetHeight(), 0, 255);
int b = (int)ofRandom(0, 255);
light.setAmbientColor(ofColor(r, g, b));

Hi,

At ofBaseApp, variable mouseX and mouseY contain information about the current x and y coordinates of the mouse.

Then you can use the coords to create a RGB or HSV value as you want.

awesome thanks! I’ll give these a go