Exemple #1
0
func (me *Controller) applyTranslation() {
	if me.autoUpdate {
		var mlook, mtrans unum.Mat4
		mlook.Orient(&me.dir, &me.UpAxis)
		mtrans.Translation(me.Pos.Negated())
		me.thrApp.mat.SetFromMult4(&mlook, &mtrans)
	}
}
//	Updates the internal 4x4 transformation matrix for all transformations of the specified
//	node and child-nodes. It is only this matrix that is used by the rendering runtime.
func (me *Scene) ApplyNodeTransforms(nodeID int) {
	if me.allNodes.IsOk(nodeID) {
		//	this node
		var matParent, matTrans, matScale, matRotX, matRotY, matRotZ unum.Mat4
		matScale.Scaling(&me.allNodes[nodeID].Transform.Scale)
		matTrans.Translation(&me.allNodes[nodeID].Transform.Pos)
		matRotX.RotationX(me.allNodes[nodeID].Transform.Rot.X)
		matRotY.RotationY(me.allNodes[nodeID].Transform.Rot.Y)
		matRotZ.RotationZ(me.allNodes[nodeID].Transform.Rot.Z)
		if me.allNodes[nodeID].parentID < 0 {
			matParent.Identity()
		} else {
			matParent.CopyFrom(&me.allNodes[me.allNodes[nodeID].parentID].Transform.thrApp.matModelView)
		}
		me.allNodes[nodeID].Transform.thrApp.matModelView.SetFromMultN(&matParent, &matTrans /*me.Other,*/, &matScale, &matRotX, &matRotY, &matRotZ)
		//	child-nodes
		for i := 0; i < len(me.allNodes[nodeID].childNodeIDs); i++ {
			me.ApplyNodeTransforms(me.allNodes[nodeID].childNodeIDs[i])
		}
		me.allNodes[nodeID].thrApp.bounding.full.Clear()
		me.allNodes[nodeID].thrApp.bounding.self.Clear()
		if Core.Libs.Meshes.IsOk(me.allNodes[nodeID].Render.meshID) {
			me.applyBounds(nodeID, &Core.Libs.Meshes[me.allNodes[nodeID].Render.meshID].raw.bounding)
		} else {
			//	this node has no geometry of its own but its child-nodes might
			me.applyBounds(nodeID, nil)
		}
	}
}