Welcome, Guest. Please login or register.

Login with username, password and session length

 
Advanced search

1411283 Posts in 69325 Topics- by 58380 Members - Latest Member: bob1029

March 29, 2024, 01:51:18 AM

Need hosting? Check out Digital Ocean
(more details in this thread)
TIGSource ForumsDeveloperTechnical (Moderator: ThemsAllTook)[SOLVED] Change the 3D "focus point" of a perspective camera
Pages: [1]
Print
Author Topic: [SOLVED] Change the 3D "focus point" of a perspective camera  (Read 4092 times)
Pampattitude
Level 0
**



View Profile WWW
« on: December 12, 2014, 04:43:30 AM »

Hey there!

I'm working on a POC for a top-down Link's Awakening-like game (with "procedural" world generation and all the buzzwords you can find Tongue ) on mobile mixing 2D (character sprite) and 3D (ground, walls, scenery elements).

However, I'm having trouble with a specific thing.
I would like to "center" the perspective effect on the player without moving the camera (the idea behind is, my girlfriend and some potential players are epileptic and I want the camera to be as static as can be). That is to say, I want the walls perspective to adapt to the player position instead of the camera center, to bend more when the player is away and be almost vertical when the player is close.

I couldn't find any kind of resource on the subject, and I don't even know where to start. The idea is pretty simple, right?

If you guys have any kind of idea, that'd be a delight!

P.S.: I can't doodle anything right now, but if needed I'll try to Paint something to be a bit more explicit when I can.
« Last Edit: December 14, 2014, 02:20:13 PM by Pampattitude » Logged
bateleur
Level 10
*****



View Profile
« Reply #1 on: December 12, 2014, 06:37:27 AM »

