[VisualWorks top] [Lecture] [OOA/OOD] [Jun] [Bibliography] [Quotations]

In Praise of Learning: Jun


「じゅん」

contents
  1. FAQ
  2. 幾何 (Geometry)
  3. 位相 (Topology)
  4. OpenGL
  5. VRML
  6. Solid Model
  7. 「じゅん」が持っているおいしい機能

FAQ

「じゅん」ってなに?
3次元グラフィックスにおける高機能アプリケーションフレームワークの一つ。幾何操作と位相操作を合わせ持つオブジェクト指向の3次元グラフィックライブラリおよびアプリケーションフレームワーク。 3次元形状の変形操作などを矛盾なく行うためには,位相要素を扱えることが不可欠であり、しかも、これができるものは高価。
なにができるの?
3次元グラフィックアプリケーションの開発。OpenGL などのライブラリが持つ原始的な機能を包み込み、気軽に利用できる。
どうして作ったの?
プログラムが数値や文字の処理すなわち記号処理をするものだけという偏見からの脱却を目ざして構築されている。 フリーソフトウェア「じゅん」(公開版) を参照。
ワタシのパソコンで動くの?
OpenGL (または Mesa) 必須。16bitカラー以上が表示可能であること。なるべく高速なマシン。余りあるメモリ。大きく高速なディスク。
Smalltalk 版
VisualWorks 2.5 以上を要する。非商用版の VisualWorks Non-Commercial 3.0, 3.1 でも動く。 MacOS,Windows95/98/NT, Linux (RedHat5.2相当) 要。
Java 版
JDK 1.1 (1.1.6以降) を要する。JDK は Sun のサイトから取得可能。 Windows95/98/NT, Linux (RedHat5.2相当) 要。Macintosh 版 (MRJ 上で動く) は近日堂々公開予定!
いくらするの?
GPL に則ったフリーソフトウェア兼オープンソース・ソフトウェア。しかも開発環境も無償で入手可能であるので、最低限のネットワーク使用料 (電話代と電気代) だけで始めることができる。
最新情報は?
フリーソフトウェア「じゅん for Smalltalk」:位相と幾何を合わせ持つ3次元グラフィックライブラリ を参照。
ちなみに……
ちなみに、 青木淳の名前は「あつし」であって「じゅん」ではありません。

「VisualWorks Smalltalk V2.0」用の3Dグラファライブラリ「じゅん(Jun)」の readme ftp://sraswa.sra.co.jp/pub/lang/smalltalk/jun/VisualWorks2.0/README.txt より。
だいたい、字が違います。じゃ、どんな字を書くんだって? 教えたげません。;-P

[contents]


幾何 (Geometry)

右手座標系
♪何事も 困ったときは 右手系

反時計回り
♪何事も 回転方向 反時計

座標 (point)

座標 P(x, y, z)
ベクトル P(x, y, z)

generality
        class           generality
        --------------------------
        Jun3dPoint      220
        Jun2dPoint      200
        Point           180
        JunAngle        120
        Double           90
        Float            80
        FixedPoint       70
        Fraction         60
        Integer          40
        SmallInteger     20

[contents]

座標変換 (transformation)

アフィン変換 (affine transformation)
投影変換 (projective transformation)
投影変換 の特殊な場合が アフィン変換
x1 = ax0 + dy0 + gz0 + l
y1 = bx0 + ey0 + hz0 + m
z1 = cx0 + fy0 + iz0 + n
のとき、
横形式
横形式(行ベクトル)で扱う。ただし
| a d g | 
| b e h | ~~ 0 (行列式 T の転置行列 は 0 でないものとする)
| c f i | 
同時座標
変換行列を3×3から,4×4の行列に拡張して,一次元追加した同次座標

点P0と点P1の位置ベクトル[x0 y0 z0 1]と[x1 y1 z1 1]をP0P1とし,変換行列をTとすれば,座標変換は下記の式で表されます。

P1 = P0T

加法は可換だが、積法は非可換であることに注意。

  "-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- "!
拡大・縮小 (scaling)
変換行列
拡大縮小の変換行列
        a > 1 : X軸において拡大
    1 > a > 0 : X軸において縮小
    0 > a     : X軸において反転(YZ平面に対して反転)
    
        e > 1 : Y軸において拡大
    1 > e > 0 : Y軸において縮小
    0 > e     : Y軸において反転(XZ平面に対して反転)
    
        i > 1 : Z軸において拡大
    1 > i > 0 : Z軸において縮小
    0 > i     : Z軸において反転(XY平面に対して反転)
