Page 1 of 1

[Tree Feller] Drawing features from Lua

Posted: 23 Mar 2014, 22:19
by Beherith
I would like to draw falling trees, but I cant get the texture blending right. Depending on which textures I bind, the feature is either completely opaque, or its color is totally black.

Code:

Code: Select all

	function gadget:DrawWorldPreUnit()
		gf=Spring.GetGameFrame()

		for featureID, featureinfo in pairs(treesdying) do
			local x, y, z = featureinfo.posx, featureinfo.posy, featureinfo.posz
			--Spring.Echo('drawing tree:', featureID, featureinfo.frame, gf,'defid',featureinfo.fDefID)
			--local _, b, _ = spGetPositionLosState(x, y, z)
			if (featureinfo.frame +90 < gf) then
				treesdying[featureID]=nil
			else 
				local losState = true
				if ( losState == true ) then
					--glow effect?
					glColor(1.0, 1.0, 1.0, 0.8 )

					
					glTexture(0,"%-" .. featureinfo.fDefID .. ":0 ")
					glTexture(1,"%-" .. featureinfo.fDefID .. ":1 ")

					glTexEnv( GL.TEXTURE_ENV, GL.TEXTURE_ENV_MODE, 0x8570 ) --GL_COMBINE_RGB
					glPushMatrix()
					glTranslate(x, y, z)
					glRotate(featureinfo.angle,0,y,0)
					
					glRotate((gf-featureinfo.frame)*1,x,0,0)
					Spring.Echo('drawing', featureID,featureinfo.fDefID, x,y,z,"%-" .. featureinfo.fDefID .. ":0 ")
					glFeatureShape(featureinfo.fDefID, gaiaTeamID)
					  
					glPopMatrix()
				end
			end
		end
	end
Screenshot:
Image

Re: Drawing features from Lua

Posted: 23 Mar 2014, 22:38
by jK
likely not possible, you need to patch engine

gl.FeatureShape is not as gl.UnitShape and changes a lot gl states and you can't stop it doing so atm.

So engine needs patched.

Re: Drawing features from Lua

Posted: 24 Mar 2014, 21:58
by Beherith
Thanks for clarifying this jK, I got the tree feller to work through intercepting dying trees in FeaturePreDamaged then using SetFeatureDirection.

Re: Drawing features from Lua

Posted: 24 Mar 2014, 23:07
by FLOZi
Beherith wrote:Thanks for clarifying this jK, I got the tree feller to work through intercepting dying trees in FeaturePreDamaged then using SetFeatureDirection.
Arguably the more sensible approach :P Do you detect the direction of the collision and fall accordingly? knorke wrote such a system before but iirc it was just random direction.

Has long been on my todo list for S44 to write a feature destruction gadget to mimic some of the effects in world of tanks but one of those things I never got around to.

Re: Drawing features from Lua

Posted: 24 Mar 2014, 23:29
by knorke
Do you detect the direction of the collision and fall accordingly? knorke wrote such a system before but iirc it was just random direction.
Yes, mine is random. Getting the direction from unit&feature position should be possible though.
Did not bother with it because falling trees was only one use..
Only works different so not sure how relevant it is...
The crushed feature is replaced by unit for the animation..gives bit more flexibilty than just falling over.
For example in spring tanks the trees "explode" when tanks drive into them. Or wall falls over then shatters http://www.youtube.com/watch?v=ogjf7h5gD8w
Or like this:
Image

Re: [Tree Feller] Drawing features from Lua

Posted: 24 Mar 2014, 23:33
by Beherith
Here it is guys:

http://imolarpg.dyndns.org/trac/balates ... feller.lua

I also didnt do the directional falling, just random, because the feature rotations are calculated in a wierd way.

Re: Drawing features from Lua

Posted: 25 Mar 2014, 16:59
by gajop
jK wrote:likely not possible, you need to patch engine

gl.FeatureShape is not as gl.UnitShape and changes a lot gl states and you can't stop it doing so atm.

So engine needs patched.
Could you please clarify that (so even stupids like myself can understand it), what can't be done exactly? I tried drawing features (with textures) in my scenario editor, but they were always black (with some level of transparency)< where I could always draw units with textures normally.

(Sorry if it feels like I'm hijacking the thread, but I think the question is still on topic)

Re: [Tree Feller] Drawing features from Lua

Posted: 25 Mar 2014, 19:27
by Beherith
As far as i can see, you cant draw feature with that because the textruing and lighting and shadows states are not set up, and because the depth testing wont work properly. couldnt you just use createfeature in your editor?

Re: [Tree Feller] Drawing features from Lua

Posted: 25 Mar 2014, 19:37
by gajop
Beherith wrote:As far as i can see, you cant draw feature with that because the textruing and lighting and shadows states are not set up, and because the depth testing wont work properly. couldnt you just use createfeature in your editor?
I was drawing them while they still weren't placed on the map, and would like to avoid creating them because it messes with the state (especially multi-"player" editing), as one would need to remove them if they aren't added eventually.

Re: [Tree Feller] Drawing features from Lua

Posted: 25 Mar 2014, 20:15
by FLOZi
For the purposes of pre-placement, does accurate texture representation really matter?

@knorke; Cool water tower. I have wondered if per-featuredef is the best way or if a generic piece projectile spawning unit might be reasonable.