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

Glm perpendicular vector

$
0
0

@edapx wrote:

I need to build a 3d tube primitive from a set of point. For each point I've the position and the direction.
In order to set the normal correctly, i need the vector perpendicular to the direction. Using Vec3f there was getPerpendicular method https://github.com/openframeworks/openFrameworks/blob/master/libs/openFrameworks/math/ofVec3f.h#L1787

What is its equivalent in glm ? I had a look at this documentation https://glm.g-truc.net/0.9.0/api/a00181.html#_details
but it looks not the same thing as it takes 2 vectors as parameters.

Posts: 2

Participants: 1

Read full topic


Converting addon to glm syntax

$
0
0

@edapx wrote:

Hello, I want to use this addon https://github.com/neilmendoza/ofxPtf by @neilmendoza in my project but unfortunately it is not using the new glm syntax. I've started to convert it to glm ( https://github.com/edap/ofxPtf/tree/glm ) and as far as it goes with vectors it is straightforward. The problems arise with matrices because I did not found any documentation about it. I will be happy to add it to this page http://openframeworks.cc/learning/02_graphics/how_to_use_glm/ as soon as I understand it :wink:

My specific question is, what is the equivalent in the new glm of these operations ( r is a float and a is a glm::vec3)?

            ofMatrix4x4 R;
            R.makeRotationMatrix(RAD_TO_DEG * r, a);
            ofMatrix4x4 Tj;
            Tj.makeTranslationMatrix( points.back() );
            ofMatrix4x4 Ti;
            Ti.makeTranslationMatrix( -points[points.size() - 2] );

would be correct something like this ?

auto R = glm::rotation(RAD_TO_DEG * r, a);
auto Tj = glm::translate( points.back() );
auto Ti = glm::translate(  -points[points.size() - 2] );

Posts: 2

Participants: 1

Read full topic

How to orientate the top face of a cylinder to another point

$
0
0

@edapx wrote:

I've to build a tubular structure out of branches. Each branch has a starting position, an end position, a starting direction and an end direction. With this 4 elements I want to draw cylinders connected to each other. Unfortunately, I can not use ofNode like I did here https://forum.openframeworks.cc/t/how-to-draw-a-cylinder-starting-from-2-ofnode/22323 because it turned out to be too slow.

My current problem is to draw a single cylinder, what I would like to have is this:

Where A is startingPos and B is endingPos. B-A is the startingDir and C - B is the the endDir. C is the lookingAt point that the top face should look.

What I'm obtaining now, is this:

As you see, the rotation of the top face happens on an axis that is not what it should be.

To rotate the top face, I use:
the formula:
angle = acos(v1 dot v2)
axis = norm(v1 cross v2)

Therefore:

auto angle = acos(glm::dot(glm::normalize(startDir), glm::normalize(endDir)));
auto axis = glm::normalize(glm::cross(startDir, endDir));
glm::mat4x4 rotMat = glm::axisAngleMatrix(axis, angle);

This is the whole code that I'm using to draw this scene:

#include "ofApp.h"

//--------------------------------------------------------------
void ofApp::setup(){
    //light.enable();
    glm::vec3 startPos = glm::vec3(0.0f,0.0f, 0.0f);
    glm::vec3 endPos = glm::vec3(0.0f, 40.0f, 0.0f);
    lookingAt = glm::vec3(40.0f, 75.0f, 0.0f);
    glm::vec3 startDir = glm::normalize(endPos - startPos);
    glm::vec3 endDir = glm::normalize(lookingAt - endPos);

    createTube(startPos, endPos, startDir, endDir, this->mesh);
}

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

}

//--------------------------------------------------------------
void ofApp::draw(){
    ofEnableDepthTest();
    cam.begin();
    ofSetColor(0,0,0,100);
    mesh.drawWireframe();
    auto n = mesh.getNormals();
    auto v = mesh.getVertices();
    float normalLength = 20.;

    ofSetColor(255,0,0,70);
for(unsigned int i=0; i < n.size() ;i++){
    ofDrawLine(.98*v[i].x,.98*v[i].y,.98*v[i].z,
               .98*v[i].x+n[i].x*normalLength*.2,.98*v[i].y+n[i].y*normalLength*.2,.98*v[i].z+n[i].z*normalLength*.2);

}

ofDrawSphere(lookingAt.x, lookingAt.y, lookingAt.z, 3);

cam.end();
ofDisableDepthTest();
}

