Gamestudio Links
Zorro Links
Newest Posts
AlpacaZorroPlugin v1.3.0 Released
by kzhao. 05/22/24 13:41
Free Live Data for Zorro with Paper Trading?
by AbrahamR. 05/18/24 13:28
Change chart colours
by 7th_zorro. 05/11/24 09:25
Data from CSV not parsed correctly
by dr_panther. 05/06/24 18:50
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
1 registered members (henrybane), 1,499 guests, and 1 spider.
Key: Admin, Global Mod, Mod
Newest Members
LucasJoshua, Baklazhan, Hanky27, firatv, wandaluciaia
19054 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Page 1 of 2 1 2
bone interpolation? #310414
02/14/10 19:05
02/14/10 19:05
Joined: May 2009
Posts: 1,816
at my pc (duh)
darkinferno Offline OP
Serious User
darkinferno  Offline OP
Serious User

Joined: May 2009
Posts: 1,816
at my pc (duh)
i have an angle, lets say vector(20.80,-10.85,-2.55)

and i want to smoothly rotate a bone to that angle, i've been trying some stuff with vec_lerp and such but i guess i must be doing something wrong, this isnt for ragdolls or anything, i just want to smoothly blend a bone to a certain angle

Re: bone interpolation? [Re: darkinferno] #310429
02/14/10 19:38
02/14/10 19:38
Joined: Oct 2009
Posts: 149
Germany
M
muffel Offline
Member
muffel  Offline
Member
M

