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 an object in the scenario #35

Open
UlyssesRocha opened this issue Apr 4, 2016 · 16 comments
Open

How to add an object in the scenario #35

UlyssesRocha opened this issue Apr 4, 2016 · 16 comments

Comments

@UlyssesRocha
Copy link

Hi,
I saw at issue 19, a way of add a button in the screen, outside the VR scenario.

But, Its possible to add an object at a relative position inside the VR image?
Set an image to represent an Object at a relative position (altitude and azimute) , to be render with the background image?

@mayakraft
Copy link
Owner

by "object" do you mean UIKit element or OpenGL geometry? or something else?

@UlyssesRocha
Copy link
Author

Ideally an UIKit element (I am not familiar with OpenGL ), in my scenario I want to add a .PNG image of a satellite object at a "real world position" , I am not sure what kind of object I will need.

@mayakraft
Copy link
Owner

right.. so, the problem isn't solved for UIKit elements. you saw from issue 19 that you can update the element's x,y position using that getScreenLocation... function? but that the object doesn't rotate with the scene.

what's missing is some kind of function that's like rotationValue for Screen Location.

were you trying to solve the rotation problem? or thinking of a different approach?

@UlyssesRocha
Copy link
Author

You mean rotation by the itself rotation?
http://i.stack.imgur.com/yt3D4.png

Or in the 3d environment?
In my case, I only need to set the "spacial position", so I only need to set the "2d" position. ( I only have the azimuth and altitude of the object)

I am not sure what I need to do to achieve this behaviour (again, I am not familiar with OpenGL).

@mayakraft
Copy link
Owner

again, this is not a good solution. UIKit integration isn't seamless at this point. step 1 is this function:

-(CGPoint) screenLocationFromVector:(GLKVector3)vector;

you have the altitude and azimuth, convert that to a vector, and then set your UIKit element's position to the CGPoint returned.

but you'll notice that your UIKit element doesn't rotate if you rotate your screen around the Z axis (the normal through the screen). doing this would be step 2

is this the direction you are aiming for?

@UlyssesRocha
Copy link
Author

:/ I need the Z axis to give the user the "point to a satellite" feature.

This step 2 to get the Z axis is too complicated using UIKit?
What you recommend to be done, use an OpenGL object? Can you give some directions?

@mayakraft
Copy link
Owner

i'm not good enough at 3D math to anticipate wether or not step2 would be an easy problem to solve. it might be easy..
the best approach might be a combination of the two.
doing it in opengl will be visually seamless but loses the uikit touch interaction paradigms. you have to build your own touch detection -(BOOL) touchInRect:(CGRect)rect; would help you get started but using a (clear) uikit element for touch detection might make for the best behavior you're seeking.

@UlyssesRocha
Copy link
Author

So I should start setting the UIKit element and setting its position to
-(CGPoint) screenLocationFromVector:(GLKVector3)vector;
And then work to correct the position in the Z axis?

@mayakraft
Copy link
Owner

the position won't be incorrect.

you should do what you're suggesting. you'll see what i'm talking about. it's only the rotation of the object that will be incorrect. the position should be fine.

@UlyssesRocha
Copy link
Author

Ty very much for the support, I will try to implement it.
To add the object, I should use addSubView? do I have to worry about keep updating the position of the object, or it will be done automatically?

@UlyssesRocha
Copy link
Author

Probably there is a smarter way of doing this, buuuut it kind of worked.

At initOpenGL

   button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    GLKVector3 satelite = GLKVector3Make(0, 0, 1);

    CGPoint location = [self screenLocationFromVector:satelite];
    [button setFrame:CGRectMake(location.x, location.y, 100, 100)];
    [button setBackgroundColor:[UIColor blackColor]];

    [self addSubview:button];

At updateLook

    GLKVector3 position = GLKVector3Make(0.0000001, -0.04, 0.1);
    buttonLocation = [self screenLocationFromVector:position];

    if (buttonLocation.x == buttonLocation.x){
        [button setFrame:CGRectMake(buttonLocation.x, buttonLocation.y, 40, 40)];
    }

The result,

There is another question, Why it kind of create 2 objects...? there is some way of solving this?

@mayakraft
Copy link
Owner

oh great! i think you uncovered a bug in screenLocationFromVector: it appears to be returning its antipode as well

@mayakraft
Copy link
Owner

what you did is fine but i would alloc UIKit things inside of ViewController instead of PanoramaView, place the button updating code in -(void) glkView:(GLKView *)view drawInRect:(CGRect)rect if it's possible that way

@Allui
Copy link

Allui commented Aug 1, 2016

little trick, and we have one button :D

-(void) glkView:(GLKView *)view drawInRect:(CGRect)rect {
    [panoramaView draw];
    GLKVector3 position = GLKVector3Make(0.0000001, -0.04, 0.1);
    CGPoint  buttonLocation = [panoramaView screenLocationFromVector:position];
    CGPoint p = [panoramaView imagePixelAtScreenLocation:buttonLocation];

    if (round(p.x) != 512) return;

    if (buttonLocation.x == buttonLocation.x) {
        [button setFrame:CGRectMake(buttonLocation.x, buttonLocation.y, 40, 40)];
    }
}

@mattiosdev
Copy link

@Allui
Can you add your code here?

@marcelosalloum
Copy link
Contributor

Hey @Allui, @UlyssesRocha, did any of you manage to show only one button over there? I am not sure how to do it but I guess the screenLocationFromVector method might have more than one solution. Am I right?

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

5 participants