典型的なコード
    | characterN pointP aTransformation xyzAxes compoundObject |
    characterN := JunOpenGL3dObject characterN.
    characterN paint: ColorValue magenta.
    characterN := characterN translatedBy: characterN boundingBox corner.
    pointP := JunOpenGL3dObject cube.
    pointP := pointP scaledBy: 0.1.
    pointP := pointP translatedBy: characterN boundingBox corner.
    aTransformation := Jun3dTransformation scale: 1.5 , 1.5 , 1.5.
    characterN := characterN transform: aTransformation.
    pointP := pointP transform: aTransformation.
    xyzAxes := JunOpenGL3dObject axes.
    xyzAxes := xyzAxes scaledBy: 3.5.
    compoundObject := JunOpenGL3dCompoundObject new.
    compoundObject add: characterN.
    compoundObject add: xyzAxes.
    compoundObject add: pointP.
    compoundObject show.

cf.) JunOpenGL3dObject cube. で単位ベクトルが得られる。ほかに box というメッセージがある。

平行移動 (translation) (加法)
変換行列
平行移動の変換行列

典型的なコード
    | characterN pointP aTransformation xyzAxes compoundObject |
    characterN := JunOpenGL3dObject characterN.
    characterN paint: ColorValue magenta.
    characterN := characterN translatedBy: characterN boundingBox corner.
    pointP := JunOpenGL3dObject cube.
    pointP := pointP scaledBy: 0.1.
    pointP := pointP translatedBy: characterN boundingBox corner.
    aTransformation := Jun3dTransformation translate: 0 , 0 , 1.2.
    characterN := characterN transform: aTransformation.
    pointP := pointP transform: aTransformation.
    xyzAxes := JunOpenGL3dObject axes.
    xyzAxes := xyzAxes scaledBy: 3.5.
    compoundObject := JunOpenGL3dCompoundObject new.
    compoundObject add: characterN.
    compoundObject add: xyzAxes.
    compoundObject add: pointP.
    compoundObject show.
    Transcript cr; show: pointP boundingBox center printString
回転 (rotation)
変換行列
X 軸を中心に回転 X軸回転の変換行列

Y 軸を中心に回転 Y軸回転の変換行列

Z 軸を中心に回転 Z軸回転の変換行列

典型的なコード (X 軸を中心に回転)
    | characterN pointP aTransformation xyzAxes compoundObject |
    characterN := JunOpenGL3dObject characterN.
    characterN paint: ColorValue magenta.
    characterN := characterN translatedBy: characterN boundingBox corner.
    pointP := JunOpenGL3dObject cube.
    pointP := pointP scaledBy: 0.1.
    pointP := pointP translatedBy: characterN boundingBox corner.
    aTransformation := Jun3dTransformation rotateX: (JunAngle fromDeg: 30).
    characterN := characterN transform: aTransformation.
    pointP := pointP transform: aTransformation.
    xyzAxes := JunOpenGL3dObject axes.
    xyzAxes := xyzAxes scaledBy: 3.5.
    compoundObject := JunOpenGL3dCompoundObject new.
    compoundObject add: characterN.
    compoundObject add: xyzAxes.
    compoundObject add: pointP.
    compoundObject show.
    Transcript cr; show: pointP boundingBox center printString
複数軸を中心に回転 (X軸,Y軸,Z軸) (強調文字部分のみ) (積法)
    aTransformation := ((Jun3dTransformation rotateX: (JunAngle fromDeg: 30))
            product: (Jun3dTransformation rotateY: (JunAngle fromDeg: 30)))
            product: (Jun3dTransformation rotateZ: (JunAngle fromDeg: 30)).

座標変換の順序すなわち変換行列の結合順序が重要!
X軸,Y軸,Z軸と回転させるのと,Z軸,Y軸,X軸と回転させるのでは,結果が丸っ切り異なる!

cf.) JunAngle のインスタンスは高速化のため、sinθ, cosθの値を cache している。

任意の軸を中心に回転
    aLine := Jun3dLine from: 0 , 0 , 0 to: characterN boundingBox corner.
    aTransformation := Jun3dTransformation rotate: (JunAngle fromDeg: 30)
                around: aLine.
せん断 (shearing) (XY平面,YZ平面,XZ平面などの平面上の点を固定して,それ以外の点を軸に平行に移動させる変換)
変換行列
せん断

典型的なコード
    | characterN pointP aTransformation xyzAxes compoundObject |
    characterN := JunOpenGL3dObject characterN.
    characterN paint: ColorValue magenta.
    characterN := characterN translatedBy: characterN boundingBox corner.
    pointP := JunOpenGL3dObject cube.
    pointP := pointP scaledBy: 0.1.
    pointP := pointP translatedBy: characterN boundingBox corner.
    aTransformation := Jun3dTransformation 
            fromArray: #(1 0 0 0 0 1 0 0 0 0.5 1 0 0 0 0 1).
    characterN := characterN transform: aTransformation.
    pointP := pointP transform: aTransformation.
    xyzAxes := JunOpenGL3dObject axes.
    xyzAxes := xyzAxes scaledBy: 3.5.
    compoundObject := JunOpenGL3dCompoundObject new.
    compoundObject add: characterN.
    compoundObject add: xyzAxes.
    compoundObject add: pointP.
    compoundObject show.
    Transcript cr; show: pointP boundingBox center printString