Joined: Oct 2009
Posts: 149
Germany
my first idea to this is that you scale the ANGLE
ANGLE target;
var percent =0;
ANGLE temp;
while(1)
{
percent += time_step;
if(percent<1)
{
vec_set(temp,target
vec_scale(temp,percent);
ent_bonereset(me,"theBone");
ent_bonerotate(me,"theBone",temp);
}
else
{
ent_bonereset(me,"theBone");
ent_bonerotate(me,"theBone",target);
break;
}
wait(1);
}

something like this
muffel

Last edited by muffel; 02/14/10 20:17.
Re: bone interpolation? [Re: muffel] #310433
02/14/10 20:06
02/14/10 20:06
Joined: May 2009
Posts: 1,816
at my pc (duh)
darkinferno Offline OP
Serious User
darkinferno  Offline OP
Serious User

Joined: May 2009
Posts: 1,816
at my pc (duh)
well am not sure if am playing with this correctly however it also seems to just snap the bone to the angle

Re: bone interpolation? [Re: darkinferno] #310438
02/14/10 20:36
02/14/10 20:36
Joined: Jul 2008
Posts: 1,178
England
M
MrGuest Offline
Serious User
MrGuest  Offline
Serious User
M

Joined: Jul 2008
Posts: 1,178
England
is it always rotated to that position from 0,0,0 or can it be at different angles before it's required to get to that angle?

Re: bone interpolation? [Re: MrGuest] #310444
02/14/10 21:03
02/14/10 21:03
Joined: May 2009
Posts: 1,816
at my pc (duh)
darkinferno Offline OP
Serious User
darkinferno  Offline OP
Serious User

Joined: May 2009
Posts: 1,816
at my pc (duh)
it will be at different angles

Re: bone interpolation? [Re: darkinferno] #310446
02/14/10 21:15
02/14/10 21:15
Joined: Jul 2008
Posts: 1,178
England
M
MrGuest Offline
Serious User
MrGuest  Offline
Serious User
M

Joined: Jul 2008
Posts: 1,178
England
here's a code i wrote for rotating an entity, it passes the entity and the desired angles
Code:
void ai_rotate(ENTITY* ent, int degrees){
	
	while(ent.z < 40){
		if(int_game_state != game_state_playing){
			return;
		}
		
		ent.z = minv(ent.z + (time_step * 8), 40);
		wait(1);
	}
	
	int pan = ent.pan + degrees;
	while(ent.pan != pan){
		
		if(int_game_state != game_state_playing){
			return;
		}
		
		if(degrees < 0){
			
			ent.pan = maxv(ent.pan - (3 * time_step), pan);
		}else{
			
			ent.pan = minv(ent.pan + (3 * time_step), pan);
		}
		wait(1);
	}
	ent.pan = ang(ent.pan);
	
	while(ent.z > 0){
		if(int_game_state != game_state_playing){
			return;
		}
		
		ent.z = maxv(ent.z - (time_step * 8), 0);
		wait(1);
	}
}

I'm sure you'll be able to work it out from there, otherwise gimme a shout

the 2 other angles will just be proporionate to the percentage the 1st angle has rotated

Re: bone interpolation? [Re: MrGuest] #310453
02/14/10 21:42
02/14/10 21:42
Joined: May 2009
Posts: 1,816
at my pc (duh)
darkinferno Offline OP
Serious User
darkinferno  Offline OP
Serious User

Joined: May 2009
Posts: 1,816
at my pc (duh)
sadly am not seeing the result of this? basically this is saying if the angle is lower than degree, add to it, if higher than degree, subtract from it? remember am trying to rotate bones not an entity, am not sure the same principles apply

Re: bone interpolation? [Re: darkinferno] #310487
02/15/10 00:49
02/15/10 00:49
Joined: Jul 2008
Posts: 1,178
England
M
MrGuest Offline
Serious User
MrGuest  Offline
Serious User
M

Joined: Jul 2008
Posts: 1,178
England
ok, a bit more work, i've come up with this

moves around the biggest angle and calculates the scale for the other angles

Code:
#include <acknex.h>
#include <default.c>


#define bone_pan skill1
#define bone_tilt skill2
#define bone_roll skill3


STRING* str_model = "dummy_man.mdl";
STRING* str_bone = "waist";

//rotate angle by
void bone_rotate(ENTITY* ent, ANGLE* ang_temp){
	
	ANGLE ang_target;
	
	vec_set(ang_target, ent.bone_pan); //current bone position
	vec_add(ang_target, ang_temp);
	
	int int_maxpivot = 0;
	
	//find which is moving the most
	if(abs(ang_temp.pan) > abs(ang_temp.tilt)){
		
		if(abs(ang_temp.pan) > abs(ang_temp.roll)){
			
			int_maxpivot = 1; //biggest is pan
		}else{
			
			int_maxpivot = 3; //biggest is roll
		}
	}else{
		
		if(abs(ang_temp.tilt) > abs(ang_temp.roll)){
			
			int_maxpivot = 2; //biggest is tilt
		}else{
			
			int_maxpivot = 3; //biggest is roll
		}
	}
	
	var var_pandiff = 1;
	var var_tiltdiff = 1;
	var var_rolldiff = 1;
	
	//calculate percentages based on biggest pivot
	switch(int_maxpivot){
		
		case 1: //pan
			var_tiltdiff = ang_temp.tilt / ang_temp.pan;
			var_rolldiff = ang_temp.roll / ang_temp.pan;
		break;
		
		case 2: //tilt
			var_pandiff = ang_temp.pan / ang_temp.tilt;
			var_rolldiff = ang_temp.roll / ang_temp.tilt;
		break;
		
		case 3: //roll
			var_pandiff = ang_temp.pan / ang_temp.roll;
			var_tiltdiff = ang_temp.tilt / ang_temp.roll;
		break;
	}
	
	
	while(ent.bone_pan != ang_target.pan){
		
		if(ent.bone_pan < ang_target.pan){
			
			ent.bone_pan = minv(ent.bone_pan + (1 * var_pandiff * time_step), ang_target.pan);
			
		}else{
			
			ent.bone_pan = maxv(ent.bone_pan - (1 * var_pandiff * time_step), ang_target.pan);
		}
		
		if(ent.bone_tilt < ang_target.tilt){
			
			ent.bone_tilt = minv(ent.bone_tilt + (1 * var_tiltdiff * time_step), ang_target.tilt);
			
		}else{
			
			ent.bone_tilt = maxv(ent.bone_tilt - (1 * var_tiltdiff * time_step), ang_target.tilt);
		}
		
		if(ent.bone_roll < ang_target.roll){
			
			ent.bone_roll = minv(ent.bone_roll + (1 * var_rolldiff * time_step), ang_target.roll);
			
		}else{
			
			ent.bone_roll = maxv(ent.bone_roll - (1 * var_rolldiff * time_step), ang_target.roll);
		}
		
		ent_bonereset(ent, str_bone);
		ent_bonerotate(ent, str_bone, ent.bone_pan);
		wait(1);
	}
}


//rotate angle to
void bone_rotate_to(ENTITY* ent, ANGLE* ang_temp){
	
	ANGLE ang_target;
	
//	vec_set(ang_target, ent.bone_pan); //current bone position
//	vec_add(ang_target, ang_temp);
	
	vec_set(ang_target, ang_temp);
	
	int int_maxpivot = 0;
	
	//find which is moving the most
	if(abs(ang_temp.pan) > abs(ang_temp.tilt)){
		
		if(abs(ang_temp.pan) > abs(ang_temp.roll)){
			
			int_maxpivot = 1; //biggest is pan
		}else{
			
			int_maxpivot = 3; //biggest is roll
		}
	}else{
		
		if(abs(ang_temp.tilt) > abs(ang_temp.roll)){
			
			int_maxpivot = 2; //biggest is tilt
		}else{
			
			int_maxpivot = 3; //biggest is roll
		}
	}
	
	var var_pandiff = 1;
	var var_tiltdiff = 1;
	var var_rolldiff = 1;
	
	//calculate percentages based on biggest pivot
	switch(int_maxpivot){
		
		case 1: //pan
			var_tiltdiff = ang_temp.tilt / ang_temp.pan;
			var_rolldiff = ang_temp.roll / ang_temp.pan;
		break;
		
		case 2: //tilt
			var_pandiff = ang_temp.pan / ang_temp.tilt;
			var_rolldiff = ang_temp.roll / ang_temp.tilt;
		break;
		
		case 3: //roll
			var_pandiff = ang_temp.pan / ang_temp.roll;
			var_tiltdiff = ang_temp.tilt / ang_temp.roll;
		break;
	}
	
	
	while(ent.bone_pan != ang_target.pan){
		
		if(ent.bone_pan < ang_target.pan){
			
			ent.bone_pan = minv(ent.bone_pan + (1 * var_pandiff * time_step), ang_target.pan);
			
		}else{
			
			ent.bone_pan = maxv(ent.bone_pan - (1 * var_pandiff * time_step), ang_target.pan);
		}
		
		if(ent.bone_tilt < ang_target.tilt){
			
			ent.bone_tilt = minv(ent.bone_tilt + (1 * var_tiltdiff * time_step), ang_target.tilt);
			
		}else{
			
			ent.bone_tilt = maxv(ent.bone_tilt - (1 * var_tiltdiff * time_step), ang_target.tilt);
		}
		
		if(ent.bone_roll < ang_target.roll){
			
			ent.bone_roll = minv(ent.bone_roll + (1 * var_rolldiff * time_step), ang_target.roll);
			
		}else{
			
			ent.bone_roll = maxv(ent.bone_roll - (1 * var_rolldiff * time_step), ang_target.roll);
		}
		
		ent_bonereset(ent, str_bone);
		ent_bonerotate(ent, str_bone, ent.bone_pan);
		wait(1);
	}
}


void main(){
	
	wait(1);
	
	level_load(NULL);
	
	me = ent_create(str_model, vector(150, 0, 0), NULL);
	
	vec_set(my.bone_pan, vector(45, 0, 0));
	ent_bonerotate(me, str_bone, my.bone_pan);
	
//	bone_rotate(me, vector(90, 0, 0));
	bone_rotate_to(me, vector(90, 0, 0));
}

change the strings at the top for the entity and bone you want to spawn and move,

ent_rotate() will rotate the bone that distance,
ent_rotate_to() will rotate the bone to that angle,

hopefully linear interpolation is enough, have a look at the cinematic swooping camera if you wanted polynomial interpolation

hope this helps


*No consideration for negative numbers or use of ang()*

Last edited by MrGuest; 02/15/10 01:03.
Re: bone interpolation? [Re: MrGuest] #310551
02/15/10 13:26
02/15/10 13:26
Joined: May 2009
Posts: 1,816
at my pc (duh)
darkinferno Offline OP
Serious User
darkinferno  Offline OP
Serious User

Joined: May 2009
Posts: 1,816
at my pc (duh)
lol, that seems like a really huge amount of code to do what i want and i want to rotate every bone of a model to a certain angle, think of it as:

i have a leg thats straight and i want to smoothly interpolate it to an angle that would make it seem like the knees bent, as said, i though vec_lerping would work but i didnt get any accurate results

Re: bone interpolation? [Re: darkinferno] #310571
02/15/10 17:10
02/15/10 17:10
Joined: Jul 2008
Posts: 1,178
England
M
MrGuest Offline
Serious User
MrGuest  Offline
Serious User
M

Joined: Jul 2008
Posts: 1,178
England
ahhh inverse kinematics, never got that to work either frown

Page 1 of 2 1 2

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