Jump to content

Recommended Posts

Posted

I wrote a 3x3 grid of planes treadmill. Currently the whole grid is repositioned if the camera would exiting the range of 1 tile size (from center to center). Obviously that just works if the camera if following n/s/w/e exactly (the tilable texture dictates) - if going diagonal the camera is located between the tiles and repositioning does "snap" the view/grid to the center of the treedmill again (very noticable because of the tilable texture).

 

question :

How do i rewrite the grid repositioning to find the exact opposite point ?

 

currently :


require("scripts/class")
require("scripts/constants/collision_const")
local class=CreateClass(...)
function class:CreateObject(model)
local object=self.super:CreateObject(model)
-- Load all the parts for the 3x3 grid
-- & setup
--[[
 \ | / patch 1, 2, 3
 - o - patch 4, 5, 6
 / | \ patch 7, 8, 9
--
--]]
local oldViewPos
local newViewPos
local patchPos
local viewLevel = -1.0
function object:Init()
 patchPos = Vec3(0,0,0)
 patchPos.y = patchPos.y + viewLevel
 self.model:SetPosition(patchPos)
 oldViewPos = self.model.position
 newViewPos = fw.main.camera.position
 -- preSetup w/o update
 --
 self.treadmill_patch1:SetPosition( Vec3(patchPos.x-340, patchPos.y, patchPos.z+340), 1)
 self.treadmill_patch2:SetPosition( Vec3(patchPos.x, patchPos.y, patchPos.z+340), 1)
 self.treadmill_patch3:SetPosition( Vec3(patchPos.x+340, patchPos.y, patchPos.z+340), 1)
 self.treadmill_patch4:SetPosition( Vec3(patchPos.x-340, patchPos.y, patchPos.z), 1)
 self.treadmill_patch5:SetPosition( Vec3(patchPos.x, patchPos.y, patchPos.z), 1)
 self.treadmill_patch6:SetPosition( Vec3(patchPos.x+340, patchPos.y, patchPos.z), 1)
 self.treadmill_patch7:SetPosition( Vec3(patchPos.x-340, patchPos.y, patchPos.z-340), 1)
 self.treadmill_patch8:SetPosition( Vec3(patchPos.x, patchPos.y, patchPos.z-340), 1)
 self.treadmill_patch9:SetPosition( Vec3(patchPos.x+340, patchPos.y, patchPos.z-340), 1)
end
object.treadmill_patch1=LoadModel("abstract::treadmill_patch1.gmf")
object.treadmill_patch2=LoadModel("abstract::treadmill_patch2.gmf")
object.treadmill_patch3=LoadModel("abstract::treadmill_patch3.gmf")
object.treadmill_patch4=LoadModel("abstract::treadmill_patch4.gmf")
object.treadmill_patch5=LoadModel("abstract::treadmill_patch5.gmf")
object.treadmill_patch6=LoadModel("abstract::treadmill_patch6.gmf")
object.treadmill_patch7=LoadModel("abstract::treadmill_patch7.gmf")
object.treadmill_patch8=LoadModel("abstract::treadmill_patch8.gmf")
object.treadmill_patch9=LoadModel("abstract::treadmill_patch9.gmf")
object.treadmill_patch1:SetCollisionType( COLLISION_SCENE, 0 )
object.treadmill_patch2:SetCollisionType( COLLISION_SCENE, 0 )
object.treadmill_patch3:SetCollisionType( COLLISION_SCENE, 0 )
object.treadmill_patch4:SetCollisionType( COLLISION_SCENE, 0 )
object.treadmill_patch5:SetCollisionType( COLLISION_SCENE, 0 )
object.treadmill_patch6:SetCollisionType( COLLISION_SCENE, 0 )
object.treadmill_patch7:SetCollisionType( COLLISION_SCENE, 0 )
object.treadmill_patch8:SetCollisionType( COLLISION_SCENE, 0 )
object.treadmill_patch9:SetCollisionType( COLLISION_SCENE, 0 )
--parent all parts to form the model
--
object.treadmill_patch1:SetParent(object.model)
object.treadmill_patch2:SetParent(object.model)
object.treadmill_patch3:SetParent(object.model)
object.treadmill_patch4:SetParent(object.model)
object.treadmill_patch5:SetParent(object.model)
object.treadmill_patch6:SetParent(object.model)
object.treadmill_patch7:SetParent(object.model)
object.treadmill_patch8:SetParent(object.model)
object.treadmill_patch9:SetParent(object.model)
--object handling will now be performed relative to its parent
--
object.treadmill_patch1:SetPosition(object.model.position, 1)
object.treadmill_patch1:SetRotation(object.model.rotation, 1)
object.treadmill_patch2:SetPosition(object.model.position, 1)
object.treadmill_patch2:SetRotation(object.model.rotation, 1)
object.treadmill_patch3:SetPosition(object.model.position, 1)
object.treadmill_patch3:SetRotation(object.model.rotation, 1)
object.treadmill_patch4:SetPosition(object.model.position, 1)
object.treadmill_patch4:SetRotation(object.model.rotation, 1)
object.treadmill_patch5:SetPosition(object.model.position, 1)
object.treadmill_patch5:SetRotation(object.model.rotation, 1)
object.treadmill_patch6:SetPosition(object.model.position, 1)
object.treadmill_patch6:SetRotation(object.model.rotation, 1)
object.treadmill_patch7:SetPosition(object.model.position, 1)
object.treadmill_patch7:SetRotation(object.model.rotation, 1)
object.treadmill_patch8:SetPosition(object.model.position, 1)
object.treadmill_patch8:SetRotation(object.model.rotation, 1)
object.treadmill_patch9:SetPosition(object.model.position, 1)
object.treadmill_patch9:SetRotation(object.model.rotation, 1)
function object:Update()
 local distance
 local range	 = 340
 patchPos = fw.main.camera:GetPosition()
 patchPos.y = viewLevel
 distance = PointDistance(oldViewPos, newViewPos)
 print(" distance : ", tonumber(distance) )
 if ( distance > range) then
 print("exiting range : ", tonumber(distance) )