文字Nが Y軸方向に傾いて、さらに引き延ばされる。
変換行列を生成する配列は 横形式 で与えること。
| 1 0   0 0 |
| 0 1   0 0 |
| 0 0.5 1 0 |
| 0 0   0 1 |

[contents]

境界箱 (bounding box)

多面体を包含し,かつ座標軸に平行な最少の直方体のこと。 境界箱を表現するクラスは,JunBoundingBoxのサブクラス群

2つの境界箱の関係
Zソート
多面体をディスプレイに表示するために3Dから2Dに変換する際に,その多面体の境界箱の6つの平面の中のZ軸と垂直になる(手前の)平面をみて,他の多面体との前後関係を判断する。
体積(面積)
 

[contents]

座標系 (coordinate system)

座標系
右手座標系(right hand coordinate system) & 反時計回り(CCW: counterclockwise rotation)
平行・回転移動やスケーリング
P'=M0・P + M1
これらの変換を繰り返し行うために……三次元の点を四次元の点として表す同次座標
ある点P(x0, y0, z0)の幾何変換
[ x y z H ] = [ x0 y0 z0 1 ]変換行列
ただし,X軸回転の変換行列

[contents]

直線 (line)

直線の表現
座標型
P1, P2
関数型
y = kx + a
z = hx + b
方程式型
(x - x1) / l = (y - y1) / m = (z - z1) / n
媒介変数型
x = x0 + ft
y = y0 + gt
z = z0 + ht

任意の2点 P1(a, b, c), P2(d, e, f)を通る直線の式は

    x = a + ( d - a )t
    y = b + ( e - b )t
    z = c + ( f - c )t
    | x |   | a |     | d - a |
    | y | = | b | + t | e - b |
    | z |   | c |     | f - c |
媒介変数型から関数型や方程式型へ変換
媒介変数型の直線
    x = x0 + f0t
    y = y0 + g0t
    z = z0 + h0t
のとき、 関数型の各変数
    k = g0 / f0, a = y0 - x0g0 / f0,
    h = h0 / f0, b = z0 - x0h0 / f0
方程式型の各変数
    x1 = x0, y1 = y0, z1 = z0,
    l = f, m = g, n = h

[contents]

平面 (plane)

平面の定義

方程式型の ax + by + cz + d = 0 を表現として採用。

任意の3点 P1(a, b, c), P2(d, e, f), P3(g, h, i)を通る平面
    | x - a  y - b  z - c |
    | d - a  e - b  f - c | = 0
    | g - a  h - b  i - c |
平面上の任意の点 P(x1, y1 ,z1)と,平面の法線となる直線 l が
x = x0 + ft
y = y0 + gt
z = z0 + ht
で与えられているとき、平面の式は、
fx + gy + hz - (fx1 + gy1 + hz1) = 0
典型的なコード (同一直線上にない任意の3点を通る)
    | a3dObject polygon vertex model |
    a3dObject := JunOpenGL3dObject axes.
    polygon := JunOpenGL3dPolygon vertexes: (Array
                    with: 0.8 , 0.8 , 0
                    with: -0.8 , 0.8 , 0
                    with: -0.8 , -0.8 , 0
                    with: 0.8 , -0.8 , 0).
    polygon paint: ColorValue yellow.
    polygon stipple: (JunOpenGLStipple halftone: 0.5).
    a3dObject add: polygon.
    vertex := JunOpenGL3dVertex point: -0.6 , -0.6 , 0.
    vertex paint: ColorValue cyan.
    vertex size: 6.
    a3dObject add: vertex.
    vertex := JunOpenGL3dVertex point: 0 , 0.6 , 0.
    vertex paint: ColorValue cyan.
    vertex size: 6.
    a3dObject add: vertex.
    vertex := JunOpenGL3dVertex point: 0.6 , 0 , 0.
    vertex paint: ColorValue cyan.
    vertex size: 6.
    a3dObject add: vertex.
    a3dObject name: 'example'.
    model := JunOpenGLDisplayModel new.
    model displayObject: a3dObject.
    model open.
    ^plane