void ofApp::createTube(glm::vec3 startPos, glm::vec3 endPos, glm::vec3 startDir, glm::vec3 endDir, ofMesh& mesh){
    bool cap = false;
    int resolution = 6;
    int textureRepeat = 1;
    float length = glm::distance(startPos, endPos);
    const int radius = 8;
    const int scaledRadius = 8;//for now, do not scale the branches;

    auto angle = acos(glm::dot(glm::normalize(startDir), glm::normalize(endDir)));
auto axis = glm::normalize(glm::cross(startDir, endDir));
glm::mat4x4 rotMat = glm::axisAngleMatrix(axis, angle);

// Cylinder body
int first = mesh.getNumVertices();
for (int i = 0; i <= resolution; i++) {
    // if it is the last face, close it where the first face
    // was started
    if (i == resolution) {
        mesh.addIndex(first+(i*2));
        mesh.addIndex(first);
        mesh.addIndex(first+1);

        mesh.addIndex(first+1);
        mesh.addIndex(first+(i*2)+1);
        mesh.addIndex(first+(i*2));
    } else {
        mesh.addIndex(first+(i*2));
        mesh.addIndex(first+(i*2)+2);
        mesh.addIndex(first+(i*2)+3);

        mesh.addIndex(first+(i*2)+3);
        mesh.addIndex(first+(i*2)+1);
        mesh.addIndex(first+(i*2));
    }
}

for (int i = 0; i <= resolution; i++) {
    //calculate x and y component
    float theta = 2.0f * 3.1415926f * float(i) / float(resolution);
    float x = radius * cosf(theta);
    float z = radius * sinf(theta);

    glm::vec3 offset = glm::vec3(x, startPos.y, z);
    glm::vec3 circleBottom = startPos + offset;
    glm::vec3 direction = glm::normalize(circleBottom);

    glm::vec3 circleTop =  glm::vec3(rotMat * glm::vec4((endPos + offset),0.0));
    glm::vec3 directionTop = endDir;

    // bottom
    //botton and top vertices share the same normal
    glm::vec3 normal = glm::normalize(circleBottom-startPos);
    mesh.addVertex(circleBottom);
    mesh.addNormal(normal);

    //top
    mesh.addVertex(circleTop);
    mesh.addNormal(normal);
}
}

Does anyone have some suggestion?

Posts: 1

Participants: 1

Read full topic

Multiplication of two images - best approach?

$
0
0

@Autofasurer wrote:

I'm looking for a way to compare two images, one read from disk and one generated in OFX (using loadScreenData), multiply them and calculate how much 'white' is in the result.
What would be the best approach for this?

e.g.:

Multiplied by:

results in:

Posts: 2

Participants: 2

Read full topic

Qtcreator fails with openframeworks project

$
0
0

@iwkse wrote:

Hi,
I've downloaded latest Qt with Qtcreator included from the online installer. It works just fine when I test the Qt examples provided in the Welcome page, but when I try to create a new openframeworks project, I get such error

warning: /mnt/wdblue/src/of_v0.9.8_linux64_release/libs/openFrameworksCompiled/project/qtcreator/modules/of/helpers.js:5 Cannot open '/mnt/wdblue/src/of_v0.9.8_linux64_release/libs/openFrameworksCompiled/project/qtcreator/modules/of/qbs'.

Actually the file qbs is not available in the of folders, there's only helpers.js and of.qbs.

Could anyone give support?

Thank you and regards

Posts: 1

Participants: 1

Read full topic

Having trouble installing ofxGStreamer - ofGstUtils.cpp not found (partial fix)

$
0
0

@adeler wrote:

I'm having some trouble getting ofxGStreamer to work. I followed arturo's instructions exactly as outlined here: https://github.com/arturoc/ofxGStreamer and then I created a project using the Project Generator and added the ofxGStreamer addon.

When I try to compile the generated project in XCode I get the following error: 'No such file or directory: '/libs/openFrameworks/video/ofGstUtils.cpp'.

Even though if I check this folder: /of_v0.9.8_osx_release/libs/openFrameworks/video/ , ofGstUtils.cpp is right there.

If I navigate to that same folder in the Project navigator on XCode I can also see the ofGstUtils.cpp file under video.

I'm using:
-OSX Sierra 10.12.3
-Open Frameworks 0.9.8
-XCode 8.3.3

Any advice on what to try?

Update: I see some connection to this post, which leads me to think the problem lies with addon_config.mk not setting my addon_sources right. I think it has to do with the fact that $(OF_ROOT) is pointing to something incorrect.

I changed my ../addons/ofxGStreamer/addon_config.mk file and replaced all the $(OF_ROOT) declarations with the full local path to my openframeworks folder (i.e. /Users/user_name/Documents/of_v0.9.8_osx_release/) and it worked. Obviously this is just a solution on my local computer. What would be the right way to fix this more generally?

