Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to add objects #19

Closed
zhuozhuo opened this issue Oct 16, 2014 · 8 comments
Closed

How to add objects #19

zhuozhuo opened this issue Oct 16, 2014 · 8 comments

Comments

@zhuozhuo
Copy link

No description provided.

@zhuozhuo
Copy link
Author

I want add some objects such as buttons or view.

@mayakraft
Copy link
Owner

got a solution-
it looks like GLKView Opaque property needs to be NO for this to happen. I'm going to push this small change up to master.

@mayakraft
Copy link
Owner

my hierarchy looks like this:
GLKViewController
-GLKView (PanoramaView)
--UIKIT Objects (UIButton, UIView)

add all your elements as subviews to PanoramaView and it should work fine

here's my ViewController.m code:
@interface ViewController (){
PanoramaView *panoramaView;
}
@EnD

@implementation ViewController

  • (void)viewDidLoad{
    [super viewDidLoad];
    panoramaView = [[PanoramaView alloc] init];
    [panoramaView setImage:@"park_2048.jpg"];
    [panoramaView setOrientToDevice:YES];
    [panoramaView setTouchToPan:NO];
    [panoramaView setPinchToZoom:YES];
    [panoramaView setShowTouches:NO];
    [self setView:panoramaView];

    UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    [button setFrame:CGRectMake(10, 10, 100, 100)];
    [button setBackgroundColor:[UIColor blackColor]];
    [panoramaView addSubview:button];
    [button addTarget:self action:@selector(buttonAction) forControlEvents:UIControlEventTouchUpInside];
    }

-(void) buttonAction{
NSLog(@"hit");
}

-(void) glkView:(GLKView *)view drawInRect:(CGRect)rect{
[panoramaView draw];
}

@EnD

@zhuozhuo
Copy link
Author

Thank you for your answer。But I want to let button follow panoramaView rotation movement.

@mayakraft
Copy link
Owner

oh, i would build an object in openGL, putting it where this comment is:
//TODO: add any objects here to make them a part of the virtual reality
that way it distorts properly and feels like it's integrated.

if you just want a UIKit object tracking a point (it wouldn't rotate for example), then you want to convert a unit vector to a screen point. i have a function
-(GLKVector3) vectorFromScreenLocation:(CGPoint)screenTouch inAttitude:(GLKMatrix4)matrix;
and what you'd want is the inverse of that. which might be useful to have. i don't have time free time at the moment, but if you want to take care of it I'll merge it. Or I can look into it at a later time.

@autresphere
Copy link

Hi,
Any news about this screenLocationFromVector method?
Thanks in advance.

@autresphere
Copy link

Here is some code that returns the location on screen from a 3D point:

- (BOOL)computeScreenLocation:(CGPoint*)location fromVector:(GLKVector3)vector inAttitude:(GLKMatrix4)matrix
{
    GLKVector4 screenVector;
    GLKVector4 vector4;

    if(location == NULL)
        return NO;

    matrix = GLKMatrix4Multiply(_projectionMatrix, matrix);
    vector4 = GLKVector4Make(vector.x, vector.y, vector.z, 1);
    screenVector = GLKMatrix4MultiplyVector4(matrix, vector4);

    location->x = (screenVector.x/screenVector.w/2.0 + 0.5) * self.frame.size.width;
    location->y = (0.5-screenVector.y/screenVector.w/2) * self.frame.size.height;

    return (screenVector.z >= 0);
}

This method returns wether the point is before or behind the screen.
It does work in portrait but would need some additional code to take care of all orientations.
I will create a PR if I find some time.

@mayakraft
Copy link
Owner

it actually works fine with orientations, it alerted me to another issue- orientation handling is being over-complicated, fixing it now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants