Difference between revisions of "Matrix:transformPoint"

From GiderosMobile
m (Text replacement - "</source>" to "</syntaxhighlight>")
 
(3 intermediate revisions by 2 users not shown)
Line 1: Line 1:
 
__NOTOC__
 
__NOTOC__
<languages />
+
'''Available since:''' Gideros 2013.9<br/>
'''<translate>Available since</translate>:''' in development<br/>
+
'''Class:''' [[Matrix]]<br/>
'''<translate>Class</translate>:''' [[Special:MyLanguage/Matrix|Matrix]]<br/>
+
 
=== <translate>Description</translate> ===
+
=== Description ===
<translate>Transforms the matrix</translate>
+
Transforms the matrix to an array of points. This function applies the geometric transform represented by the Matrix to a specified array of points.
<source lang="lua">
+
<syntaxhighlight lang="lua">
Matrix:transformPoint()
+
Matrix:transformPoint()
</source>
+
</syntaxhighlight>
 +
 
 +
=== Example ===
 +
'''In this example we reset the player1 matrix by transforming it to the points (0, 0, 0) and we use the result for the lighting'''
 +
<syntaxhighlight lang="lua">
 +
-- game loop
 +
function LevelX:onEnterFrame(e)
 +
local matrix = self.player1.body:getTransform()
 +
local playerx, playery, playerz = self.player1.body:getTransform():getPosition()
 +
-- move player
 +
local force = 12
 +
if self.player1.isleft and not self.player1.isright then
 +
self.player1.body:applyLocalForceAtCenterOfMass(0, 0, force)
 +
elseif self.player1.isright and not self.player1.isleft then
 +
self.player1.body:applyLocalForceAtCenterOfMass(0, 0, -force)
 +
end
 +
-- position the player model along its body
 +
self.player1:setMatrix(matrix)
 +
-- the camera FPS style
 +
self.camera:lookAt(playerx+0.1, playery+24, playerz+4,
 +
playerx, playery, playerz+4
 +
)
 +
-- lighting
 +
local px, py, pz = matrix:transformPoint(0, 0, 0) -- hgy29
 +
Lighting.setLight(px, py+8, pz+1, 0.2)
 +
Lighting.setLightTarget(px, py, pz, 32, 20)
 +
--Compute shadows
 +
Lighting.computeShadows(self.scene)
 +
end
 +
</syntaxhighlight>
  
 
{{Matrix}}
 
{{Matrix}}

Latest revision as of 14:30, 13 July 2023

Available since: Gideros 2013.9
Class: Matrix

Description

Transforms the matrix to an array of points. This function applies the geometric transform represented by the Matrix to a specified array of points.

Matrix:transformPoint()

Example

In this example we reset the player1 matrix by transforming it to the points (0, 0, 0) and we use the result for the lighting

-- game loop
function LevelX:onEnterFrame(e)
	local matrix = self.player1.body:getTransform()
	local playerx, playery, playerz = self.player1.body:getTransform():getPosition()
	-- move player
	local force = 12
	if self.player1.isleft and not self.player1.isright then
		self.player1.body:applyLocalForceAtCenterOfMass(0, 0, force)
	elseif self.player1.isright and not self.player1.isleft then
		self.player1.body:applyLocalForceAtCenterOfMass(0, 0, -force)
	end
	-- position the player model along its body
	self.player1:setMatrix(matrix)
	-- the camera FPS style
	self.camera:lookAt(playerx+0.1, playery+24, playerz+4,
		playerx, playery, playerz+4
	)
	-- lighting
	local px, py, pz = matrix:transformPoint(0, 0, 0) -- hgy29
	Lighting.setLight(px, py+8, pz+1, 0.2)
	Lighting.setLightTarget(px, py, pz, 32, 20)
	--Compute shadows
	Lighting.computeShadows(self.scene)
end