典型的なコード (平面上の点と平面の法線となる直線が与えられている)
    | a3dObject polygon polyline vertex model point plane line |
    point := (Jun3dLine from: 0.5 , 0.5 , 0 to: 0 , 0 , 1) atT: 0.8.
    line :=Jun3dLine from: (0 , 0 , 0) to: (1 , 1 , 1).
    plane := JunPlane on: point vertical: line.
    a3dObject := JunOpenGL3dObject axes.
    polygon := JunOpenGL3dPolygon vertexes: (Array
                    with: 0 , 1 , 0
                    with: 1 , 0 , 0
                    with: 0.5, -0.5, 1
                    with: -0.5, 0.5, 1).
    polygon paint: ColorValue yellow.
    polygon stipple: (JunOpenGLStipple halftone: 0.5).
    a3dObject add: polygon.
    vertex := JunOpenGL3dVertex point: point.
    vertex paint: ColorValue cyan.
    vertex size: 6.
    a3dObject add: vertex.
    polyline := JunOpenGL3dPolyline vertexes: (Array with: line from with: line to).
    polyline paint: ColorValue magenta.
    polyline lineWidth: 2.
    a3dObject add: polyline.
    a3dObject name: 'example'.
    model := JunOpenGLDisplayModel new.
    model displayObject: a3dObject.
    model open.
    ^plane

[contents]

オイラー角 (eulerian angles)

オイラー角と呼ばれるφ,θ,ψの3つの角で旧座標系に対する新座標系の位置を表現する。

グローバル座標系(ワールド座標系)
すべてのモデルが共通して持つ座標系 などに有利。
ローカル座標系
個々のモデルが独自に持つ座標系 などに有利。
典型的なコード (点(1, 0, 0)と点(0, 1, 0)を通る直線を X-Y-Z のオイラー角でφ = 1,θ = 2,ψ = 3(単位:ラジアン)ずつ回転した直線を求める)
    | line1 line2 eulerianAnglesXYZ aTransformation a3dObject polyline model |
    line1 := Jun3dLine from: 1 , 0 , 0 to: 0 , 1 , 0.
    eulerianAnglesXYZ := JunEulerianAnglesXYZ
                phi: 1 
                theta: 2 
                psi: 3. 
    line2 := line1 transform: eulerianAnglesXYZ asTransformation.
    aTransformation := Jun3dTransformation scale: 1.2 , 1.2 , 1.2.
    a3dObject := JunOpenGL3dObject axes transform: aTransformation.
    polyline := JunOpenGL3dPolyline vertexes: (Array with: line1 from with: line1 to).
    polyline paint: ColorValue magenta.
    polyline lineWidth: 2.
    a3dObject add: polyline.
    polyline := JunOpenGL3dPolyline vertexes: (Array with: line2 from with: line2 to).
    polyline paint: ColorValue cyan.
    polyline lineWidth: 2.
    a3dObject add: polyline.
    a3dObject name: 'example'.
    model := JunOpenGLDisplayModel new.
    model displayObject: a3dObject.
    model open
典型的なコード (同じ直線をZ-Y-Zのオイラー角でφ=1,θ=2,ψ=3(単位:ラジアン)ずつ回転した直線を求める)
    | line1 line2 eulerianAnglesXYZ aTransformation a3dObject polyline model |
    line1 := Jun3dLine from: 1 , 0 , 0 to: 0 , 1 , 0.
    eulerianAnglesXYZ := JunEulerianAnglesXYZ
                phi: 1 
                theta: 2 
                psi: 3. 
    line2 := line1 transform: eulerianAnglesZYZ asTransformation.
    aTransformation := Jun3dTransformation scale: 1.2 , 1.2 , 1.2.
    a3dObject := JunOpenGL3dObject axes transform: aTransformation.
    polyline := JunOpenGL3dPolyline vertexes: (Array with: line1 from with: line1 to).
    polyline paint: ColorValue magenta.
    polyline lineWidth: 2.
    a3dObject add: polyline.
    polyline := JunOpenGL3dPolyline vertexes: (Array with: line2 from with: line2 to).
    polyline paint: ColorValue cyan.
    polyline lineWidth: 2.
    a3dObject add: polyline.
    a3dObject name: 'example'.
    model := JunOpenGLDisplayModel new.
    model displayObject: a3dObject.
    model open
オイラー角の値が同じでも、回転順序が異なると丸っきり違う結果になる。
    | eulerianAnglesZYZ eulerianAnglesXYZ |
    eulerianAnglesZYZ := JunEulerianAnglesZYZ
                phi: 1
                theta: 2
                psi: 3.
    eulerianAnglesXYZ := eulerianAnglesZYZ asEulerianAnglesXYZ.
    ^eulerianAnglesXYZ asArrayOfRadians

    --> #(2.0689271969251d 0.51357650883364d -1.451284239176d)

[contents]


位相 (Topology)

オイラー操作 (eulerian operator)

幾何操作 (geometric operator)

大域操作 (global operator)

[contents]


OpenGL

