Skip to main content
gamedev.net
🔒 Locked 🎮 Unity

AspectRation Camera

Started by Zanzibar 3 replies 1k views
Original Post
Zanzibar
Zanzibar
Hi I'm trying something really simple, but I just won't succeed. It is already bothering me for a whole day and I don't see light at the end of the tunnel. I'm trying to get a straight view on my screen, devide my screen in 8 blocks and have 1 area filled with a silly bitmap. These are some of my calculations Camera stuff SetViewParameters(new Vector3(0.0f, 0.0f, -1f), new Vector3(0, 0, 0), new Vector3(0, 1, 0)); SetProjectionParameters((float)Math.DegreeToRadian(90), 800f/600f, 0f, 100.0f); Screen resolution is 800/600 so aspectratio returns 1.333 PointF Reso = new PointF(800, 600); Now this is how I scale and Position the little thingy. s = new Smurf(400, 150); s.Scale = new Vector3(((float)s.Width / Reso.X), ((float)s.Height / Reso.Y), 1); s.Position = new Vector3(-1 + ((float)s.Width / Reso.X), -1 + ((float)s.Height / Reso.Y), 0); The effect on the Y-axis is perfect. On the X-Axis, the effect is incorrect. It doesn't fill the entire area. When I change my camera to use an aspectRatio of 1, it stretched correct. SetProjectionParameters((float)Math.DegreeToRadian(90), 1f, 0f, 100.0f); What am I doing wrong. I don't see my mistake. Many thanks Alexader
Buckeye
Buckeye
It's not clear how you apply s.Scale. But if you scale the object and then project it, you're applying the aspect ratio twice.

When you set the aspect ratio to 1, then you're applying the ratio once (which is what you want, I think).

BTW:
Quote:
SetProjectionParameters((float)Math.DegreeToRadian(90), 800f/600f, 0f, 100.0f);

You should never use a near plane setting of 0! Use 0.25 or 0.5 at a minimum!

Please don't PM me with questions. Post them in the forums for everyone's benefit, and I can embarrass myself publicly. You don't forget how to play when you grow old; you grow old when you forget how to play.
Zanzibar
Zanzibar
Hi

Thanks for the info, I switched the nearplane.

This is how I calculate the worldmatrix of the object. I use slimdx and C# as api.


protected virtual Matrix CalcWorldMatrix(){
return Matrix.Scaling(Scale.X, Scale.Y, Scale.Z) *
Matrix.RotationYawPitchRoll(Rotation.Y, Rotation.X, Rotation.Z) *
Matrix.Translation(Position.X, Position.Y, Position.Z);
}

What is actually the disadvantage of setting the aspectratio to 1?


Kind regards

Alexander
Zanzibar
Zanzibar
You are right though about the double aspectratio.

When I make a bitmap of 150*400 it has less pixels than a bitmap of 400*150.
So I put the aspect ratio to 1 and now they are the same.
I'll continue the playing.

kind regards

Alexander
Buckeye
Buckeye
Quote:
What is actually the disadvantage of setting the aspectratio to 1?

I wouldn't say it's a "disadvantage," but you'll have to remember to scale objects appropriately to look correct on the screen. I've never tried it but it may affect other sprites, text, etc.
Please don't PM me with questions. Post them in the forums for everyone's benefit, and I can embarrass myself publicly. You don't forget how to play when you grow old; you grow old when you forget how to play.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.