Do you have Unity Pro? If so (and assuming I'm understanding you correctly) you could do this with a Render Texture: http://docs.unity3d.com/Manual/class-RenderTexture.html

The idea would be to have the render texture larger than the screen, have a camera following the player's character around, but then scroll the render texture to put the rendered character back in the centre of the player's screen.

I think you'd need a texture roughly twice the size of the screen in each dimension to make all positions possible.
Logged

ThemsAllTook
Administrator
Level 10
******



View Profile WWW
« Reply #2 on: December 12, 2014, 06:38:22 AM »

It sounds like what you want is to change your view matrix's vanishing point without moving a specific center point in the foreground. From what I recall, you'd need to apply a translation to your matrix before doing the perspective transformation, but I haven't done it myself so I'm pretty fuzzy on the specifics of the math. Does Unity let you directly manipulate its projection/modelview matrix?
Logged

gimymblert
Level 10
*****


The archivest master, leader of all documents


View Profile
« Reply #3 on: December 12, 2014, 07:05:10 AM »

It's an oblique frustrum
http://docs.unity3d.com/Manual/ObliqueFrustum.html

Code:
function SetObliqueness(horizObl: float, vertObl: float;) {
    var mat: Matrix4x4 = camera.projectionMatrix;
    mat[0, 2] = horizObl;
    mat[1, 2] = vertObl;
    camera.projectionMatrix = mat;
}
Logged

Pampattitude
Level 0
**



View Profile WWW
« Reply #4 on: December 12, 2014, 07:45:45 AM »

Well, Gimym, you get the grand prize! Thanks a bunch!
@bateleur, I thought about that but, from what I know of render textures, it isn't that efficient and may cause trouble if I have multiple cameras (which I do, I have three cameras for now).
@ThemsAllTook, apparently I do, as Gimym pointed out.

Thanks a whole bunch of bunches :3
Logged
Pampattitude
Level 0
**



View Profile WWW
« Reply #5 on: December 14, 2014, 11:23:21 AM »

Alright, I'm sorry for bringing the topic back up, but I don't really understand what "oblique" means.
I did tests to check out the effect and see what I could do with it, and I don't understand.

What is an "oblique"? I mean, I know angles and stuff, but an "oblique" does not seem to be an angle.

What I want to do is simple: I want to focus the rendering on the player position (x, y, z) but keep the camera in the middle of the screen.

Here is an example:




As you can see, the effect by itself is good but the camera position is wrong. I tried playing with the values to get a satisfying result, but I don't understand the values. Also, it seems to affect aspect ratio and I don't get why.

Did someone already do a similar effect, or know docs explaining what means what?

Thanks a bunch, guys, for the help :3


[EDIT] Also, does the FOV have any impact on this oblique thing?
Logged
gimymblert
Level 10
*****


The archivest master, leader of all documents


View Profile
« Reply #6 on: December 14, 2014, 11:45:51 AM »

I don't understand the screen is the camera the camera is always in the middle.

Let say you have an horizon, every line converge to it, if you want to horizon to not sit in the middle ofe screen you angle the camera, but then it is wrong the horizon didn't move the camera did, now all your vertical who where perpendicular to the horizon now converge to another point. If you want to move the horizon and keep the vertical as is, you "shear" the frustrum at an angle without moving the camera, so it allow you to give more space to sky or ground or just have a more pleasing composition with horizon sitting on a rule of third line.

NOW deducing from the sample image it seem that you want to emulate the old top down zelda thingy!

Okay, there is two major way to do it:



1. you set the camera to ORTHOGRAPHIC and then angle the camera a bit, you will lose the vanishing point effect and every object will be the same size, you won't have "the wall at angle" like in 2D zelda either.

This is perpective


this is orthographic (no more vanishing line, parallel keep being parallel)




2. You modify the asset to get the minimized the effect and set some object to tilt depending to where the camera is.

This is how they do it on the 3DS zelda game



Old game cheated with perspective


http://opengameart.org/content/chapter-3-perspectives

You can achieve this effect with a shader that scale vertex linearly from the base the asset along the Y axis of the object.

AND

You can combine both techniques fo better effects too.
Logged

Pampattitude
Level 0
**



View Profile WWW
« Reply #7 on: December 14, 2014, 12:22:58 PM »

I don't really want to emulate that effect.

I want the elements close to the play be aligned more with the camera than the objects far away. That I to say, I want the 3D perspective to be centered on the player, but I don't want to center the camera on the player.

The idea is, when you move, the walls seem to skew around you (because of the 3D "origin" being the player).
What you showed me about the frustum seem to do exactly that. I can change where the "origin" of the 3D perspective is. What I don't get now is, what is the "oblique" of the frustum? Why do I have to move the camera (at least in Unity) after changing said oblique? Why does the aspect ratio is messed up when I change the size of the screen but keep the same oblique parameters?
Logged
gimymblert
Level 10
*****


The archivest master, leader of all documents


View Profile
« Reply #8 on: December 14, 2014, 12:42:59 PM »

It basically change the relative center of the perspective away from the center of the screen, they are usually aligned.





A way to visualize it is to imagine that you move the far away clip plane of the camera



It's oblique because now the frustrum side isn't equally scaled along the camera direction, it's also called tilt frustrum

Another way to look at it is to see the frustrum as if you extend the screen ratio in one direction to see more stuff, but the ratio of teh screen stay the same and it crop the image into the other direction.

To keep the player centered you need to offset by equal amount the screen to the center of the perspective.

A value of:
(0,0) mean that the frustrum is centered to the screen
(0,1) mean the frustrum is centered to the top of the screen (negative mean bottom)
(1,0) mean it's on the right (negative mean left)

The screen coordinate can be projected on a 0 to 1 scale (xposition/xscreensize,similar for y)
You need to convert it to 0 centered coordinate which mean

offset = (x+0.5)*2
Logged

Pampattitude
Level 0
**



View Profile WWW
« Reply #9 on: December 14, 2014, 02:19:58 PM »

I think I got it, thanks a bunch for your patience!
Logged
BorisTheBrave
Level 10
*****


View Profile WWW
« Reply #10 on: December 14, 2014, 03:14:21 PM »

Does anyone have a gif or video demonstrating the oblicueness. It sounds interesting, but I cannot visualize it.
Logged
gimymblert
Level 10
*****


The archivest master, leader of all documents


View Profile
« Reply #11 on: December 14, 2014, 03:20:50 PM »

Have played need for speed most wanted? when the game spot a cop and focus on it without having typical parallax effect due to perspective. That's it, it's like scrolling a photo without the parralax
Logged

Pages: [1]
Print
Jump to:  

Theme orange-lt created by panic