How to display a part of a scene in another scene (Scene Kit + Swift) - swift

First, I just want to introduce to you guys my problem, because it is really complex so you need this to understand it properly.
I am trying to do something with Scene Kit and Swift : I want to reproduce what we can see in the TV Show Doctor Who where the Doctor's spaceship is bigger on the inside, as you can see in this video.
Of course the Scene Kit Framework doesn't support those kind of unreal dimensions so we need to do some sort of hackery to do achieve that.
Now let's talk about my idea in plain english
In fact, what we want to do is to display two completely different dimensions at the same place ; so I was thinking to :
A first dimension for the inside of the spaceship.
A second dimension for the outside of the spaceship.
Now, let's say that you are outside of the ship, you would be in the outside dimension, and in this outside dimension, my goal would be to display a portion of the inside dimension at the level of the door to give this effect where the camera is outside but where we can clearly see that the inside is bigger :
We would use an equivalent principle from the inside.
Now let's talk about the game logic :
I think that a good way to represent these dimensions would be two use two scenes.
We will call outsideScene the scene for the outside, and insideScene the scene for the inside.
So if we take again the picture, this would give this at the scene level :
To make it look realistic, the view of the inside needs to follow the movements of the outside camera, that's why I think that all the properties of these two cameras will be identical :
On the left is the outsideScene and on the right, the insideScene. I represent the camera field of view in orange.
If the outsideScene camera moves right, the insideScene camera will do exactly the same thing, if the outsideScene camera rotates, the insideScene camera will rotate in the same way... you get the principle.
So, my question is the following : what can I use to mask a certain portion of a certain scene (in this case the yellow zone in the outsideView) with what the camera of another view (the insideView) "sees" ?
First, I thought that I could simply get an NSImage from the insideScene and then put it as the texture of a surface in the outsideScene, but the problem would be that Scene Kit would compute it's perspective, lighting etc... so It would just look like we was displaying something on a screen and that's not what I want.

there is no super easy way to achieve this in SceneKit.
If your "inside scene" is static and can be baked into a cube map texture you can use shader modifiers and a technique called interior mapping (you can easily find examples on the web).
If you need a live, interactive "inside scene" you can use the sane technique but will have to render your scene in a texture first (or renderer your inside scene and outer scene one after the other with stencils). This can be done by leveraging SCNTechnique (new in Yosemite and iOS 8). On older versions you will have to write some OpenGL code in SCNSceneRenderer delegate methods.

I don't know if it's 'difficult'. As we have to in iOS , a lot of times the simplest answer ..is the simplest answer.
Maybe consider this:
Map a texture onto a cylinder sector prescribed by the geometry of the Tardis cube shape. Make sure the cylinder radius is equal of the focal point of the camera. Make sure you track the camera to the focal point.
The texture will be distorted because it is a cylinder making onto a cube. The actors' nodes in the Tardis will react properly to the camera but there should be two groups of light sources...One set for the Tardis and one outside the Tardis.

Related

How to make one game object to be in front of another in unity

I heard that game objects are drawn in the same order they appear in the Hierarchy. But in my case it doesn't work.
For example I wanted the wolf is placed in front of the rabbit, but it doesn't work.
Is there some way to make it with sorting objects according in hierarchy or I can make it only with layers?
The hierarchy sorting you speak of only works in the canvas - so for example with RectTransforms and Images. However I guess you want to use Sprites. SpriteRenderer component has a Order in layer property. Plus Sprites are more lightweight than Images with Transparency. Or you could just move Transforms closer and further away from the camera (even if your game is 2D/ using an orthogonal camera). If everything fails you could change the RenderQueue of the Materials.

Infinite plane background

How would i go about creating as a background for a 3d scene a plane with a texture that stretches into the horzon? I have tried a skybox but i think a skybox will also be needed "behind" the infinite plane.
It depends whether you need to have an actual geometry that will be seen from close up - if not, you can bake it into the skybox.
In some cases (i.e. when the user has stereoscopic display on their head) you will need to have actual geometry.
Its not exactly clear from your question if you want to create a 'floor' or a 'wall', but in both cases I would link it with player position somehow. A floor could follow players X an Z, while a 'wall' could be made a child to the camera, this way it would never leave the viewport.
Skybox would still be the cheapest by a significant margin, we can give more advice if you provide some additional information. i.e. what are you trying to achieve

How to zoom out a material in Unity?

Ok, new to skyboxes here but Im having a problem involving a radial gradient material I'm using as a skybox and the field of view on my camera. My problem is this: the gradient looks great and ou can see the gradient part only when the camera's field of view is really high.
I built my whole scene at field of view 7 and at that proximity, I don't get a gradient here is the comparison:
I have my whole scene (the objects) in an empty, but even if I up their z value at the high field of view they don't look like they used to. Without completely rebuilding EVERYTHING in my scene position wise, how can I zoom out my material as the skybox?
Is there a way to up the field of view without moving away from the objects in my scene?
I can post my shader code as well.
Is there a way to up the field of view without moving away from the objects in my scene?
Here's the key: Because FOV basically zooms in you'll get all the ugly artefacts associated with being eye-ball close with something, such as your skybox. So, unfortunately the answer is no, you need to position your camera further away and increase the scale of your objects. To compensate just scale up all the objects in your scene, preferably in your 3D modelling app rather than in Unity.

