Quantcast
Channel: beginners - openFrameworks
Viewing all articles
Browse latest Browse all 4929

Spotlight ofmesh

$
0
0

@Poulp wrote:

Hello,

I'have a strange behavior with a spotlight on an Ofmesh. Indeed, when I orient the spotlight on my mesh only half of the light appears, contrary to an ofPlane. Here is an illustration of my issue (ofMesh on the left / ofPlane on the right).

Thank you very much in advance for your help !

And here is the code

include "ofApp.h"

//--------------------------------------------------------------
void ofApp::setup(){
ofSetFrameRate(60);

int height = 100;
int width = 100;

mesh.disableColors();
for (int y = 0; y < height; y++){
    for (int x = 0; x<width; x++){
        mesh.addVertex(ofPoint(x,0,y)); // make a new vertex
        mesh.addColor(ofFloatColor(0,0,255));  // add a color at that vertex
    }
}

// now it's important to make sure that each vertex is correctly connected with the
// other vertices around it. This is done using indices, which you can set up like so:
for (int y = 0; y<height-1; y++){
    for (int x=0; x<width-1; x++){
        mesh.addIndex(x+y*width);               // 0
        mesh.addIndex((x+1)+y*width);           // 1
        mesh.addIndex(x+(y+1)*width);           // 10

        mesh.addIndex((x+1)+y*width);           // 1
        mesh.addIndex((x+1)+(y+1)*width);       // 11
        mesh.addIndex(x+(y+1)*width);           // 10
    }
}

plane.set(100, 100, 100, 100);
plane.rotate(-90, ofVec3f(1,0,0));
plane.setPosition(150, 0, 50);

}

//--------------------------------------------------------------
void ofApp::update(){

}

//--------------------------------------------------------------
void ofApp::draw(){
ofBackground(230);
spotLight1.setSpotlight();
spotLight2.setSpotlight();


spotLight1.setPosition (50, 20, 50);
spotLight1.lookAt(ofVec3f(50, 0, 50));
spotLight1.setSpotConcentration(0);
spotLight1.setAttenuation(0.1);
spotLight1.setSpotlightCutOff(50);

spotLight2.setPosition(150, 20, 50);
spotLight2.lookAt(ofVec3f(150, 0, 50));
spotLight2.setSpotConcentration(0);
spotLight2.setAttenuation(0.1);
spotLight2.setSpotlightCutOff(50);

spotLight1.enable();
spotLight2.enable();

camera.begin();
ofEnableDepthTest();
ofSetColor(0, 255, 0);
mesh.draw();
plane.draw();
ofDrawAxis(200);
ofDisableDepthTest();
camera.end();

}

Posts: 2

Participants: 1

Read full topic


Viewing all articles
Browse latest Browse all 4929

Trending Articles