5
- Posicionando Shapes
5.1
- O nó Transform
O
nó Transform
é um
caso especial dos Nós de Agrupamento, pois aplica uma transformação
geométrica a um grupo de elementos.
Transform
{
......addChildren
......removeChildren
......center 0 0 0
......children [ ]
......rotation 0 0
1 0
......scale 1 1 1
......scaleOrientation
0 0 1 0
......translation
0 0 0
......bboxCenter 0
0 0
......bboxSize -1
-1 -1
}
Os
campos translation,
rotation e scale executam
a translação, a rotação e o escalonamento
tridimensional, respectivamente.
Exemplo
21: Translação
#VRML
V2.0 utf8
Transform
{
......translation
2 0 0
......children [
............Shape
{
..................appearance
DEF Apare4 Appearance {
........................material
Material {
..............................diffuseColor
.79 .25 0.0
........................}
..................}
..................geometry Box
{ size 3 3 3 }
............}
............Shape
{
..................appearance
DEF Apare4 Appearance {
........................material
Material {
..............................diffuseColor
0.0 0.25 0.790
........................}
..................}
..................geometry Sphere
{ radius 2.1 }
............}
............Shape
{
..................appearance
DEF Apare4 Appearance {
........................material
Material {
..............................diffuseColor
0.0 0.79 0.79
........................}
..................}
..................geometry Sphere
{ radius 2.1 }
............}
......]
}
5.1.1
- Translação
O
campo translation
permite aplicar
uma translação a todos os nós incluídos no campo children
do nó. Cada
um dos elementos deste vetor corresponde à translação que os nós
irão efetuar em relação a cada um dos eixos, em que o 1º valor corresponde
ao eixo dos XX, o 2º ao eixo dos YY e o 3º ao eixo dos ZZ, como
seria de esperar.
Por
exemplo, suponha que se use o cone definido com o nome ConeAzul, que se encontra
na posição de origem (0, 0, 0), e que se pretende criar uma nova
instância deste objeto na posição (1,1,1). Para tal, basta aplicar
a transformação de translação que se segue à nova instância do nó
ConeAzul
criada pela
instrução USE.
Transform
{
......children USE
ConeAzul
......translation
1 1 1
}
Exemplo
22: Translação
#VRML
V2.0 utf8
Transform
{
......translation
2 0 0
......children [
............Shape
{
..................appearance
DEF Apare4 Appearance {
........................material
Material {
..............................diffuseColor
.79 .25 0.0
........................}
..................}
..................geometry Box
{ size 3 3 3 }
............}
......]
}
Transform
{
......translation
0 2 0
......children [
............Shape
{
..................appearance
DEF Apare4 Appearance {
........................material
Material {
..............................diffuseColor
0.0 0.25 0.790
........................}
..................}
..................geometry Sphere
{ radius 2.1 }
............}
......]
}
Transform
{
......translation
0 0 2
......children [
............Shape
{
..................appearance
DEF Apare4 Appearance {
........................material
Material {
..............................diffuseColor
0.0 0.79 0.79
........................}
..................}
..................geometry Sphere
{ radius 2.1 }
............}
......]
}
Exemplo
23: Translação
#VRML
V2.0 utf8
Group {
......children
[
............Shape
{
..................appearance
DEF Apare1 Appearance {
........................material
Material {
..............................diffuseColor
.32 .54 .26
..............................specularColor
.46 .46 .46
..............................ambientIntensity
.0933
..............................shininess
.51
........................}
..................}
..................geometry
Cylinder {
........................height
4.0
........................radius
0.2
..................}
............},
............Transform
{
..................translation
0.0 2.3 0.0
..................children
[
........................Shape
{
..............................appearance
DEF Apare2 Appearance {
....................................material
Material {
..........................................diffuseColor
.8 .51 .09
..........................................specularColor
.92 .43 .01
..........................................ambientIntensity
.117
..........................................shininess
.4
....................................}
..............................}
..............................geometry
Cone {
....................................height
0.6
....................................bottomRadius
0.2
..............................}
........................}
..................]
............}
......]
}
Exemplo
24: Translação
#VRML
V2.0 utf8
# The VRML 2.0 Sourcebook
# Copyright (c) 1997
# Andrea L. Ames, David R. Nadeau, and John L. Moreland
Group {
......children [
......# Ground
............Shape
{
..................appearance
DEF White Appearance {
........................material
Material { }
..................}
..................geometry
Box {
........................size
25.0 0.1 25.0
..................}
............},
............#
Left Column
............Transform
{
..................translation
-2.0 3.0 0.0
..................children
Shape {
........................appearance
USE White
........................geometry
Cylinder {
..............................radius
0.3
..............................height
6.0
........................}
..................}
............},
............#
Right Column
............Transform
{
..................translation
2.0 3.0 0.0
..................children
Shape {
........................appearance
USE White
........................geometry
Cylinder {
..............................radius
0.3
..............................height
6.0
........................}
..................}
............},
............#
Archway span
............Transform
{
..................translation
0.0 6.05 0.0
..................children
Shape {
........................appearance
USE White
........................geometry
Box {
..............................size
4.6 0.4 0.6
........................}
..................}
............}
......]
}
Exemplo
25: Translação
#VRML
V2.0 utf8
# The VRML 2.0 Sourcebook
# Copyright (c) 1997
# Andrea L. Ames, David R. Nadeau, and John L. Moreland
Group {
...... children [
...... # Ground
...... ...... Shape
{
...... ...... ...... appearance
DEF White Appearance {
...... ...... ...... ...... material
Material { }
...... ...... ...... }
...... ...... ...... geometry
Box {
...... ...... ...... ...... size 25.0
0.1 25.0
...... ...... ...... }
...... ...... },
...... ...... # First
archway
...... ...... # Left
Column
...... ...... DEF LeftColumn
Transform {
...... ...... ...... translation
-2.0 3.0 0.0
...... ...... ...... children
DEF Column Shape {
...... ...... ...... ...... appearance
USE White
...... ...... ...... ...... geometry
Cylinder {
...... ...... ...... ...... ...... radius
0.3
...... ...... ...... ...... ...... height
6.0
...... ...... ...... ...... }
...... ...... ...... }
...... ...... },
...... ...... # Right
Column
...... ...... DEF RightColumn
Transform {
...... ...... ...... translation
2.0 3.0 0.0
...... ...... ...... children
USE Column
...... ...... },
...... ...... # Archway
span
...... ...... DEF ArchwaySpan
Transform {
...... ...... ...... translation
0.0 6.05 0.0
...... ...... ...... children
Shape {
...... ...... ...... ...... appearance
USE White
...... ...... ...... ...... geometry
Box {
...... ...... ...... ...... ...... size 4.6
0.4 0.6
...... ...... ...... ...... }
...... ...... ...... }
...... ...... },
...... ...... # Second
archway
...... ...... Transform
{
...... ...... ...... translation
0.0 0.0 -2.0
...... ...... ...... children
[
...... ...... ...... ...... USE LeftColumn,
...... ...... ...... ...... USE RightColumn,
...... ...... ...... ...... USE ArchwaySpan
...... ...... ...... ]
...... ...... }
...... ]
}