Ribbon effects. - Page 2

Ribbon effects.

Requests for features in the spring code.

Moderator: Moderators

User avatar
Argh
Posts: 10920
Joined: 21 Feb 2005, 03:38

Re: Ribbon effects.

Post by Argh »

I'm almost done, if I can just get the table I've built in the sync side to show up on the unsync side. The actual drawing part's not too hard, getting the data that you need, insofar as it's available without having to do a lot of really heavy math... is not the hard part... it's the data-transport that's been a royal pain in the ass. You would think that it'd be fairly easy, but that's the worst part.

If LUA in Spring could just draw in sync, or if there were some SIMPLE examples of how to do sync-->unsync communication available, then I'd have had this done and available to mess with two days ago...
User avatar
Zpock
Posts: 1218
Joined: 16 Sep 2004, 23:20

Re: Ribbon effects.

Post by Zpock »

Projectiles are a problem, it's something that's really generally needed, a way for LUA to see the projectiles. I think this is the biggest weakness of LUA currently.

Hint on how to do it is cross-product of vector between camera and points, and vector between the two points of the effect, for a sort of semi-billboard.
Last edited by Zpock on 22 Feb 2008, 08:36, edited 2 times in total.
User avatar
Argh
Posts: 10920
Joined: 21 Feb 2005, 03:38

Re: Ribbon effects.

Post by Argh »

Um, can I have a hint on how to get SYNCED to actually do anything useful? That's where I'm stuck. I have data coming in from COB... but I cannot seem to get unsync to do anything with it...

Code: Select all

function gadget:GetInfo()
	return {
		name = "Trails.lua",
		desc = "Draws trails behind fighters.",
		author = "Argh",
		date = "February 21st, 2007",
		license = "Public Domain",
		layer = 1,
		enabled = true,
	}
end

if (gadgetHandler:IsSyncedCode()) then

local TrailQueue = {}
--////////////////////////////////////////////////////////////////BEGIN SYNC

--////////////////////////////////////////////////////////////////////////////
function GetValues(u,ud,team)
	local x,y,z = Spring.GetUnitPosition(u)
	return x,y,z
end
gadgetHandler:RegisterGlobal("GetValues", GetValues)
--////////////////////////////////////////////////////////////////////////////

--////////////////////////////////////////////////////////////////////////////
function SendOverValues(u,ud,team,X1,Y1,Z1,X2,Y2,Z2)
	table.insert(TrailQueue,{x1=X1,y1=Y1,z1=Z1,x2=X2,y2=Y2,z2=Z2})
end
gadgetHandler:RegisterGlobal("SendOverValues", SendOverValues)
--//////////////////////////////////////////////////////////////////////////// 

--////////////////////////////////////////////////////////////////END SYNC
else
--////////////////////////////////////////////////////////////////BEGIN UNSYNC

--////////////////////////////////////////////////////////////////////////////
function gadget:DrawWorld()
	Spring.Echo (SYNCED,SYNCED.TrailQueue)
	--[[if (TrailQueue[0]) ~= nil then
		for _,u in ipairs(TrailQueue) do
		Spring.Echo (u.x1,u.y1,u.z1) end			
				gl.Color(0,0.3,1,0.5)
				gl.LineWidth(1.0)
		for _,t in ipairs(TrailQueue) do
				gl.BeginEnd(GL.LINE_STRIP,function()
				gl.Vertex(t.x1,t.y1,t.z1)
				gl.Vertex(t.x2,t.y2,t.z2)
				end)
		end
	end]]		 
end
--////////////////////////////////////////////////////////////////////////////

--////////////////////////////////////////////////////////////////END UNSYNC
end
That last Spring.Echo in DrawWorld() results in a table value for the first query, then nil for the second one... so what am I doing wrong? The only thing that's left here is to get that done, and I'll have some ribbon effects...
User avatar
Zpock
Posts: 1218
Joined: 16 Sep 2004, 23:20

Re: Ribbon effects.

Post by Zpock »

You can make a table that is in synced to become global so it's acessible in the unsynced part with this:

Code: Select all

gadgetHandler:RegisterGlobal('tablename', tablename)
I put the above in

Code: Select all

function gadget:Initialize()
Then to acess the table in the unsynced part:

Code: Select all

SYNCED.tablename
I see that you try to do something like this altough I can't really dechiper your code it looks really weird. Try to just make your trailqueue table global and then calculate the values in that table in the synced part, and draw in the unsynced, you have too many functions and crap I think.
User avatar
Argh
Posts: 10920
Joined: 21 Feb 2005, 03:38

Re: Ribbon effects.

Post by Argh »

<testing>

DRAT. I know I'm close. I can taste it. But, no. This still doesn't work.

Code: Select all