OpenGL表示モデル (OpenGL display model)

視線
視体積 (viewing volume)
視体積
視点から注視点方向へ無限に延びる角錐を想定する。 角錐の高さを有限化するために、その角錐を前方と後方に位置を決めて切り落とす。 残った角錐台形が視体積を現す。 これらは、Projector にまとめられている。 Projector の様子は、 ViewPort から覗くことができる。 Projector は以下の情報を保持している。

ビューファインダは,三次元空間を二次元にレンダリングして表示する、 Visual Debugger である。

ビューファインダの操作
zoom (pan)
広角 (望遠) レンズに取り替える。視野角が変更される。視点、注視点は移動しない。
dolly
視点が注視点との直線上を移動する。注視点との距離は保たれる。視野角は変更されない。
tumble (grab)
注視点を動かさないで、注視点-視点の距離を保ちつつ、視点を動かす (視点-注視点の方向が変わる)。視点は距離を半径とする球体の表面上を移動することになる。視野角は変更されない。
track
注視点-視点の距離と方向を保ちつつ、視点を動かす。注視点もセットで動くことになる。視野角は変更されない。 dolly はこれの特殊な形態 (移動方向が注視-視点の直線上に固定される)。
up vector
視点から注視点への方向を中心軸として回転する。チルト効果が得られる。
view factor
視体積の高さ (視点-注視点方向の長さ) を変更する。注視点を中心に伸縮する。
Perspective Projection
円錐形の視野。
Parallel Projection
直方体の視野。
Solid Presentation
ソリッド表示。
Wireframe Presentation
ワイヤフレーム表示。
hidden-line Presentation
陰線消去されたワイヤフレーム表示。
ビューファインダ行列
ビューファインダ (上) とビューポート (下)

ビューポート
手前から伸びている直線において、黄色が near より手前、青色が near から注視点まで、マゼンタが注視点から far までを表す。
四面体の中心から突き出ている 3 つの矢印は、赤: X 軸, 緑: Y 軸, 青: Z 軸。矢頭が向いている方が正方向 (右手系だから)。
黄色の矩形はビューファインダで見える窓の大きさ (矢印は 赤: X 軸, 緑: Y 軸)。青の球体は OpenGL オブジェクト (ビューファインダで観ているオブジェクト) が取り得る最大限の領域。
スティップルではなくてトランスペアレンシーを掛けているのでスムーズに見えている。

[contents]

OpenGL流動モデル (OpenGL flux model)

OpenGLオブジェクトを紙芝居のように切り替えながら表示することで,アニメーションのような表示 (フラックス表示) を行うことができるビューファインダ。ただし、時間軸は持っていない。

JunOpenGLFluxObject (フラックスオブジェクト) をフラックス表示する。

フラックスメイカー(JunOpenGLFluxMaker)はセグメント群からフラックスオブジェクトを生成する。

フラックスオブジェクト
  1. 複数の基本図形からなる複合オブジェクトを格納 (JunOpenGLFluxMutableObject)
    この場合は、複合オブジェクトを構成する基本図形をフラックス表示する。
  2. 一つの基本図形と複数の座標変換行列を格納 (JunOpenGLFluxMutableObject)
    アニメーション。
  3. 一つの基本図形のみを格納 (JunOpenGLFluxImmutableObject)
    Immutable の名のとおり、動かない
  4. 上記1〜3を複数格納するオブジェクト (JunOpenGLFluxObject)
    アニメーション。

QuickTime Movie Player に似たユーザ・インタフェースを持つ。

[contents]

OpenGLグラファ (OpenGL grapher)

Xグラファ

[contents]

OpenGLライト (OpenGL light)

点光源 (Spot Light)
指定された座標点に配置され、全方向に向かって一様に放射される光。
平行光線 (Parallel Light)
無限遠からブジェクトに対して平行に照射される光。
環境光 (Ambient Light)
いわばエーテル。
拡散光
オブジェクトに照射された光が反射して、すべての方向に均一に散乱する光。そのため、拡散光による光は視点がどこにあっても同じ照度で見える。
鏡面光
オブジェクトに照射された光が、特定の方向に強く反射するような光の成分。鏡面光による光は、光源と視点、オブジェクトの位置関係によって照度が変わる。
環境光
光源からの光が何度も反射を繰り返して散乱し、光源の方向が特定できなくなった光。環境光が設定されると、すべてのオブジェクトはその向きに関係なく環境光で照らされる。環境光によって照射された場合、オブジェクトに反射した光はすべての方向に均一に散乱する。
放射光
オブジェクト自体から放射される光。光源からの影響を受けません。放射光は、オブジェクトの材質の属性としてRGB値で設定する。

光源は 4 つまで持てる。 OpenGL では 8 個までの光源を持つことができるが、残りの 4 個は放射光に割り当てることができる。

