This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
es:orx:tutorials:viewport [2012/03/01 14:48 (14 years ago)] – [Detalles] zera | es:orx:tutorials:viewport [2020/08/20 04:13 (5 years ago)] (current) – Old content sausage | ||
---|---|---|---|
Line 1: | Line 1: | ||
- | ====== Tutorial de Vista y Cámara ====== | ||
- | |||
- | ===== Sumario ===== | ||
- | |||
- | Ver previamente [[main# | ||
- | |||
- | Este tutorial muestra como usar múltiples vistas con múltiples cámaras.\\ | ||
- | Cuatro vistas son creadas aquí. | ||
- | |||
- | La esquina superior izquierda con una vista('' | ||
- | Para archivar esto, necesitamos usar el mismo nombre en el fichero de configuración para la cámara. | ||
- | |||
- | Además, cuando manipulando esta cámara usando los botones izquierdo y derecho del ratón para hacerla girar, | ||
- | las flechas para moverla y dejar presionado control y shift izquierdos para ampliarla, las dos ventanas asociadas con esta cámara se verán afectadas. | ||
- | |||
- | La vista('' | ||
- | |||
- | La última vista ('' | ||
- | |||
- | Esta vista mostrará lo que originalmente tenga en '' | ||
- | Tu puedes también interactuar directamente con las propiedades de la primera vista, usando las teclas WASD para moverla y Q & E para redimensionarla. | ||
- | |||
- | //PD: Cuando dos vistas se superponen, la antigua (ej. una creada primero que la otra)se mostrará encima.// | ||
- | |||
- | Por último, tenemos una caja que no se mueve del todo, y un pequeño soldado cuya posición en el mundo será determinado por la actual posición del ratón en la pantalla.\\ | ||
- | En otras palabras, no importa en cual vista esté tu ratón, y no importa cómo la cámara para esta vista se fija, | ||
- | el soldado siempre tiene sus pies en la misma posición que el puntero del ratón en la pantalla (siempre y cuando sea en una vista). | ||
- | |||
- | Vistas y objectos son creados con tamaños y colores aleatorios usando el carácter ' | ||
- | |||
- | //PD: Las cámaras almacenan su posicion/ | ||
- | |||
- | Como resultado, el objeto de auto-seguimiento se puede lograr mediante el ajuste del objeto como padre de la cámara.\\ | ||
- | En la otra mano, teniendo una cámara como padre de un objeto se asegurará de que el objeto se mostrará siempre en el mismo lugar en la correspondiente ventana((muy útil para hacer HUD & UI, por ejemplo)) .// | ||
- | |||
- | ===== Detalles ===== | ||
- | |||
- | As usual, we begin by loading our config file, getting the main clock and registering our '' | ||
- | Please refer to the [[main# | ||
- | |||
- | However we create four viewports this time. Nothing really new, so we only need to write this code. | ||
- | |||
- | <code c> | ||
- | orxViewport_CreateFromConfig(" | ||
- | orxViewport_CreateFromConfig(" | ||
- | orxViewport_CreateFromConfig(" | ||
- | |||
- | As you can see we only keep a reference to one created viewport. We do so as we want to interact with it later on, but we won't touch the three other ones. | ||
- | |||
- | Let's jump directly to our '' | ||
- | First we snap our soldier guy under the mouse position. We've already seen such a thing in the [[frame|frame tutorial]].\\ | ||
- | Here we do the exact same thing and we see that it works perfectly with multiple viewports.\\ | ||
- | When the mouse is not over a viewport, '' | ||
- | |||
- | <code c> | ||
- | |||
- | if(orxRender_GetWorldPosition(orxMouse_GetPosition(& | ||
- | { | ||
- | orxVECTOR vSoldierPos; | ||
- | |||
- | orxObject_GetWorldPosition(pstSoldier, | ||
- | vPos.fZ = vSoldierPos.fZ; | ||
- | |||
- | orxObject_SetPosition(pstSoldier, | ||
- | }</ | ||
- | |||
- | Before interacting directly with a viewport, let's play a bit with its associated camera.\\ | ||
- | We could, for example, move it, rotate it or zoom. | ||
- | |||
- | Let's begin by getting our first viewport camera. | ||
- | |||
- | <code c> | ||
- | |||
- | Ok, that was easy. Let's try to rotate it ((only part of the code will be shown as for other directions, the logic remains)). | ||
- | |||
- | <code c> | ||
- | { | ||
- | orxCamera_SetRotation(pstCamera, | ||
- | }</ | ||
- | |||
- | Again, we see that our rotation won't be affected by the FPS and can be time-stretched as we use the clock' | ||
- | We could still have used the config system to get the rotation speed instead of hardcoding it! =) | ||
- | |||
- | Let's zoom, now. | ||
- | |||
- | <code c> | ||
- | { | ||
- | orxCamera_SetZoom(pstCamera, | ||
- | }</ | ||
- | |||
- | As this code doesn' | ||
- | |||
- | Lastly, let's move our camera. | ||
- | |||
- | <code c> | ||
- | |||
- | if(orxInput_IsActive(" | ||
- | { | ||
- | vPos.fX += orx2F(500) * _pstClockInfo-> | ||
- | } | ||
- | |||
- | orxCamera_SetPosition(pstCamera, | ||
- | |||
- | We're now done playing with the camera.\\ | ||
- | As we'll see a bit later in this tutorial, this same camera is linked to two different viewports.\\ | ||
- | They' | ||
- | |||
- | As for viewport direct interactions, | ||
- | We can do it like this, for example. | ||
- | |||
- | <code c> | ||
- | |||
- | orxViewport_GetRelativeSize(pstViewport, | ||
- | |||
- | if(orxInput_IsActive(" | ||
- | { | ||
- | fWidth *= orx2F(1.02f); | ||
- | fHeight*= orx2F(1.02f); | ||
- | } | ||
- | |||
- | orxViewport_SetRelativeSize(pstViewport, | ||
- | |||
- | orxViewport_GetPosition(pstViewport, | ||
- | |||
- | if(orxInput_IsActive(" | ||
- | { | ||
- | fX += orx2F(500) * _pstClockInfo-> | ||
- | } | ||
- | |||
- | orxViewport_SetPosition(pstViewport, | ||
- | |||
- | Nothing really surprising as you can see. | ||
- | |||
- | Let's now have a look to the data side of our viewports. | ||
- | |||
- | <code ini> | ||
- | Camera | ||
- | RelativeSize | ||
- | RelativePosition | ||
- | BackgroundColor | ||
- | |||
- | [Viewport2] | ||
- | Camera | ||
- | RelativeSize | ||
- | RelativePosition | ||
- | BackgroundColor | ||
- | |||
- | [Viewport3] | ||
- | Camera | ||
- | RelativeSize | ||
- | RelativePosition | ||
- | BackgroundColor | ||
- | |||
- | [Viewport4] | ||
- | Camera | ||
- | RelativeSize | ||
- | RelativePosition | ||
- | BackgroundColor | ||
- | |||
- | As we can see, nothing really surprising here either.\\ | ||
- | We have three cameras for 4 viewports as we're using '' | ||
- | We can also notice that all our viewports begins with a relative size of '' | ||
- | This means each viewport will use half the display size vertically and horizontally (the Z coordinate is ignored).\\ | ||
- | In other words, each viewport covers exactly a quart of our display, whichever sizes we have chosen for it, fullscreen or not.\\ | ||
- | |||
- | As you may have noticed, we only gave an explicit value for the '' | ||
- | All the other viewports inherits from the '' | ||
- | That means that this value will be the same than the one from '' | ||
- | We did it exactly the same way for '' | ||
- | |||
- | We then need to place them on screen to prevent them to be all displayed on top of each other.\\ | ||
- | To do so, we use the property '' | ||
- | |||
- | Lastly, the first three viewports use different shades for their '' | ||
- | For example, | ||
- | |||
- | <code ini> | ||
- | |||
- | means the this viewport will use a random ((the ' | ||
- | |||
- | If we want to color more presicely the '' | ||
- | |||
- | <code ini> | ||
- | |||
- | This gives three possibilities for our random color: yellow, cyan and magenta. | ||
- | |||
- | Finally, let's have a look to our cameras. | ||
- | |||
- | <code ini> | ||
- | FrustumWidth | ||
- | FrustumHeight = @Display.ScreenHeight | ||
- | FrustumFar | ||
- | FrustumNear | ||
- | Position | ||
- | |||
- | [Camera2] | ||
- | FrustumWidth | ||
- | FrustumHeight = 300.0 | ||
- | FrustumFar | ||
- | FrustumNear | ||
- | Position | ||
- | |||
- | [Camera3@Camera1]</ | ||
- | |||
- | We basically define their [[wp> | ||
- | //NB: As we're using '' | ||
- | |||
- | Note that the '' | ||
- | //NB: When inheritance is used for a whole section, it's written this way: [MySection@ParentSection].// | ||
- | Why using two different cameras then? Only so as to have two physical entities: when we alter properties of '' | ||
- | |||
- | We can also notice that '' | ||
- | //NB: When inheritance is used for a value, it's written like this '' | ||
- | The parent' | ||
- | |||
- | Lastly we notice that our '' | ||
- | This means '' | ||
- | ===== Recursos ===== | ||
- | |||