Gamestudio Links
Zorro Links
Newest Posts
loading historical data 1st time
by AndrewAMD. 04/14/23 12:54
Trade at bar open
by juanex. 04/13/23 19:43
Bug in Highpass2 filter
by rki. 04/13/23 09:54
Adding Limit Orders For IB
by scatters. 04/11/23 16:16
FisherN
by rki. 04/11/23 08:38
AUM Magazine
Latest Screens
SHADOW (2014)
DEAD TASTE
Tactics of World War I
Hecknex World
Who's Online Now
4 registered members (fogman, Grant, AndrewAMD, juanex), 989 guests, and 8 spiders.
Key: Admin, Global Mod, Mod
Newest Members
rki, FranzIII, indonesiae, The_Judge, storrealba
18919 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Morphing Code #417713
02/16/13 09:44
02/16/13 09:44
Joined: Jul 2005
Posts: 187
L
lostzac Offline OP
Member
lostzac  Offline OP
Member
L

Joined: Jul 2005
Posts: 187
Code:
function morph_target(ENTITY* e, ENTITY* m, p)
{
	VECTOR Current;  //Current Mesh Vert Pos 
	VECTOR Target;  	//Morph1 Vert Pos

	VECTOR Base;     //Base or unchanged mesh vert pos
	VECTOR Diff;   
	VECTOR morph;
	
	var vert;
	var vert_cnt = ent_status(e,0);	
	
	for(vert=1;vert<vert_cnt;vert++)
	{
		//Base Model Postions
		CONTACT* c1 = ent_getvertex(e,NULL,vert);
		Base.x = c1.x;
		Base.y = c1.y;
		Base.z = c1.z;		
		
		//Target Models Postions
		CONTACT* c2 = ent_getvertex(m,NULL,vert);
		Target.x = c2.x;
		Target.y = c2.y;
		Target.z = c2.z;
		
		vec_set(morph.x,Base.x);
				
		vec_lerp(Diff.x,Base.x,Target.x,p);
		morph.x += Diff.x - Base.x;
		morph.y += Diff.y - Base.y;
		morph.z += Diff.z - Base.z;	
			
		c1.v = NULL;
		c1.x = morph.x;
		c1.y = morph.y;
		c1.z = morph.z;
		ent_setvertex(e,c1,vert);		
	}
	
	ent_fixnormals(e,0);
	c_updatehull(e,0);	
}



Note* Both models have to have the same number of verts and the morph object should be derived from the base object or you will get weird results..

p - this is the percentage of the morph you want your entity to take on. Use decimals so a 50% morph would be 0.5


John C Leutz II

Re: Morphing Code [Re: lostzac] #417716
02/16/13 10:38
02/16/13 10:38
Joined: Mar 2006
Posts: 1,993
Karlsruhe
PadMalcom Offline
Serious User
PadMalcom  Offline
Serious User

Joined: Mar 2006
Posts: 1,993
Karlsruhe
Hey, nice idea! If you manage to deal with models with a different number of vertices it would not only be great but awesome! laugh

Re: Morphing Code [Re: PadMalcom] #417718
02/16/13 10:44
02/16/13 10:44
Joined: Jul 2005
Posts: 187
L
lostzac Offline OP
Member
lostzac  Offline OP
Member
L

Joined: Jul 2005
Posts: 187
Hmmm never thought about that...I think I could get a system like that working...off the top of my head I would think about using target areas...and proximate distance of the target vert...I may have to look into that after I finish what I am working on... The hardest part would be morphing entities into targets with more verts as the detail would be hard to mimic....suppose you could fake it with normal maps, and if you used some sort of multi-texture with it as well like you would use in a terrain, that could handle the stretching of the textures.....

Last edited by lostzac; 02/16/13 10:58.

John C Leutz II


Moderated by  HeelX, Lukas, rayp, Rei_Ayanami, Superku, Tobias, TWO, VeT 

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1