function gadget:GetInfo()
	return {
		name = "Trails.lua",
		desc = "Draws trails behind fighters.",
		author = "Argh",
		date = "February 21st, 2007",
		license = "Public Domain",
		layer = 1,
		enabled = true,
	}
end

if (gadgetHandler:IsSyncedCode()) then

local TrailQueue = {}
--////////////////////////////////////////////////////////////////BEGIN SYNC

--////////////////////////////////////////////////////////////////////////////
function GetValues(u,ud,team)
	local x,y,z = Spring.GetUnitPosition(u)
	return x,y,z
end
gadgetHandler:RegisterGlobal("GetValues", GetValues)
--////////////////////////////////////////////////////////////////////////////

--////////////////////////////////////////////////////////////////////////////
function SendOverValues(u,ud,team,X1,Y1,Z1,X2,Y2,Z2)
	table.insert(TrailQueue,{x1=X1,y1=Y1,z1=Z1,x2=X2,y2=Y2,z2=Z2})
end
gadgetHandler:RegisterGlobal("SendOverValues", SendOverValues)
--//////////////////////////////////////////////////////////////////////////// 

function gadget:Initialize()
gadgetHandler:RegisterGlobal("TrailQueue", TrailQueue)
end
--////////////////////////////////////////////////////////////////END SYNC
else
--////////////////////////////////////////////////////////////////BEGIN UNSYNC

--////////////////////////////////////////////////////////////////////////////
function gadget:DrawWorld()
			gl.Color(0,0.3,1,0.5)
			gl.LineWidth(1.0)
	for _,t in ipairs(SYNCED.TrailQueue) do
			gl.BeginEnd(GL.LINE_STRIP,function()
			gl.Vertex(t.x1,t.y1,t.z1)
			gl.Vertex(t.x2,t.y2,t.z2)
			end)
	end		 
end
--////////////////////////////////////////////////////////////////////////////

--////////////////////////////////////////////////////////////////END UNSYNC
end
User avatar
Argh
Posts: 10920
Joined: 21 Feb 2005, 03:38

Re: Ribbon effects.

Post by Argh »

OMFG!!!! I DID IT! FINALLY!!!

Screen, here in a second. Please, don't laugh, it looks like crap, and I don't know how to get rid of the old lines yet...
User avatar
Argh
Posts: 10920
Joined: 21 Feb 2005, 03:38

Re: Ribbon effects.

Post by Argh »

Image

Er... so how am I supposed to remove the lines, anyhow? Maybe tie them to a unitID, instead of just using table.insert?

Screw it, I need to get to bed, I have a busy day tomorrow. Maybe I'll be able to figure it out when I wake up.

At any rate, here's the code to do this, including the COB stuff I'm using. Feel free to improve it, it has nowhere to go but up, but I'd strongly prefer that the COB-->LUA back-and-forth stayed in, there are other things that can be done with that... hereby released into the Public Domain...

COB:

Code: Select all

lua_GetValues(arg){return 0;}
lua_SendOverValues(arg){return 0;}

positionUpdate()
{
	while(1)
	{
		call-script lua_GetValues();
		X1 = GET LUA1;
		Y1 = GET LUA2;
		Z1 = GET LUA3;
		call-script lua_SendOverValues(X1,Y1,Z1,X2,Y2,Z2);
		sleep 1000;
		X2 = X1;
		Y2 = Y1;
		Z2 = Z1;	
	}
}
LUA:

Code: Select all

function gadget:GetInfo()
	return {
		name = "Trails.lua",
		desc = "Draws trails behind fighters.",
		author = "Argh",
		date = "February 21st, 2007",
		license = "Public Domain",
		layer = 1,
		enabled = true,
	}
end

if (gadgetHandler:IsSyncedCode()) then

local TrailQueue = {}
--////////////////////////////////////////////////////////////////BEGIN SYNC

--////////////////////////////////////////////////////////////////////////////
function GetValues(u,ud,team)
	local x,y,z = Spring.GetUnitPosition(u)
	return x,y,z
end
gadgetHandler:RegisterGlobal("GetValues", GetValues)
--////////////////////////////////////////////////////////////////////////////

--////////////////////////////////////////////////////////////////////////////
function SendOverValues(u,ud,team,X1,Y1,Z1,X2,Y2,Z2)
	table.insert(TrailQueue,{x1=X1,y1=Y1,z1=Z1,x2=X2,y2=Y2,z2=Z2})
end
gadgetHandler:RegisterGlobal("SendOverValues", SendOverValues)
--//////////////////////////////////////////////////////////////////////////// 

function gadget:Initialize()
gadgetHandler:RegisterGlobal("TrailQueue", TrailQueue)
end
--////////////////////////////////////////////////////////////////END SYNC
else
--////////////////////////////////////////////////////////////////BEGIN UNSYNC

