Chapter 8. Advanced Topics

Table of Contents

Viewport-relative content
Reacting to object proximity

This chapter contains additional information regarding the details of how scenes are rendered by the Popcode system.

Viewport-relative content

Content can be rendered in the frame of the viewport (rather than relative to the target) by specifying the relativeto of a transformable node (e.g. group). There are several options for this parameter.

Screen-relative content

Figure 8.1. Screen coordinate system

Screen coordinate system

By specifying relativeto="screen", the node (and its children) are displayed on the screen, in front of any other scene content. The coordinate system is shown in Figure 8.1, “Screen coordinate system”. It is centered on the center of the screen. The x-axis is positive in the right-hand direction, the y-axis is positive upwards, and the z-axis is positive towards the viewer.

When using screen-relative view:

  • Projection is orthographic - objects are the same size, regardless of their z position.

  • Objects are visible on the screen if their z-coordinate is between -10 and +10. Objects with higher z-coordinates will be displayed on top of objects with lower z-coordinates.

Example 8.1. Example of screen-relative content

	<group relativeto="screen" scale="0.2 0.2 1">
		<!-- a red plane -->
		<object type="primitives://plane.aro"
			position="-1 1 0" color="1 0 0 1"/>
		<!-- a green plane -->	
		<object type="primitives://plane.aro"
			position="0 0 1" color="0 1 0 1"/>

Camera-relative content

By specifying relativeto="camera", the node (and its children) are displayed relative to the center of the camera (effectively the center of the screen). This is useful for placing 3-D objects in front of the camera.

The coordinate system is arranged like this: the camera is centred on x, y, z = 0 with the x-axis is positive in the right-hand direction, the y-axis is positive upwards and the z-axis is positive towards the viewer. Thus, for content to be visible, it must be given some negative z position.

When using camera-relative view:

  • Projection is perspective - objects get smaller the further from the camera they are.

  • The viewable range depends on the viewing angle of the physcial camera.

  • Any object (or part of an object) closer to the camera than 0.1 will not be visible.

  • The scale of the coordinate system is equal to that of the target being viewed. Thus, a distance of 2 in camera-relative space is approximately equal to the height of the target.

Example 8.2. Example of camera-relative content

	<object type="primitives://plane.aro" relativeto="camera"
		position="0 0 -3" rotation="0 45 0" />