Difference between revisions of "Matrix:transformPoint"

From GiderosMobile
(removed language stuff+)
(added example)
Line 4: Line 4:
  
 
=== Description ===
 
=== Description ===
Transforms the matrix.
+
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">
 
<source lang="lua">
 
Matrix:transformPoint()
 
Matrix:transformPoint()
 +
</source>
 +
 +
=== 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'''
 +
<source 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
 
</source>
 
</source>
  
 
{{Matrix}}
 
{{Matrix}}

Revision as of 18:56, 16 March 2022

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