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 07:07 (13 years ago)] – [Sumario] zera | es:orx:tutorials:viewport [2020/08/19 21: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 posición/ | ||
- | |||
- | 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 ===== | ||
- | |||
- | Como es usual, comenzaremos por cargar nuestro fichero de configuración, | ||
- | Por favor, referirse al [[main# | ||
- | |||
- | Sin embargo crearemos cuatro vistas esta vez. Nada realmente nuevo, por lo que solo necesitaríamos escribir este código. | ||
- | |||
- | <code c> | ||
- | orxViewport_CreateFromConfig(" | ||
- | orxViewport_CreateFromConfig(" | ||
- | orxViewport_CreateFromConfig(" | ||
- | |||
- | Como puedes ver solo mantenemos una referencia a una vista creada. Lo hacemos porque queremos interactuar con ella más adelante, pero no tocaremos las otras tres. | ||
- | |||
- | Vamos a ir directamente a nuestro código de actualización '' | ||
- | En primer lugar ajustaremos a nuestro soldado a la posición del ratón. Ya hemos visto tal cosa en el [[frame|tutorial de fotogramas]].\\ | ||
- | Aquí haremos exactamente los mismo y veremos como trabaja perfectamente con múltiples vistas.\\ | ||
- | Cuando el ratón no esta sobre la vista, '' | ||
- | |||
- | <code c> | ||
- | |||
- | if(orxRender_GetWorldPosition(orxMouse_GetPosition(& | ||
- | { | ||
- | orxVECTOR vSoldierPos; | ||
- | |||
- | orxObject_GetWorldPosition(pstSoldier, | ||
- | vPos.fZ = vSoldierPos.fZ; | ||
- | |||
- | orxObject_SetPosition(pstSoldier, | ||
- | }</ | ||
- | |||
- | Antes de interactuar directamente con la vista, juguemos un poco sus cámaras asociadas.\\ | ||
- | Podemos, por ejemplo, moverla, rotarla o hacer zoom. | ||
- | |||
- | Comenzemos por obtener nuestra primera cámara de la vista. | ||
- | |||
- | <code c> | ||
- | |||
- | OK, eso es fácil. Intentemos rotarla ((solo una parte del código se muestra, falta aún la lógica)). | ||
- | |||
- | <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 ===== | ||
- | |||