Panorama
Panorama copied to clipboard
How to add an object in the scenario
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?
by "object" do you mean UIKit element or OpenGL geometry? or something else?
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.
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?
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).
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?
:/ 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?
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.
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?
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.
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?
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?
oh great! i think you uncovered a bug in screenLocationFromVector:
it appears to be returning its antipode as well
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
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)];
}
}
@Allui Can you add your code here?
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?