--////////////////////////////////////////////////////////////////////////////
function gadget:DrawWorld()
			gl.Color(0,0.3,1,0.5)
			gl.LineWidth(1.0)
	for _,t in spairs(SYNCED.TrailQueue) do
			gl.BeginEnd(GL.LINE_STRIP,function()
			gl.Vertex(t.x1,t.y1,t.z1)
			gl.Vertex(t.x2,t.y2,t.z2)
			end)
	end		 
end
--////////////////////////////////////////////////////////////////////////////

--////////////////////////////////////////////////////////////////END UNSYNC
end
If I can figure out how to only draw the n-number of last segments (where n is "whatever looks nicest"), then I can very easily make some pretty trails with this, by using multiple lines of different thicknesses and alpha values. Later on, I can try and figure out how to do a polystrip, I figured lines would probably be very efficient, though, and probably sufficiently pretty for a lot of things.
User avatar
rattle
Damned Developer
Posts: 8278
Joined: 01 Jun 2006, 13:15

Re: Ribbon effects.

Post by rattle »

//////////////////////cantreadshit///////////////////////
user
Posts: 452
Joined: 22 Jan 2008, 16:33

Re: Ribbon effects.

Post by user »

replace the '/' with '-'.

try it with, lots of fighters, about 200-500.

to remove the lines, just make it remove old points.

you really should consider using a display list.

and please make a better screenshot, we can hardly see how cool it looks in game.
User avatar
rattle
Damned Developer
Posts: 8278
Joined: 01 Jun 2006, 13:15

Re: Ribbon effects.

Post by rattle »

Can't you get a units position through Lua? Also, lines. Some textured polygon strips would be nicer.
user
Posts: 452
Joined: 22 Jan 2008, 16:33

Re: Ribbon effects.

Post by user »

I DID IT!
not really:

Image

and they have their own UnitDef tags, like:

trailwidth,
trailframes,
trailfadealpha,
trail<color,r,g,b,a>,
trailblendmode,

what still needs to be done is make it use quads instead of lines.
User avatar
Zpock
Posts: 1218
Joined: 16 Sep 2004, 23:20

Re: Ribbon effects.

Post by Zpock »

Do you need help to do that?
user
Posts: 452
Joined: 22 Jan 2008, 16:33

Re: Ribbon effects.

Post by user »

this was originally made by quantum, but it was very very limited.
all it did was drawing a fixed size trail with the team color.

its features were:
you can't choose which units use it.
you can't choose the size, color, width.
it wont be draw on the minimap.

since i don't like limits and magic numbers i made all this:
you can choose which units use it,
you can choose the RGBA color,
you can choose the blend mode,
you can choose the max life time,
you can choose the trail width,
you can choose if you want to draw it on the minimap,
you can choose if its alpha will fade over size,
you can choose to draw its shadows or not,
you can choose to draw its reflection and refraction,
soon to come: you can choose which rendering mode(points,lines,quads)

if you want to help then you can,
User avatar
smoth
Posts: 22309
Joined: 13 Jan 2005, 00:46

Re: Ribbon effects.

Post by smoth »

Does this come in a non-gpl flavor as well? Thanks bunches for taking this on user!
user
Posts: 452
Joined: 22 Jan 2008, 16:33

Re: Ribbon effects.

Post by user »

well, since nobody was going to make this, i decided to make it.

look at the first page, they were not getting anywhere,
argh was doing it wrong, and jk said it can't be made in lua.

when i make a cool effect in lua, i always do everything possible to make it work for everyone.
User avatar
lurker
Posts: 3842
Joined: 08 Jan 2007, 06:13

Re: Ribbon effects.

Post by lurker »

user wrote:its features were:
Yes, quantum was making a tech demo for someone else to finish.
user
Posts: 452
Joined: 22 Jan 2008, 16:33

Re: Ribbon effects.

Post by user »

i really have to thank him for taking time to start this, i couldn't have started this myself, i am not that good.
User avatar
smoth
Posts: 22309
Joined: 13 Jan 2005, 00:46

Re: Ribbon effects.

Post by smoth »

I appreciate it man, I will give you full props in the gundam credits page once I add your lua! thanks in advance!
User avatar
bobthedinosaur
Blood & Steel Developer
Posts: 2702
Joined: 25 Aug 2004, 13:31

Re: Ribbon effects.

Post by bobthedinosaur »

prettiness, will this be in the next spring version?
user
Posts: 452
Joined: 22 Jan 2008, 16:33

Re: Ribbon effects.

Post by user »

thanks smoth.
will this be in the next spring version?
this wont be on the next spring version, because this is a lua script.
Post Reply

Return to “Feature Requests”