Re: Journeywar
Posted: 17 Sep 2012, 02:41
Code: Select all
function setIntervallSmooth(intStart,intEnd)
if intStart== intEnd then return false end
for i=intStart,intEnd,1 do
resultDeg=0
groundheight2=0
if i~=1 then
x,y,z,_,_,_=Spring.GetUnitPiecePosDir(unitID,rope[13-i])
groundheight2=Spring.GetGroundHeight(x,z)
Spring.Echo("Element: ",13-i.." has forerunner Degree: ", nPrevDegTable[13-i+1])
resultDeg=math.floor(-1*nPrevDegTable[13-i+1] + acquireRopeDegree(i)) --bachelors rope by now
nPrevDegTable[13-i]=resultDeg
else --start intervall clause
x,y,z,_,_,_=Spring.GetUnitPiecePosDir(unitID,rope[12])
groundheight2=Spring.GetGroundHeight(x,z)
resultDeg=math.floor(-1*acquireVehicleDegree() + acquireRopeDegree(1))
nPrevDegTable[12]=resultDeg
end
--delMe
Spring.Echo("Setting Intervall Smooth.. piece ",i.. "Degree",resultDeg)
--/delMe
Turn(rope[13-i],x_axis,math.rad(resultDeg),0)
nPrevDegTable[13-i]=resultDeg
heightTable[13-i]=groundheight2
end
return true
end
Code: Select all
function acquireRopeDegree(i)
if i ==1 then
ax,ay,az,_,_,_=Spring.GetUnitPiecePosDir(unitID,rope[13-i])
ay=Spring.GetGroundHeight(ax,az)
bx,by,bz,_,_,_=Spring.GetUnitPiecePosDir(unitID,pm2)
-- by=Spring.GetGroundHeight(bx,bz)
local opposite=ay-by --+overfloor
local ax=ax-bx
local az = az - bz
local len = math.sqrt( ax*ax +az * az)
deg=math.floor(math.atan2(opposite, len)*(180/pi))
Spring.Echo("Aquired RopeDegree for ", i.." is ", deg)
return deg
else
ax,ay,az,_,_,_=Spring.GetUnitPiecePosDir(unitID,rope[13-i])
ay=Spring.GetGroundHeight(ax,az)
t=13-(i+1)
if t==0 then t=1 end
Turn(rope[t],x_axis,math.rad(-1*nPrevDegTable[13-i]),0) --line added to avoid mathtroubles when getting the pieces point
WaitForTurn(ropte[t],x_axis)
bx,by,bz,_,_,_=Spring.GetUnitPiecePosDir(unitID,rope[t])
-- by=Spring.GetGroundHeight(bx,bz)
local opposite=ay-by --+overfloor
local ax=ax-bx
local az = az - bz
local len = math.sqrt( ax*ax +az * az)
deg=math.floor(math.atan2(opposite, len)*(180/pi))
Spring.Echo("Aquired RopeDegree for ", i.." is ", deg)
return deg
end
end
Code: Select all
function FloraPhysixLoop() --Programmed by Cubex - Warning: This function pseudo-code was mentally programmed in my bathroom and then implemented in lua, can contain shit traces
--Speed Ups
local spGetUnitPosition = Spring.GetUnitPosition
local spGetUnitPiecePosition = Spring.GetUnitPiecePosition
local spGetUnitVectors = Spring.GetUnitVectors
local pi = math.pi
local abs = math.abs
local random = math.random
--Functions
local function GetUnitPiecePos(unit,piece) --function by jK
local x,y,z = spGetUnitPosition(unit)
local front,up,right = spGetUnitVectors(unit)
local px,py,pz = spGetUnitPiecePosition(unit,piece)
return x + (pz*front[1] + py*up[1] + px*right[1]),
y + (pz*front[2] + py*up[2] + px*right[2]),
z + (pz*front[3] + py*up[3] + px*right[3])
end
--Parameters
--local Randomness = 0.50 --Adding some random to trees, never conviced me, use at your wish
local Scale = 0.4 --Scales the current applied force, bigger means more shakey
local Speed = 0.5 --How much time takes a tree to turn to spetified angle, improves smoothness (too high might cause too radical moves, too low can cause lack of time to react)
local RotationLimit = pi / 6 --The maximum angle which a tree can rotate
local MoveThreshold = pi / 15 --If the movement is less than this, don't move, used to avoid "shake effect" in trees
local RefreshInterval = 100 --How much ms to wait for each iteration
local TreePosition = {} --Each tree position (last x axis, last z axis) used to calculate the diference betwen each loop and checks how much the tree was moved until last check
--Initialization
--Spring.Echo("RING RING RING!!! BANANA PHONE!!!") --For knowing if unit script runs or it crashed :/
for i = 70, 90 do
local Piece = optObjects[i]
--Show(Piece) --Used for looking all trees
local px, _, pz = GetUnitPiecePos(unitID, Piece) --Actual Position
TreePosition[i] = {px, pz} --update the last position with the actual
end
--Code
while true do
for i = 70, 90 do
local Piece = optObjects[i]
local px, _, pz = GetUnitPiecePos(unitID, Piece) --Actual Position
local lx, lz = unpack(TreePosition[i]) --get the last position
TreePosition[i] = {px, pz} --update the last position with the actual
--calculate the piece base traveled distance until the last update
px = (px-lx) -- * (random() + Randomness)
pz = (pz-lz) -- * (random() + Randomness)
px = px * Scale
pz = pz * Scale
if abs(px) > RotationLimit then
if px < 0 then px = -RotationLimit
else px = RotationLimit
end
elseif abs(px) < MoveThreshold then
px = 0
end
if abs(pz) > RotationLimit then
if pz < 0 then pz = -RotationLimit
else pz = RotationLimit
end
elseif abs(pz) < MoveThreshold then
pz = 0
end
Turn(Piece, x_axis, px, Speed)
Turn(Piece, z_axis, pz, Speed)
end
Sleep(RefreshInterval)
end
end -- Cubex's Ecosystem ends here, bye indentation :( I will miss you
Code: Select all
--Explain/Excuse code
while true do
if Me.Age < 18 then
Me.TouchBalls()
else
Me.Donate(Licho, "Spring Server", 10)
break
end
end
Code: Select all
#version 330 core
// Interpolated values from the vertex shaders
in vec2 UV;
in vec3 Position_worldspace;
in vec3 Normal_cameraspace;
in vec3 EyeDirection_cameraspace;
in vec3 LightDirection_cameraspace;
// Ouput data
layout(location = 0) out vec3 color;
// Values that stay constant for the whole mesh.
uniform sampler2D myTextureSampler;
uniform mat4 MV;
uniform vec3 LightPosition_worldspace;
void main(){
// Light emission properties
// You probably want to put them as uniforms
vec3 LightColor = vec3(1,1,1);
float LightPower = 50.0f;
// Material properties
vec3 MaterialDiffuseColor = texture2D( myTextureSampler, UV ).rgb;
vec3 MaterialAmbiantColor = vec3(0.1,0.1,0.1) * MaterialDiffuseColor;
vec3 MaterialSpecularColor = vec3(0.3,0.3,0.3);
// Distance to the light
float distance = length( LightPosition_worldspace - Position_worldspace );
// Normal of the computed fragment, in camera space
vec3 n = normalize( Normal_cameraspace );
// Direction of the light (from the fragment to the light)
vec3 l = normalize( LightDirection_cameraspace );
// Cosine of the angle between the normal and the light direction,
// clamped above 0
// - light is at the vertical of the triangle -> 1
// - light is perpendiular to the triangle -> 0
// - light is behind the triangle -> 0
float cosTheta = clamp( dot( n,l ), 0,1 );
// Eye vector (towards the camera)
vec3 E = normalize(EyeDirection_cameraspace);
// Direction in which the triangle reflects the light
vec3 R = reflect(-l,n);
// Cosine of the angle between the Eye vector and the Reflect vector,
// clamped to 0
// - Looking into the reflection -> 1
// - Looking elsewhere -> < 1
float cosAlpha = clamp( dot( E,R ), 0,1 );
color =
// Ambiant : simulates indirect lighting
MaterialAmbiantColor +
// Diffuse : "color" of the object
MaterialDiffuseColor * LightColor * LightPower * cosTheta / (distance*distance) +
// Specular : reflective highlight, like a mirror
MaterialSpecularColor * LightColor * LightPower * pow(cosAlpha,5) / (distance*distance);
}