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
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
2 registered members (AndrewAMD, ozgur), 1,421 guests, and 6 spiders.
Key: Admin, Global Mod, Mod
Newest Members
AemStones, LucasJoshua, Baklazhan, Hanky27, firatv
19055 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
v attach calculating roll? #128078
05/04/07 15:53
05/04/07 15:53
Joined: Feb 2006
Posts: 2,185
mpdeveloper_B Offline OP
Expert
mpdeveloper_B  Offline OP
Expert

Joined: Feb 2006
Posts: 2,185
Something for the scripting gurus here , i'm using vertexes to attach a shield to my mech model, the pan and tilt angles are calculated properly, meaning that my shield faces the right position, but it won't roll to the right position. what i mean by this is the shield will "face" the right position, but it won't roll to match up with the second vertex i'm using, here are some pics showing what i mean:





my question is, is it possible to use a vertex to calculate the roll angle of a vertex attached entity?

i'm using one vertex on the mech's arm that's used for placing the shield, then there is one that is in the direction where the shield should face, and last there is one close to the hand's position used to calculate where the shield's bottom should point to, or the shield should roll to.

here's the code i'm using so far:

Code:

function slim_shield()
{
var roll_pos;
var attach_pos;
var temp2;
var roll_pos2;
var roll2;
my.passable = on;
while(you)
{// weapon will always "face" the second vertice from
proc_late();
vec_for_vertex(my.x,you,712); //position vertex
vec_for_vertex(attach_pos,you,713); ///the roll should be calculated here...
vec_for_vertex(roll_pos2,you, 735); ///pan and tilt angles are calculated here
temp.x = attach_pos.x - MY.X;
temp.y = attach_pos.y - MY.Y;
temp.z = attach_pos.z - MY.Z;

temp2.x = roll_pos2.x - MY.X;
temp2.y = roll_pos2.y - MY.Y;
temp2.z = roll_pos2.z - MY.Z;

vec_to_angle(roll_pos,temp);
vec_to_angle(roll2, temp2);

my.pan = roll2.pan;
my.tilt = roll2.tilt;
my.roll = roll_pos.roll;
wait(1);
}
}




- aka Manslayer101
Re: v attach calculating roll? [Re: mpdeveloper_B] #128079
05/05/07 17:44
05/05/07 17:44
Joined: Feb 2006
Posts: 2,185
mpdeveloper_B Offline OP
Expert
mpdeveloper_B  Offline OP
Expert

Joined: Feb 2006
Posts: 2,185
is it possible or isn't it?


- aka Manslayer101
Re: v attach calculating roll? [Re: mpdeveloper_B] #128080
05/05/07 18:29
05/05/07 18:29
Joined: Mar 2007
Posts: 776
Poor village - Poland ;)
tompo Offline
User
tompo  Offline
User

Joined: Mar 2007
Posts: 776
Poor village - Poland ;)
try to use vec_for_bone and ang_for_bone with vec_for_vertex


Never say never.
Re: v attach calculating roll? [Re: tompo] #128081
05/05/07 22:36
05/05/07 22:36
Joined: Mar 2006
Posts: 3,538
WA, Australia
J
JibbSmart Offline
Expert
JibbSmart  Offline
Expert
J

Joined: Mar 2006
Posts: 3,538
WA, Australia
this is just off the top of my head, but...

i think you need a third vertex position for roll. using two vertex positions gives you a line, and something oriented along that line can have any roll. a third vertex position gives you a triangle -- there are no unknowns if you do it right.

don't change the way you're finding pan and tilt at the moment, coz that appears to be working just fine. sorry i can't go into specifics, coz i just can't think of what you'd actually do with the third vertex position, and i have homework due tomorrow that i have to do in a couple of minutes.

good luck

julz


Formerly known as JulzMighty.
I made KarBOOM!
Re: v attach calculating roll? [Re: JibbSmart] #128082
05/06/07 00:03
05/06/07 00:03
Joined: Mar 2006
Posts: 2,503
SC, United States
xXxGuitar511 Offline
Expert
xXxGuitar511  Offline
Expert

