Jump to content

Smooth Zooming


Shard
 Share

Recommended Posts

Hey guys. Been a while since I've posted. Hope ya'll are having great holidays.

 

So my question is about zooming.

 

In my game, the player can go into overhead view, which allows the camera to fly above the battlefield so that the players can see more of the field. Then they can hit a key and zoom back into their character bodies.

 

While I have the most if it figured out, I'm not sure how to do the transition.

 

Currently, I'm using the code below but that just sends the camera flying away from the screen.

 

Has anyone ever tried this before? What should I do?

 

void Switch()
{

switching = true;

TVec3 newPos = EntityPosition(player->player);
cameraPos = EntityPosition(world->frameWerk.GetMain().GetCamera());

newPos.Y += 5;
newPos.Z -= 10;



if(cameraPos == newPos)
{
	switching = false;
}

else
{
	MoveEntity(world->frameWerk.GetMain().GetCamera(), Vec3(0,5,10));
}

}



void Update()
{
   if(switching)
{
	Switch();
}

else
{
              //Do other stuff
}
}

simpleSigPNG.png

 

Programmer/Engineer/Student

www.reikumar.com

 

2.6 GHz Intel Core Duo - nVidia GeForce 8600 GT - Windows 7 64-bit - 4 Gigs RAM

C++ - Visual Studio Express - Dark GDK - Leadwerks SDK

Link to comment
Share on other sites

You can use the Curve() function of LE to smoothly interpolate to a certain coordinate, or you can parent the camera to a physics sphere and move the sphere with force commands.

Ryzen 9 RX 6800M ■ 16GB XF8 Windows 11 ■
Ultra ■ LE 2.53DWS 5.6  Reaper ■ C/C++ C# ■ Fortran 2008 ■ Story ■
■ Homepage: https://canardia.com ■

Link to comment
Share on other sites

To get this smoothed out use Curve. Now you are using some linear movement, if you want some swifty side movement you'll need to use some math.

 

For the time being, linear motion is just fine.

 

 

How do I use the curve? From what I've seen, MoveEntity just sends the camera flying away from the map, not stopping.

simpleSigPNG.png

 

Programmer/Engineer/Student

www.reikumar.com

 

2.6 GHz Intel Core Duo - nVidia GeForce 8600 GT - Windows 7 64-bit - 4 Gigs RAM

C++ - Visual Studio Express - Dark GDK - Leadwerks SDK

Link to comment
Share on other sites

You basically supply the Curve method a destination value, the previous value and a smoothing value.

 

Curve is used in the "Camera Controls" tutorial at http://www.leadwerks.com/files/Tutorials/CPP/Camera_Controls.pdf. Check out page 6, "Fine Tuning".

 

 

Curve only takes in a float as its parameters. How would I give it a Vec3() destination coordinates?

simpleSigPNG.png

 

Programmer/Engineer/Student

www.reikumar.com

 

2.6 GHz Intel Core Duo - nVidia GeForce 8600 GT - Windows 7 64-bit - 4 Gigs RAM

C++ - Visual Studio Express - Dark GDK - Leadwerks SDK

Link to comment
Share on other sites

Each component of Vec3 seperately.

 

 

After making every component switch by itself, it seemed to work fine until the angle was changed.

 

When facing north, it works just fine.

But if I face any other direction, it jumps to the wrong direction.

 

void Switch()
{
switching = true;

TVec3 newPos = cameraPos;
cameraPos = EntityPosition(world->frameWerk.GetMain().GetCamera());

newPos.Y += 5;
newPos.Z -= 10;


if(cameraPos == newPos)
{
	switching = false;
}

else
{
	cameraPos.X = Curve(cameraPos.X,newPos.X,3);
	cameraPos.Y = Curve(cameraPos.Y,newPos.Y,3);
	cameraPos.Z = Curve(cameraPos.Z,newPos.Z,3);

	PositionEntity(world->frameWerk.GetMain().GetCamera(),cameraPos);
}
}

 

I think this means that I need to adjust which component I'm changing based on direction, but I have no idea how to do that.

 

Note: This particular piece of code is just supposed to switch between first person and third person. The RTS/FPS switch I will code later by using the same principles.

simpleSigPNG.png

 

Programmer/Engineer/Student

www.reikumar.com

 

2.6 GHz Intel Core Duo - nVidia GeForce 8600 GT - Windows 7 64-bit - 4 Gigs RAM

C++ - Visual Studio Express - Dark GDK - Leadwerks SDK

Link to comment
Share on other sites

That symptom is indicative of mixing world rotation and local rotation. Make sure you're always using either local space or world space or translating properly between them.

 

 

After about a weeks time to trying to make this work I've come up with nothing that works properly. I hate to have to ask this, but could someone post an example or sample code of how I should be doing it?

simpleSigPNG.png

 

Programmer/Engineer/Student

www.reikumar.com

 

2.6 GHz Intel Core Duo - nVidia GeForce 8600 GT - Windows 7 64-bit - 4 Gigs RAM

C++ - Visual Studio Express - Dark GDK - Leadwerks SDK

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...