-- ?!
-- ?!self.model:SetRotation(Vec3(0,self.model.rotation.y+fw.main.camera.rotation.y,0), 1)
-- ?!
 patchPos.x = newViewPos.x-range
 patchPos.z = newViewPos.z+range
 self.treadmill_patch1:SetPosition( patchPos, 1)
-- ?!self.treadmill_patch1:SetRotation(Vec3(0,fw.main.camera.rotation.y,0), 1)
 patchPos.x = newViewPos.x
 patchPos.z = newViewPos.z+range
 self.treadmill_patch2:SetPosition( patchPos, 1)
-- ?!self.treadmill_patch2:SetRotation(Vec3(0,fw.main.camera.rotation.y,0), 1)
 patchPos.x = newViewPos.x+range
 patchPos.z = newViewPos.z+range
 self.treadmill_patch3:SetPosition( patchPos, 1)
-- ?!self.treadmill_patch3:SetRotation(Vec3(0,fw.main.camera.rotation.y,0), 1)
 patchPos.x = newViewPos.x-range
 patchPos.z = newViewPos.z
 self.treadmill_patch4:SetPosition( patchPos, 1)
-- ?!self.treadmill_patch4:SetRotation(Vec3(0,fw.main.camera.rotation.y,0), 1)
 patchPos.x = newViewPos.x
 patchPos.z = newViewPos.z
 self.treadmill_patch5:SetPosition( patchPos, 1)
-- ?!self.treadmill_patch5:SetRotation(Vec3(0,fw.main.camera.rotation.y,0), 1)
 patchPos.x = newViewPos.x+range
 patchPos.z = newViewPos.z
 self.treadmill_patch6:SetPosition( patchPos, 1)
-- ?!self.treadmill_patch6:SetRotation(Vec3(0,fw.main.camera.rotation.y,0), 1)
 patchPos.x = newViewPos.x-range
 patchPos.z = newViewPos.z-range
 self.treadmill_patch7:SetPosition( patchPos, 1)
-- ?!self.treadmill_patch7:SetRotation(Vec3(0,fw.main.camera.rotation.y,0), 1)
 patchPos.x = newViewPos.x
 patchPos.z = newViewPos.z-range
 self.treadmill_patch8:SetPosition( patchPos, 1)
-- ?!self.treadmill_patch8:SetRotation(Vec3(0,fw.main.camera.rotation.y,0), 1)
 patchPos.x = newViewPos.x+range
 patchPos.z = newViewPos.z-range
 self.treadmill_patch9:SetPosition( patchPos, 1)
-- ?!self.treadmill_patch9:SetRotation(Vec3(0,fw.main.camera.rotation.y,0), 1)
 oldViewPos = fw.main.camera:GetPosition()
 oldViewPos.y = viewLevel
 end
end
--[[
function object:Collision(entity,position,normal,force,speed)
end
]]--
--[[
function object:UpdateMatrix()
 self.treadmill_patch1:SetPosition(self.model:GetPosition(0), 1)
 self.treadmill_patch1:SetRotation(self.model:GetRotation(0), 1)
 self.treadmill_patch2:SetPosition(self.model:GetPosition(0), 1)
 self.treadmill_patch2:SetRotation(self.model:GetRotation(0), 1)
 self.treadmill_patch3:SetPosition(self.model:GetPosition(0), 1)
 self.treadmill_patch3:SetRotation(self.model:GetRotation(0), 1)
 self.treadmill_patch4:SetPosition(self.model:GetPosition(0), 1)
 self.treadmill_patch4:SetRotation(self.model:GetRotation(0), 1)
 self.treadmill_patch5:SetPosition(self.model:GetPosition(0), 1)
 self.treadmill_patch5:SetRotation(self.model:GetRotation(0), 1)
 self.treadmill_patch6:SetPosition(self.model:GetPosition(0), 1)
 self.treadmill_patch6:SetRotation(self.model:GetRotation(0), 1)
 self.treadmill_patch7:SetPosition(self.model:GetPosition(0), 1)
 self.treadmill_patch7:SetRotation(self.model:GetRotation(0), 1)
 self.treadmill_patch8:SetPosition(self.model:GetPosition(0), 1)
 self.treadmill_patch8:SetRotation(self.model:GetRotation(0), 1)
 self.treadmill_patch9:SetPosition(self.model:GetPosition(0), 1)
 self.treadmill_patch9:SetRotation(self.model:GetRotation(0), 1)
end
]]--
object:Init()
function object:Free(model)
 self.super:Free()
end
end

 

PS : you might ignore "object:init()" and "object:UpdateMatrix()" plus you might replace ":update()" with ":draw()".

 

tia

AMD 64 X2 Dual 5k - 4GB - XFX GForce9800GT - nv196.21 - WinXP Sp3

zBrush4R2 - Silo2Pro - Unwrap3DPro - Gile - MaPZone2.5

 

adv_banner-april2012_720x150_tex01.png

 

Xxploration FPS in progress ...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...