[contents]

OpenGLオブジェクト (OpenGL object)

OpenGLオブジェクトには、基本図形 (点: vertex と線: line, polyline, polyline loop と多角形: polygon)、複数の基本図形を組み合わせて操作するための複合オブジェクト (Compound Object) や、座標変換を効率よく行うための座標変換オブジェクト (Transformed Object) などがある。

[contents]

OpenGLピッカー (OpenGL picker)

2 次元の世界から 3 次元の物体を選択する方法。 2次元の非表示領域を作り、そこに各 OpenGL オブジェクトを一意に色分けして描画する。マウスポイントの色を調べれば、どのオブジェクトを選択したかが判る。注視点方向に向かって奥のものから描いて行けば、手前のものがあとに描かれることになる。よって、見えていないものは選べない。

[contents]

OpenGLプロジェクション (OpenGL projection)

射影変換 -> 視界や視体積の種類などを決定する

透視法射影
視体積がピラミッド型の錘台になる。オブジェクトが視点から離れるほど小さく投影される。 near で分断される切り口を決める際、距離と 4 点を指定する (左右非対称の錘台を定義可能) 方法、距離と視野角、および切り口の縦横比を指定する方法があり、射影行列のパラメータとしては、後者のほうが少ない。
正射影
オブジェクトの大きさは視点からの距離の影響を受けない。 無限遠方からオブジェクトを眺めている。

[contents]

OpenGL表現コンテキスト (OpenGL rendering context)

OpenGL オブジェクトを描画するための文脈/環境。描画面に対し、魔法の管があり、管に付属するボタンを操作し、そこに OpenGL オブジェクトを流し込めば描画される。 2 次元グラフィクスでの GraphicsContext に相当する。 displayOn: に対応して renderOn: が用意されている。

管に付属するボタン

表示面の Window クラス以下、非表示面の Pixmap クラス、ビューの JunOpenGLDisplayView クラス、表示部品の JunWinDIBSection クラス以下、 JunOpenGLRetainedMedium クラスのインスタンスが renderingContext を解する。

 実際には、ユーザが表現コンテキストに対して直接属性の設定を行ったり、表現コンテキストを使 って描画を行ったりすることはありません。種設定はOpenGLオブジェクトやプロジェクタ (Projector)に対して行い、オブジェクトの描画はオブジェクトに対してrenderOn:を送ったり、プ ロジェクタに対してproject:on:を送ったりして行うことになります。
OpenGL rendering context

[contents]

OpenGLテクスチャ (OpenGL texture)

テクセル (texel)
テクスチャ要素
クランプ (clamp)
テクスチャマッピングを反復しない。テクスチャ座標において、個々の座標値は最大値 1.0、最小値 0.0 に設定される。対象物の残りの面は、テクスチャ境界の色で塗りつぶされる。
ミップマップ (mipmap)
単一のテクスチャを指定して、異なる解像度で使用できる。小さな画像に対し、大きなテクスチャを写像させなくて佳い。内部的にあらかじめフィルタ処理されたテクスチャ・マップを作成する。ただし、使用できるテクスチャのサイズは制限される。
最近 フィルタ (nearest filter)
ピクセルの中心に最も近い座標を持つテクセルが選択される。実行効率は佳いがジャギーが発生する場合がある。
加重線形平均 フィルタ (linear filter)
ピクセルの中心に最も近い 2 * 2 テクセル配列の加重線形平均が選択される。スムーズな表示が得られる。
変調と混合
OpenGL では、テクスチャから得られた色をオブジェクトの面に塗りつける方法と、テクスチャから得られた色と、それを塗りつける場所の色と混合させることができる。
地球のテクスチャ
    | anObject anImage aTexture |
    anObject := JunOpenGL3dObject sphere: 10.
    anImage := JunOpenGLTexture imageEarth.
    aTexture := JunOpenGLTexture image: anImage.
    anObject texture: aTexture.
    anObject show.
    ^anObject
繰り返しあり
    | vertexes aPolygon anImage aTexture xyzAxes compoundObject |
    vertexes := OrderedCollection new.
    vertexes add: 0.0d , 0.0d , 0.0d; 
            add: 0.0d , 1.0d , 0.0d; 
            add: 0.0d , 1.0d , 1.0d; 
            add: 0.0d , 0.0d , 1.0d.
    aPolygon := JunOpenGL3dPolygon vertexes: vertexes asArray.
    aPolygon paint: ColorValue white.
    anImage := JunOpenGLTexture imageSmalltalkBalloon.
    aTexture := JunOpenGLTexture image: anImage.
    aTexture coordinates: (Array
            with: 0.0 , 0.0
            with: 2.0 , 0.0
            with: 2.0 , 2.0
            with: 0.0 , 2.0).
    aTexture repeat: true.
    "aTexture clamp: false."
    aPolygon texture: aTexture.
    xyzAxes := JunOpenGL3dObject axes.
    xyzAxes := xyzAxes scaledBy: 1.1.
    compoundObject := JunOpenGL3dCompoundObject new.
    compoundObject add: aPolygon.
    compoundObject add: xyzAxes.
    compoundObject show.
    ^aPolygon! !