Posts: 2

Participants: 1

Read full topic

[ofxBox2D] - How to get particle/object position after collision

$
0
0

@kovicic wrote:

Hi folks, I asked this question in the addons page (github), the only response was mine so far.

I am trying to get the particle coordinates to do something if they are between certain boundaries.
The way I am doing it is as follows, I don't know if it's the best way to do it, (it seems to work):

    void testApp::contactStart(ofxBox2dContactArgs &e) {
    	if(e.a != NULL && e.b != NULL) {

    		if(e.a->GetType() == b2Shape::e_edge && e.b->GetType() == b2Shape::e_circle) {

                        //some checks and sentences I do


                         ofVec2f p;

                        const b2Transform& xf = e.b->GetBody()->GetTransform();
                        b2Vec2 pos      = e.b->GetBody()->GetLocalCenter();
                        b2Vec2 b2Center = b2Mul(xf, pos);
                        p = worldPtToscreenPt(b2Center);
                        cout << "p.x " << (int)p.x << " p.y " << (int)p.y << endl;

                        if (p.y < sp->pGround1.y - 25)  // menos restrictivo
                        {
                            bData->bHit = true;
                            sound[bData->soundID].play();
                        }

    			}
    		}
    	}

Thanks for any suggestion, cheers!

Posts: 1

Participants: 1

Read full topic

Issue exporting graphics as a single screenshot to PDF

$
0
0

@celinechappert wrote:

Hello everyone,

I'm trying to export some graphics as a single screenshot to PDF.

The issue is that with my current code I am exporting a single frame of the window at a time (picture 1 below). I would like to export all of the graphics as one single vector file (picture 2 below).

Picture 1 - what I have :

Picture 2 - what I want :

Currently I'm following this tutorial from the oF book and my code looks like this :

I've added bool isSaving to the header (.h) file.

In setup() and draw() :

void ofApp::setup(){

ofSetBackgroundAuto(false); // turns off automatic bg clearing
ofBackground(0);
isSaving = false;
}


void ofApp::draw(){

if (isSaving) {

    ofBeginSaveScreenAsPDF("screenshot_"+ofGetTimestampString()+".pdf");
}

ofNoFill();
ofDrawEllipse(ofGetMouseX(), ofGetMouseY(), 20, 20);

if (isSaving) {
    ofEndSaveScreenAsPDF();
    isSaving = false;
}
}

And finally I've added an event listener :