how to deform image?

Hi Friends
I Want to make a simple gaming Application in which the user hit the car and car breaks from that point means the image get little deformed when the user hit the car image. I know everything could be possible with using of lots of images and get change when user hit that car image but i don't want to use so many images.
is there any solution for this , how can i deform the image ..sorry for my English but , here i paste a link of the game that is on flash and this is what i exactly want..
http://www.playgecogames.com/file.php?f=657&a=popup
please respond soon
thanks
You don't say if this is in 2D or 3D, or what techniques you're going to use.
If you're implementing the game using OpenGL, it's fairly straightforward. The object can be made up of a regular mesh, with the image as a texture mapped to the mesh. When the user hits the object, you just deform the mesh.
A simple method would be to take a vector in the direction of the hit, displace the nearest vertex by an amount proportional to the force of the strike, and then fan out in to deform the rest of the mesh in decreasing amounts. By deforming the mesh, the image texture will be rendered with all the dents or deformations you like.
If you want to to this without OpenGL and just straight images, you could use image resampling to simulate the effect. You have your original pristine image which is 'filtered' to make up the resulting image. At first there are no deformations so you copy the original image verbatim. Each time the user hits the object, you can add a deformation using a filter or transform within a local region of interest. This function would resample the source image in a distorted manner, causing it to look like the object is damaged.
If you look up some good books on game development, you'll find a great range of approaches to object collisions, deformations and so on.
If you know a bit about image processing technics here is the documentation for accessing the pixels of the image :
Apple Reference
You also have libraries for this such as this one :
simple-iphone-image-processing
But for what you want to do this might not be the easiest way. What I would suggest is that you divide the car into several images depending on what areas can be impacted. Then you just change the image corresponding to the damaged zone each time the car is hit.
I think you should use the cocos2d effects http://www.cocos2d-iphone.org/wiki/doku.php/prog_guide%3aeffects + multiple images. Because there are many parts which drops after the player kick the car. Like when user kick the side mirror you should change the car image with without side mirror car image.
The person that has made that flash game used around 4 images to display the car. If you want the game to be in 2d, the easiest way is to draw the car, cut it into about 4 pieces (: left side + right side (duplicate of the left side) hood and roof).
If you want to "really" deform the car you'll have to use a 3d engine like openGLES.
Id really suggest doing it in 2d :)
I suggest having a look at the cocos2d game engine. You can modify images with effects, which are applied using a virtual grid. Have a look at the effects page in their programming guide.

Scrolling a game environment in various directions

How does one create the game "area" for a scroller game?
How does one then put various obstacles with collision detection along this scrolled environment.
I want to try out a project which will allow the user to scroll to a certain direction in order to progress through the game.
How does one map the objects within the environment and then move what I guess is the "camera", the view of the environment.
Thanks
The trick is that there is no "area". The only bits that exist are what's under the camera (the view you currently see) and a small surrounding area giving you time to prepare more world in the direction you are moving..
Your world coordinates need to be defined as do the starting coordinates for the view. You use tiles to create the view - at its simplest that is 9 tiles, one you are currently "on" and one in each direction. If you look at the keyboard numberpad you are "on" the 5. If you move a little to the top right you are displaying parts of tiles 8, 9, 5 & 6. At that point you would create new tiles in case you move further. As you leave tile 5 you would probably release tiles 4, 1 & 2. Nine tiles may not be the optimal number of course.
If doing this with UIViews (probably not the high-performance choice) you are probably going to define one big view that can handle all the tiles and tile them onto the view (add and remove subviews), setting the large view's frame to define your camera position. As you move you change the frame to move your camera, when you need to shuffle tiles you move both the tiles and the frame to recenter giving room to move further within the coordinates of your view.
Collision detection is pretty simple since you define your own dimensions (the thing representing "you" in this world) and objects in your view have dimensions you can check against. CGRectIntersectsRect might be the simplest function to use but if you have irregularly-sized views it will get more complicated.
This answer about implementing a cyclic UIScrollView is a similar idea but it only handles scrolling on one direction.
This is a pretty common topic and if you google you will find a lot of sample code and tutorials around.
From the game logic side:
All your objects (lets call them gameobjects) should have a coordinate (x and y position) in your game world. You will keep all your gameobjects in a list. Your player object will be a gameobject too. Usually your "camera" position will be relative to your player objects position. I.e. the player will always be in the center of the screen. To determine the current "screen" position of your objects you will just subtract the camera position from your objects "world" position. Collision is usually made with simple rectangular overlap checks. You give all your objects a width and a height attribute and do your collision checks using x, y, width and height.
From the display side:
If you want to display many objects (i.e. Player, Enemies, Obstacles and so on) the best way to implement something like this is to use an OpenGL View. In this view you can display all Objects as Textures that are mapped to Polygons. You can use a library such as cocos2d which already has all of the code to achieve this easily.