mayakraft / SimpleOculus

Oculus Rift for native Mac OS X
28 stars 5 forks source link

how to add additional objects? #1

Open r03ert0 opened 10 years ago

r03ert0 commented 10 years ago

hello, thank you for SimpleOculus! it was just what i needed to start going with OVR and cocoa.

One question. I tried to add a cube to the panorama, but the interpupillary distance was awkward... what is the appropriate way of adding objects? This is what I added to Scene.mm, to try to display a cube:

void Scene::render() {
    drawPanorama();

    int     i,j;
    GLfloat o[3]={0,0,-5};
    GLfloat P[]={   0,0,0,  1,0,0,  1,1,0,  0,1,0,
                    0,0,1,  1,0,1,  1,1,1,  0,1,1};
    GLfloat C[]={   0,0,0,  1,0,0,  1,1,0,  0,1,0,
                    0,0,1,  1,0,1,  1,1,1,  0,1,1};
    GLint   T[]={   0,1,2, 0,2,3,
                    1,5,6, 1,6,2,
                    5,4,7, 5,7,6,
                    4,0,3, 4,3,7,
                    3,2,6, 3,6,7,
                    0,4,1, 1,4,5};
    for(i=0;i<8*3;i++)
        P[i]=(P[i]-0.5)*1;

    glBegin(GL_TRIANGLES);
    for(i=0;i<12;i++)
        for(j=0;j<3;j++) {
            glColor4f(C[T[3*i+j]*3+0],C[T[3*i+j]*3+1],C[T[3*i+j]*3+2],1);
            glVertex3f(o[0]+P[T[3*i+j]*3+0],o[1]+P[T[3*i+j]*3+1],o[2]+P[T[3*i+j]*3+2]);
        }
    glEnd();
}

Also... the cube renders all squished...

thank you in advance for your help! roberto

mayakraft commented 10 years ago

sorry for such a late response! i revisited the project and made a scene where adding objects should come a little more naturally. you can check the place where i added a chessboard of tiles on the ground. regarding your code: i learned OpenGLES, so i'm unfamiliar with GLBegin and GLEnd. If the geometry is correct, try putting it between a glpushmatrix and a glpopmatrix, and try plugging it into the scene in the same place where the chessboard tiles are generated, lemme know what happens then.

r03ert0 commented 10 years ago

thank you!

I had to to change the code in OculusView.h to this to make it compile (adding 3 more #imports):

//
//  GLView.h
//  SimpleOculus
//
//  Created by Robby Kraft on 1/25/14.
//  Copyright (c) 2014 Robby Kraft. All rights reserved.
//
#import <Cocoa/Cocoa.h>
#import <CoreGraphics/CoreGraphics.h>
#import <OpenGL/OpenGL.h>
#import <OpenGL/gl.h>
@interface OculusView: NSOpenGLView
@end

thanks, roberto

mayakraft commented 10 years ago

thanks! included in the project lemme know if you are having any more issues with squashed geometry!

mayakraft commented 10 years ago

I finally experienced squished geometry! something is very wrong! thanks for pointing this out. I fixed something momentarily so it's no longer inducing quite a headache. I got a hold my old work's Oculus, I'm gonna dive into this.

ghost commented 9 years ago

Hello! Thanks for the project and the fix-ups. As a beginner in OpenGL and OVR, now I still fail to add objects in the scene. Would you mind share a way or just share your code to show how to build a cube in the scene, and further, what if the cube is supposed to be rotating ? Thank you so much!