Joined: Mar 2006
Posts: 2,503
SC, United States
@Julz: I was thinking the same thing this morning when I was walkin to the gas-station.. (Yes, I do think about this stuff in my free time.. lol)

You'd need a third vertex, as said above. With this, you find the angle from the center of the other two vertices. Then [somehow] roll it to match...

var p1[3]; var p2[3];
var centerPoint[3];

vec_for_vertex(p1, my, ...);
vec_for_vertex(p2, my, ...);
vec_diff(temp, p2, p1);
vec_scale(temp, 0.5);
vec_add(temp, p1);
vec_set(centerPoint, temp);

// CenterPoint now contains a point between the two vertices.
// Now you need to find the direction to the third...

var p3[3];
var centerAngle[3];
vec_for_vertex(p3, my, ...);
vec_diff(temp, p3, centerPoint);
vec_to_angle(centerAngle, temp);

// centerAngle now contains a pan/tilt pointing to the centerPoint.
// Now find a way to convert this to roll...


xXxGuitar511
- Programmer
Re: v attach calculating roll? [Re: mpdeveloper_B] #128083
08/08/07 20:06
08/08/07 20:06
Joined: Mar 2007
Posts: 197
Y
yorisimo Offline
Member
yorisimo  Offline
Member
Y

Joined: Mar 2007
Posts: 197
@Manslayer101
Did you figure this out? I am doing the same thing, and am struggling to get the roll angle correct.

Re: v attach calculating roll? [Re: yorisimo] #128084
08/09/07 11:09
08/09/07 11:09
Joined: Oct 2003
Posts: 312
Lüneburg, Germany
Gnometech Offline
Senior Member
Gnometech  Offline
Senior Member

Joined: Oct 2003
Posts: 312
Lüneburg, Germany
There is an ancient part of code floating around (at least 4 years old) where I answered a similar question. Yes, you need a third vertex for the roll and do some basic vector arithmetics.

Here comes the code, try to put it to good use. :-)

Code:

function addons(entity1,v1,v2,v3); //function prototype

entity* tempentity
var hand_pos[3];
var hand_pos2[3];
var hand_pos3[3];
var hand_pos4[3];
var vec1[3];
var vec2[3];

function addons(entity1,v1,v2,v3)
{
// you = me;
tempentity = ptr_for_handle(entity1); //entity to attach to me

vec_for_vertex(tempentity.x,you,v1); //vertex to place origin at

vec_for_vertex(hand_pos,you,v2); //vert to orient pan and tilt
vec_for_vertex(hand_pos2,you,v1);
vec_for_vertex(hand_pos3,you,v3); //vert to orient roll
vec_for_vertex(hand_pos4,you,v2);

vec_sub(hand_pos,tempentity.x); //sets our pan and tilt
vec_to_angle(tempentity.pan,hand_pos);
tempentity.roll = null;

//all this does the roll, courtesy of Gnometech
vec_sub(hand_pos3,hand_pos4);
vec_set (vec1, nullvector);
vec1.y = 1;
vec_rotate (vec1, tempentity.pan);
vec_set (vec2, nullvector);
vec2.z = 1;
vec_rotate (vec2, tempentity.pan); // those vectors span the plane
temp.x = vec_dot (vec1, hand_pos3);
temp.y = vec_dot (vec2, hand_pos3);
temp.z = 0; // if target is not in the span of the front vector, temp is not equal nullvector
vec_to_angle (vec1.pan, temp); // we re-use v1, as it is no longer needed
tempentity.roll = vec1.pan; // As temp.z is 0, only the pan of v1 will be set and that is our desired angle
}



Regards,
Gnometech


Download our playable Movement & Interaction Tutorial for 3DGS here:
http://www.puppenheim.org/MITutorial.zip

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