繰り返しなし
    | vertexes aPolygon anImage aTexture xyzAxes compoundObject |
    vertexes := OrderedCollection new.
    vertexes add: 0.0d , 0.0d , 0.0d; 
            add: 0.0d , 1.0d , 0.0d; 
            add: 0.0d , 1.0d , 1.0d; 
            add: 0.0d , 0.0d , 1.0d.
    aPolygon := JunOpenGL3dPolygon vertexes: vertexes asArray.
    aPolygon paint: ColorValue white.
    anImage := JunOpenGLTexture imageSmalltalkBalloon.
    aTexture := JunOpenGLTexture image: anImage.
    aTexture coordinates: (Array
            with: 0.0 , 0.0
            with: 2.0 , 0.0
            with: 2.0 , 2.0
            with: 0.0 , 2.0).
    aTexture clamp: true.
    "aTexture repeat: false."
    aPolygon texture: aTexture.
    xyzAxes := JunOpenGL3dObject axes.
    xyzAxes := xyzAxes scaledBy: 1.1.
    compoundObject := JunOpenGL3dCompoundObject new.
    compoundObject add: aPolygon.
    compoundObject add: xyzAxes.
    compoundObject show.
    ^aPolygon! !
nearest
    | vertexes aPolygon anImage aTexture xyzAxes compoundObject |
    vertexes := OrderedCollection new.
    vertexes add: 0.0d , 0.0d , 0.0d; 
            add: 0.0d , 1.0d , 0.0d; 
            add: 0.0d , 1.0d , 1.0d; 
            add: 0.0d , 0.0d , 1.0d.
    aPolygon := JunOpenGL3dPolygon vertexes: vertexes asArray.
    aPolygon paint: ColorValue white.
    anImage := JunOpenGLTexture imageSmalltalkBalloon.
    aTexture := JunOpenGLTexture image: anImage.
    aTexture coordinates: (Array
            with: 0.0 , 0.0
            with: 1.0 , 0.0
            with: 1.0 , 1.0
            with: 0.0 , 1.0).
    aTexture nearest: true.
    aPolygon texture: aTexture.
    xyzAxes := JunOpenGL3dObject axes.
    xyzAxes := xyzAxes scaledBy: 1.1.
    compoundObject := JunOpenGL3dCompoundObject new.
    compoundObject add: aPolygon.
    compoundObject add: xyzAxes.
    compoundObject show.
    ^aPolygon! !
linear
    | vertexes aPolygon anImage aTexture xyzAxes compoundObject |
    vertexes := OrderedCollection new.
    vertexes add: 0.0d , 0.0d , 0.0d; 
            add: 0.0d , 1.0d , 0.0d; 
            add: 0.0d , 1.0d , 1.0d; 
            add: 0.0d , 0.0d , 1.0d.
    aPolygon := JunOpenGL3dPolygon vertexes: vertexes asArray.
    aPolygon paint: ColorValue white.
    anImage := JunOpenGLTexture imageSmalltalkBalloon.
    aTexture := JunOpenGLTexture image: anImage.
    aTexture coordinates: (Array
            with: 0.0 , 0.0
            with: 1.0 , 0.0
            with: 1.0 , 1.0
            with: 0.0 , 1.0).
    aTexture linear: true.
    aPolygon texture: aTexture.
    xyzAxes := JunOpenGL3dObject axes.
    xyzAxes := xyzAxes scaledBy: 1.1.
    compoundObject := JunOpenGL3dCompoundObject new.
    compoundObject add: aPolygon.
    compoundObject add: xyzAxes.
    compoundObject show.
    ^aPolygon! !
ミップマップ
    | vertexes aPolygon anImage aTexture xyzAxes compoundObject |
    vertexes := OrderedCollection new.
    vertexes add: 0.0d , 0.0d , 0.0d; 
            add: 0.0d , 1.0d , 0.0d; 
            add: 0.0d , 1.0d , 1.0d; 
            add: 0.0d , 0.0d , 1.0d.
    aPolygon := JunOpenGL3dPolygon vertexes: vertexes asArray.
    aPolygon paint: ColorValue white.
    anImage := JunOpenGLTexture imageSmalltalkBalloon.
    aTexture := JunOpenGLTexture image: anImage.
    aTexture coordinates: (Array
            with: 0.0 , 0.0
            with: 3.0 , 0.0
            with: 3.0 , 3.0
            with: 0.0 , 3.0).
    aTexture repeat: true.
    aTexture mipmap: true.
    aPolygon texture: aTexture.
    xyzAxes := JunOpenGL3dObject axes.
    xyzAxes := xyzAxes scaledBy: 1.1.
    compoundObject := JunOpenGL3dCompoundObject new.
    compoundObject add: aPolygon.
    compoundObject add: xyzAxes.
    compoundObject show.
    ^aPolygon! !