void ofApp::keyPressed(int key){

if (key == 'c') {
    isSaving = true;
}

My first thought was to switch on/off ofSetBackgroundAuto to see if the background being redrawn or not had an effect on the output and it did not.

I'm a little lost, any ideas ? :confused:

Posts: 17

Participants: 2

Read full topic


I want to change from GLSL 1.2 to GLSL 1.5

$
0
0

@taketori7616 wrote:

I would like to rewrite the code of the following two GLSL 1.2 versions for GLSL 1.5, what should I do?

fragment

#version 120
uniform sampler2DRect image;
uniform float rand;

varying vec3 pos;

void main (void)
{
    vec2 texCoord = vec2(pos.x , pos.y);

    vec4 col = texture2DRect(image,texCoord);
    vec4 col_r = texture2DRect(image,texCoord + vec2(-35.0*rand,0));
    vec4 col_l = texture2DRect(image,texCoord + vec2( 35.0*rand,0));
    vec4 col_g = texture2DRect(image,texCoord + vec2( -7.5*rand,0));


    col.b = col.b + col_r.b*max(1.0,sin(pos.y*1.2)*2.5)*rand;
    col.r = col.r + col_l.r*max(1.0,sin(pos.y*1.2)*2.5)*rand;
    col.g = col.g + col_g.g*max(1.0,sin(pos.y*1.2)*2.5)*rand;

    gl_FragColor.rgba = col.rgba;
}

vertex

#version 120
varying vec3 pos;
void main(void)
{
    pos = gl_Vertex.xyz;
    gl_Position = ftransform();
}

Posts: 1

Participants: 1

Read full topic

Has anyone uploaded an OF app to Windows Store?

$
0
0

@cuinjune wrote:

Hi, I wonder if it is possible to upload an OF app to Windows Store.
Can one upload an OF app targeting both desktops and phones?

Posts: 1

Participants: 1

Read full topic

How to set windowSettings on Android?

$
0
0

@cuinjune wrote:

Hi, I wonder how to set window settings on Android.
For example on iOS, in main.cpp file, I can do it like below.

int main(){
	//  here are the most commonly used iOS window settings.
        //------------------------------------------------------
        ofiOSWindowSettings settings;
        settings.enableRetina = true; // enables retina resolution if the device supports it.
        settings.enableDepth = true; // enables depth buffer for 3d drawing.
        settings.enableAntiAliasing = true; // enables anti-aliasing which smooths out graphics on the screen.
        settings.numOfAntiAliasingSamples = 4; // number of samples used for anti-aliasing.
        settings.enableHardwareOrientation = true; // enables native view orientation.
        settings.enableHardwareOrientationAnimation = true; // enables native orientation changes to be animated.
        settings.glesVersion = OFXIOS_RENDERER_ES1; // type of renderer to use, ES1, ES2, ES3
        settings.windowMode = OF_FULLSCREEN;
        ofCreateWindow(settings);

    	return ofRunApp(new ofApp);
}

I couldn't find any object like "ofAndroidWindowSettings".
So maybe all of these settings should be done somewhere else? (e.g manifest file)
I would appreciate any advice. Thanks!

Posts: 1

Participants: 1

Read full topic

Help with some logic ofSoundPlayer toggle button

$
0
0

@antocreo wrote:

Hello everyone,
I am trying to make a simple app with a button that plays a sequence of mp3.
It should be simple, right. But I am having a strange behaviour and I can't find the problem so I hope someone can help me.

what I am expecting:
the central toggle button (key == spacebar) on active state should activate a sequence of notes (ofSoundPlayers).
what happens:
the sequence starts after I deactivate the toggle.

It is like the toggle is inverted, however it is not...

I am enclosing the source files if anyone has some spare time and wants to have a look.
it shouldn't really be a big problem but I can't see where the code is wrong!

p.s.
I do have some issues with ofSoundPlayer sequence but I'll leave that for later!

I hope someone can make light on this

Cheers!
Archive.zip (1.5 MB)

Posts: 2

Participants: 2

Read full topic

First compilation of an example and lots of issues

$
0
0

@WrWhale wrote:

Hi. I am totally new with oF and for my first compilation, I followed the instructions from this tutorial. After a long building time, I got 292 issues. Is it an acceptable number ? I can still run the program but before getting to work I would like to have a clean build. Even the emptyExample is full of issues.

I am running with openFrameworks v0.9.8, Xcode 8.3.3 and macOS Sierra 10.12.5.


How can I extract a log file from the compilation ? Is there any obvious step that I missed ?

Edit : I added a screenshot for more clarity.
Apparently the issues I'm having are superficial and due to precision loss.

Posts: 2

Participants: 2

Read full topic

Memory junk piling up in FBO, what is really happening?

$
0
0

@celinechappert wrote:

Hi everyone,

I'm currently learning about FBO / how to use it and decided to do a couple tests. In one test, I am drawing to FBO with the mouse and displaying a circle trail. Like in the photo :

So pretty straightforward stuff. Now, to make that work I had to wrap fbo.begin() and fbo.end() around ofClear() in the setup. Like this :

void ofApp::setup(){
fbo.allocate(ofGetWidth(), ofGetHeight(), GL_RGB);
fbo.begin();
ofClear(255, 0, 0);
fbo.end();
}

Otherwise.. I got this crazy things :

So clearly the functions in the setup() clear the buffer. But what are those graphics in the window ? Are they bits of memory stored in the video card ? I'm looking for a simple explanation of what it is I'm seeing or perhaps an insight on how memory and FBO work together.

My code (with ofFbo fbo in the header) :

void ofApp::setup(){
fbo.allocate(ofGetWidth(), ofGetHeight(), GL_RGB);
fbo.begin();
ofClear(255, 0, 0);
fbo.end();
}

void ofApp::draw(){

int x = ofGetMouseX();
int y = ofGetMouseY();

fbo.begin();
ofSetColor(255);
ofNoFill();
ofDrawCircle(x, y, 100);
fbo.end();
fbo.draw(0, 0, ofGetWidth(), ofGetHeight());
}

Many thanks for your help ! :wink:

Posts: 5

Participants: 3

Read full topic

Project Generators

$
0
0

@popa wrote:

After seeing the work of Zach Lieberman of instagram I wanted to learn the program. I started by how I start to learn anything I know nothing about... youtube! I started watching Lewis Lepton's tutorials. He suggested the github client, so I downloaded that and then in the second video, he goes on to show you how to use the project generator but that file wasnt in the folder. I was just wondering how to make a project generator in terms a noob like me will understand.
Thanks
popa

Posts: 3

Participants: 3

Read full topic


Couldn't read shader file on Sierra

$
0
0

@sleepy-maker wrote:

I just trying the same code as shader example 01 and got the following errors.

[ error ] ofShader: setupShaderFromFile(): couldn't load GL_VERTEX_SHADER shader  from "shadersGL3/shader.vert"
[ error ] ofShader: setupShaderFromFile(): couldn't load GL_FRAGMENT_SHADER shader  from "shadersGL3/shader.frag"
[ error ] ofShader: bindDefaults(): trying to link GLSL program, but no shaders created yet
[ error ] ofShader: linkProgram(): trying to link GLSL program, but no shaders created yet

Does anyone know how I can fix this problem.

OS macOS Sierra version 10.12.5
Xcode 8.3

Thanks!

Posts: 1

Participants: 1

Read full topic

ofxThreadedMidiPlayer on windows

$
0
0

@dasoe wrote:

Dear all,

when trying to compile the example of ofxThreadedMidiPlayer on windows 7 VS (I already did comment out the PRETTY_FUNCTION stuff), I get multiple

Severity	Code	Description	Project	File	Line	Suppression State
Error	LNK2005	_main already defined in create_midifile.obj	tryMidiPlayer	C:\Users\coettinger\Documents\of_v0.9.3_vs_release\apps\myApps\tryMidiPlayer\jdksmidi_test_multitrack1.obj	1
Error	LNK2005	_main already defined in create_midifile.obj	tryMidiPlayer	C:\Users\coettinger\Documents\of_v0.9.3_vs_release\apps\myApps\tryMidiPlayer\jdksmidi_test_parse.obj	1
Error	LNK2005	_main already defined in create_midifile.obj	tryMidiPlayer	C:\Users\coettinger\Documents\of_v0.9.3_vs_release\apps\myApps\tryMidiPlayer\jdksmidi_test_show.obj	1
Error	LNK2005	"void __cdecl args_err(void)" (?args_err@@YAXXZ) already defined in jdksmidi_rewrite_midifile.obj	tryMidiPlayer	C:\Users\coettinger\Documents\of_v0.9.3_vs_release\apps\myApps\tryMidiPlayer\rewrite_midifile.obj	1
Error	LNK2005	_main already defined in create_midifile.obj	tryMidiPlayer	C:\Users\coettinger\Documents\of_v0.9.3_vs_release\apps\myApps\tryMidiPlayer\rewrite_midifile.obj	1
Error	LNK2005	_main already defined in create_midifile.obj	tryMidiPlayer	C:\Users\coettinger\Documents\of_v0.9.3_vs_release\apps\myApps\tryMidiPlayer\vrm_music_gen.obj	1
Error	LNK2005	_main already defined in create_midifile.obj	tryMidiPlayer	C:\Users\coettinger\Documents\of_v0.9.3_vs_release\apps\myApps\tryMidiPlayer\jdksmidi_test_drvwin32.obj	1
Error	LNK2005	_main already defined in create_midifile.obj	tryMidiPlayer	C:\Users\coettinger\Documents\of_v0.9.3_vs_release\apps\myApps\tryMidiPlayer\main.obj	1
Error	LNK1169	one or more multiply defined symbols found	tryMidiPlayer	C:\Users\coettinger\Documents\of_v0.9.3_vs_release\apps\myApps\tryMidiPlayer\bin\tryMidiPlayer_debug.exe	1

Did someone get it to work on windows?
Thanks in advance!
oe

Posts: 1

Participants: 1

Read full topic

50+ft touch screen?

$
0
0

@sjespers wrote:

I was asked if I could do a 50+ft wide touch screen app. If course I said yes but now I'm not sure where to start. :slight_smile:

Anyone have any suggestions on how to tackle this? Kinect? RealSense? Touch overlays?

Thanks!
Serge

Posts: 3

Participants: 2

Read full topic

ofVideoGrabber 4k UHD Capture Latency?

$
0
0

@eightlines wrote:

I've got a Logitech Brio and I'm trying to capture a 4k USD resolution video stream (3840 x 2160px @ 30 FPS). The issue is the latency starts to get very apparent after a few seconds. Is there a way to turn off buffering?

Tried updating a texture on isFrameNew() and using setPixelFormat(OF_PIXELS_NATIVE). Using a MacBookPro with Radeon Pro 450 graphics card. Openframeworks 0.9.8 on OS X.

Posts: 1

Participants: 1

Read full topic

Run after a certain time

$
0
0

@openF wrote:

I am a beginner in creating games using openframeworks.

I want to display a screen that says "Success" after 2 seconds when I get the score when I am playing the game.

If you know how to use ofGetElapsedTimef () function.
If you have any other suitable function, please help me.

Thank you in advance.

Posts: 1

Participants: 1

Read full topic

Viewing all 4929 articles
Browse latest View live