[contents]


VRML

VRML 1.0 変換 (VRML 1.0 conversion)

obsolete になりつつある……?

VRML 2.0 変換 (VRML 1.0 conversion)

全部の VRML オブジェクトが有効なわけではない。環境 (背景) やアニメーション機能など。 テクスチャとして貼り付けられた動画や音声。ノードにリンクした URL など (例えば跳び先が web ページだとか)。

VRML97.

[contents]


Solid Model

定義
任意の点に関して、その点が己の内部にあるか外部にあるかを答えることができるもの。 たとえば しかし 内部が充填されているものは Solid Model だが、内部が充填されていれば Solid Model であるというわけでは、輝くもの必ずしも金ならず。
仕様

B-reps (Boundary Repersentation)

あるものが空間上に存在するとは?「関係」である。

グラフを使って閉じる

パラメータ空間〜Bezier 曲面

位相要素
body (立体)
一つの立体を表す要素。次の五つの要素(shell (殻)、face (面)、loop (ループ)、edge (陵線)、vertex (頂点))から構成される。
shell (殻)
空間をある領域で囲むための要素。一つの body (立体) は、複数の shell (殻) で囲まれる連続した領域で表される。
face (面)
立体の表面を表す要素。一つの殻は、複数の面から成る連続した領域で表される。
loop (ループ)
面の境界を表す要素。一つの面は、その外側の境界として、一つ (以上)のループを保持する。 面の内部に穴 (ring) が存在するとき、その面が保持するループの数は、その穴の数だけ増える。
edge (陵線)
二つの面が交わった部分を表す要素 (直線または曲線)。一つのループは、複数の edge (陵線) で囲まれる連続した線で表される。
vertex (頂点)
二つ以上の陵線が交わった部分を表す要素 (点)。
要素

関係
        body
          |
        shell   loop
          |       |
        face 〜 edge 〜 vertex

これらの関係を知っている魔法の杖 half edge

[contents]

CSG (Constructive Solid Geometry)

あるものが空間上に存在するとは?「合成」である。

CSG

原始要素 (primitive: 球、角錐、円柱、円錐などなど) の合成

表示で死ぬほど苦労するので B-reps に変換してしまう。 ただし、一度 CSG から B-reps に変換してしまうと、その形状を定義したときの考え方が欠落してしまう (非可換)。
集合演算が高速。機械系 CAD が佳く採用している。

[contents]

Metaball

あるものが空間上に存在するとは?「」である。

メタボール
Metaball

非メタボール
JunOpenGL3dObject * 2

MetaballSolid (場) Metaball, 点と重み 1/d^n

set(G) XP -> R R -> Boolean operation X >= C
Σ(g∈G)[1/d(g・p)^n]

中心から遠ざかるほど濃度が薄くなっていく雲のようなものを考 え、同じ濃度の点の集まりをその物体の面と考えて表示するもの。 1個のときには球と変わらないが、2個以上になると互いに融合し 合って複雑な形状になる。3次元空間のある一点を中心に球状(も しくは楕円状)に広がる濃度分布によって定義される。中心点の 濃度が最大で、距離が離れるに従って減少し、ある1点を過ぎると 0になるようにする.中心点の濃度をウエイト、濃度が0になる距離 を有効半径と呼ぶが、この有効半径は実際に見えるメタボールの 半径を示すものではない。語源はメタモルフォーゼするという意味 から大阪大学の研究者がメタと名付けたものに、いつのまにかボ ールがついたもの。米国ではブロッビー(blobby)とよばれる。
http://www.3dcg.ne.jp/~momo/dic/
またもやメタボール
http://www-iti.enst-bretagne.fr/~ibanez/these/modeling.html

[contents]

Octree

あるものが空間上に存在するとは?「空間」である。

Octree
Octree

27tree
27Tree

Octree (2^3 分割)
27Tree (3^3 分割)
Octree ::= empty | full | node (Octree X .. X Octree)

[contents]


「じゅん」が持っているおいしい機能

examples プロトコルを持ち save メソッドを持つクラス
save メソッドを持つクラス
example プロトコルを持つクラス

[contents]


[VisualWorks top] [Lecture] [OOA/OOD] [Jun] [Bibliography] [Quotations]