Help: CSQC VWEP Options?

Discuss CSQC related programming.
OneManClan
Posts: 247
Joined: Sat Feb 28, 2009 2:38 pm
Contact:

Help: CSQC VWEP Options?

Post by OneManClan »

Hi all.

[EDIT: 'VWEP' is short for ''visible weapon'. It refers the weapon you see in *other* players hands. I'm not sure if it's the 'standard jargon', because I didn't see any definitions anywhere they have been discussed. More info (but no definition)here]


Rather than getting into long, detailed (and possibly pointless) descriptions of everything I've tried (which hasn't worked!), I would like take a step back, and ask the following, 'open ended' question:

Q: What is the best (easiest, simplest, fastest, and smartest) way to implement VWEPS with Blender + CSQC?


So far, IIUC [disclaimer: this is newbie speculation] there seem to be two basic strategies:
Method 1: 'VWEP Follows the Hand-bone'
Make the VWEP (with no bone), and attach it to the players hand in CSQC. The players hand does all the movements. I tried this but found it impossible to align/position the VWEP in CSQC [Edit: one shouldn't be trying to position the asset in code, it should 'arrive' correctly positioned. More info in the posts below]. It appears attached to the players hand but the angles are wrong. I experimented with HEAPS of positions/settings/values, and I STILL can't figure out exactly how the Blender position of the iqm (ie at the time of export), relates to the CSQC positioning (at the time of attachment to the hand-bone).

Method 2: 'VWEP Self Animates'
Attach the VWEP to the players hand *in Blender*, delete the player model, and export the VWEP with all the player's animations. So now you have an instant 'self animating' VWEP. Import it into CSQC, and let the players current animation determine the VWEPS 'complimentary' animation. There's no need to animate them in CSQC. This is basically how SSQC VWEPS work. I haven't done this because I *assumed* that Method 1 was the 'way to do it'. ie thats what functions like gettaginfo(), and gettagindex() are for.. Hmm

Method 3: '??'
< this space available>


My current VWEP implementation is based on Hattify(), the CSQC Hat Method I just posted . Is it obsolete/inefficient/sub-optimal? :? [edit answer = yes, re the positioning bit] It does work ... apart from the wrongly angled VWEP:

Code: Select all

        
          // self is the player entity .. we're here as a result of :
          // deltalisten("progs/player.mdl", PutVWEPOnPlayer, 0);
          local vector vwep_pos;
          if(isnew)
        { 
          
          self.vwep  = spawn(); 
          
         }
      
          str = GetCurrentVWEP();
          
          setmodel(self.vwep, str);

          // give vwep_position the value of self's "right hand" bone position
          vwep_pos = gettaginfo(self, gettagindex (self, "Hand_R")); 

          //v_forward, v_right, v_up all auto-generated by gettagindex
          //[edit: the following 3 lines are VERY difficult to use! AND you shouldn't do aligning in the code]
          vwep_pos += v_forward * 0; // 
          vwep_pos -= v_right * 0;  // moves vwep up  [edit: no, it doesnt]
          vwep_pos += v_up * 0;  // move vwep forward away from players face

          // put the vwep on!
          setorigin(self.vwep, vwep_pos);

      
          // make self be the vwep for a sec       
          olself = self;
          self = self.vwep;
          // so we can rotate it, to compensate for Blender orientation differential
          rotatevectorsbyangle ('0 0 0'); // no value worked :( [edit: dont fix broken assett in code]
          self = olself;

          // make vwep turn and tilt based on self's angles
          self.vwep.angles = vectoangles(v_forward, v_up );

          self.vwep.renderflags = self.renderflags; // make it so player cant see their own vwep 
          self.vwep.drawmask = 1; // draw the vwep!
      
any advice/feedback appreciated
Last edited by OneManClan on Sat Mar 28, 2015 2:03 am, edited 7 times in total.
toneddu2000
Posts: 1395
Joined: Tue Feb 24, 2009 4:39 pm
Location: Italy

Re: Help: CSQC VWEP Options?

Post by toneddu2000 »

first of all, thanks for all these csqc models tutorials, really appreciated! For the VWEP part, I humbly think that the only correct method should be be the #1, because #2 is really unefficent: I mean, in this case, you'd have 2 skeletons doing the same thing! I think it's a waste of computation.

Shpuld, in its great Mobster Massacre (game source code available - great resource for learning FTE game development), used this approach (Note: this is for FTE, DP I dunno. And, franly, I don't care anymore of DP because it seems that LordHavoc ceased support / development, instead Spike is always behind some corner ready to help).

1.Model your weapon WITHOUT any bone (let's try without bone for now, maybe add a bone later if nothing happens! Sorry, it's my first time doing this for me too! :D ) and place weapon origin in Blender (on in your whatever 3d modeling software) where hand origin is placed.

2.Write this code

Code: Select all

//in csqc defs
entity myWeapon;

//in CSQC_Init
myWeapon = spawn();
setmodel(myWeapon, "models/yourweapon.iqm");
wep.renderflags += RF_NOSHADOW;

//in your player_predraw(or whatever) function
setorigin(wep,gettaginfo(self, gettagindex(self,"hand.r")));
myWeapon.angles = vectoangles(v_forward, v_up);

//in your CSQC_UpdateView
addentity(myWeapon);
Let me know if this helps
cheers
Last edited by toneddu2000 on Wed Mar 25, 2015 12:13 pm, edited 1 time in total.
Meadow Fun!! - my first commercial game, made with FTEQW game engine
toneddu2000
Posts: 1395
Joined: Tue Feb 24, 2009 4:39 pm
Location: Italy

Re: Help: CSQC VWEP Options?

Post by toneddu2000 »

I was thinking.. maybe, before

Code: Select all

myWeapon.angles = vectoangles(v_forward, v_up);
Add a makevectors, using as paramater your hand bone angles. That should orient correctly your weapon
Meadow Fun!! - my first commercial game, made with FTEQW game engine
Spike
Posts: 2914
Joined: Fri Nov 05, 2004 3:12 am
Location: UK
Contact:

Re: Help: CSQC VWEP Options?

Post by Spike »

gettaginfo sets v_forward/v_right/v_up according to the orientation of the specified bone/tag, returning the origin (it makes the entire 4*3 (world-space) bone matrix available).

by vwep, onemanclan means visible weapons - as in weapons that are visible on other players. he does not mean view weapons/models that are visible only to yourself.
viewmodels do not need to use gettaginfo on the player's model, as they can directly use the view's origin - they can normally do this with the RF_VIEWMODEL flag.
viewmodels should also use RF_DEPTHHACK renderflag to prevent it from poking through walls.

visible weapons, on the other hand, should use RF_EXTERNALMODEL on any models/entities attached to the local player's model, and no special flags for entities attached to other players. gettaginfo provides all the information required to glue the attached model to a bone in the parent model, assuming the attached model is centered around its attachment point in the model editor (ie: the attached model is positioned around 0 0 0 inside blender).
toneddu2000
Posts: 1395
Joined: Tue Feb 24, 2009 4:39 pm
Location: Italy

Re: Help: CSQC VWEP Options?

Post by toneddu2000 »

Spike wrote:by vwep, onemanclan means visible weapons - as in weapons that are visible on other players. he does not mean view weapons/models that are visible only to yourself.
viewmodels do not need to use gettaginfo on the player's model, as they can directly use the view's origin - they can normally do this with the RF_VIEWMODEL flag.
Ok, and how do you attach viewmodels to characters if not with gettaginfo? Imo what I wrote does not conflict with what you wrote
Meadow Fun!! - my first commercial game, made with FTEQW game engine
OneManClan
Posts: 247
Joined: Sat Feb 28, 2009 2:38 pm
Contact:

Re: Help: CSQC VWEP Options?

Post by OneManClan »

Hey guys.
Spike wrote:by vwep, onemanclan means visible weapons - as in weapons that are visible on other players. he does not mean view weapons/models that are visible only to yourself.
Yea, thanks for pointing that out toneddu2000, I assumed VWEP was a 'standard term'' for 'the weapon you see on *other* players hands' .. I'll edit my post .

Btw, Shpuld and Tomaz (on #qc last night ) also gave a big 'NO' to Method 2 "VWEP Self Animates", so Method 1 it is!
toneddu2000 wrote:place weapon origin in Blender (on in your whatever 3d modeling software) where hand origin is placed.
Yes .. I didn't really understand how to do this, but as was explained last night on #qc ( credit: Tomaz), Quake attaches a bone at wherever the '0 0 0' point was (in Blender), at the time of export. To put it another way: when you export from Blender, the '0 0 0' point/coordinate, ie the place where Blender's '0 0 0' is in your model, is what will be the the exact 'connection point' when you attach it to a bone. [There's gotta be a clearer/better way of describing/rephrasing that]

So the best 'system' to align the VWEP seems to be (Disclaimer:I'm still learning!):
  • 1. In Blender, load the player model
    2. Load the VWEP
    3. Position the VWEP to the players hand in the correct position

    Hmm I'm not sure if a bone is necessary... [Gurus?] maybe 3 should be

    3. Connect the VWEP to the players hand bone(?)

    4. Move the player and model so that the 'point of connection' is '0 0 0'
    5. Delete the player model
    6. Export the VWEP by itself
The other issue is that the model I'm workin' with is Capn Bubs model, which has an armature, but is NOT meant to be used as an iqm. ie the purpose of the bone was to move the model to match the movements of the original quake player, not to attach VWEPS to .. so the angle /position of the hand is not optimal. To put it another way, connecting the VWEP to the hand, and having it match the 'right hands position/angle' does not produce the most aesthetically pleasing look. My Blender skills are improving though, so maybe it wont be that much work to simply add an extra 'VWEP' bone to the player model, and use *that* to control the VWEPs position/angles... or..... even simpler ... just change/modify the angle of the Quake players right hand.. not sure what the best option is ..[..Gurus?]

Finally, all agreed with something Spike said recently, that the positioning/rotation/orientation of the model should be done in Blender, NOT in the qc. As Tomaz put it "code should not fix broken assets, broken assets should be fixed by the artist".
Seems kinda obvious now, but yea, the initial rotation/positioning should be done in Blender, once, and not by qc every frame!

Thanks to all for your input, I'll modify the hat tutorial now.
toneddu2000
Posts: 1395
Joined: Tue Feb 24, 2009 4:39 pm
Location: Italy

Re: Help: CSQC VWEP Options?

Post by toneddu2000 »

Maybe I do not understand what you're trying to do but.. why do you want to attach weapon directly in Blender? I mean, I consider weapon an entity. Full stop. An entity that could have some behaviour (firing particles, emitting sounds,etc).

Regarding placing pivot
Yes .. I didn't really understand how to do this,
  1. Modeling weapon in Blender.
    Image
  2. Now, to position pivot, you have 2 options:
    2a)Go in edit mode and move the entire mesh away from 0,0,0 pivot
    Image
    2b)right click to position cursor where do you want player characters should handle weapon
    Image
    Ctrl + Shift + Alt + C and choose "Origin to 3d cursor"
    Image
    Re-position entire object, in Object mode, to 0,0,0
    Image
  3. Now, no matter which options you chose at step 2, export only mesh as iqm
    Image
  4. Checked pivot with IQE Browser
    (Noesis has an endless grid which makes impossible to understand where pivot is, with this software, instead, grid is limited, so you can easily understand where pivot is)
    Image
Quake attaches a bone at wherever the '0 0 0' point was (in Blender), at the time of export. To put it another way: when you export from Blender, the '0 0 0' point/coordinate, ie the place where Blender's '0 0 0' is in your model, is what will be the the exact 'connection point' when you attach it to a bone. [There's gotta be a clearer/better way of describing/rephrasing that]
I seriously cannot understand how this should work
Meadow Fun!! - my first commercial game, made with FTEQW game engine
OneManClan
Posts: 247
Joined: Sat Feb 28, 2009 2:38 pm
Contact:

Re: Help: CSQC VWEP Options?

Post by OneManClan »

Note: for clarity, I'll be referring to 'the place on the VWEP where the right hand is supposed to connect' as the 'Grip'.
toneddu2000 wrote:Maybe I do not understand what you're trying to do but.. why do you want to attach weapon directly in Blender? I mean, I consider weapon an entity. Full stop. An entity that could have some behaviour (firing particles, emitting sounds,etc).
What I'm trying to do is to aligning the VWEP with the player. The VWEP doesn't have any 'behavior', other than following the player's (right hand) movements. The reason I want to use Blender to position (not 'attach') the VWEP is because every attempt I made to position it in the qc (as per the code in my first post) didn't work. Here's an earlier attempt where the VWEP (the rocket launcher) is connected to the hand bone. The right hand is at the Grip, but the angles are all wrong:
Image
I was trying to adjust/correct it in the code, but (unlike my hat code) found it IMPOSSIBLE, every adjustment messed up another adjustment. I tried opening Blender, putting the players right hand at '0 0 0', and then positioning the VWEP, but back in Quake (after attaching the grip to the hand in qc) it was *still* not connecting at the right angle. One of the the problems was:
toneddu2000 wrote:
OneManClan wrote: Quake attaches a bone at wherever the '0 0 0' point was (in Blender), at the time of export. To put it another way: when you export from Blender, the '0 0 0' point/coordinate, ie the place where Blender's '0 0 0' is in your model, is what will be the the exact 'connection point' when you attach it to a bone. [There's gotta be a clearer/better way of describing/rephrasing that]
I seriously cannot understand how this should work
So when attaching an entity to a bone, qc connects that entity's 'origin' to the hand bone, and the trouble was the VWEPs origin was NOT at the Grip. As your screenshots point out, the 'solution' to moving the origin was to move the model while in edit mode, so that the Grip was at Blenders '0 0 0' at the time of export.

This wasn't perfect (the angles were all messed up), BUT it allowed me to fix/adjust angles while keeping the Grip STILL, permanently connected to the handbone. Still a little fiddly, and I'm SURE there's a better method. The good thing is that once I positioned one VWEP correctly, it's position could used as a guide for the next one. I've already done 2. Though it's still a little fiddly..

As I said, I barely know what I'm doing here, so I hope that makes sense.. :)
Last edited by OneManClan on Tue Apr 21, 2015 3:06 am, edited 1 time in total.
frag.machine
Posts: 2126
Joined: Sat Nov 25, 2006 1:49 pm

Re: Help: CSQC VWEP Options?

Post by frag.machine »

OneManClan wrote:I tried opening Blender, putting the players right hand at '0 0 0', and then positioning the VWEP, but back in Quake (after attaching the grip to the hand in qc) it was *still* not connecting at the right angle.
origin != angles...
I know FrikaC made a cgi-bin version of the quakec interpreter once and wrote part of his website in QuakeC :) (LordHavoc)
OneManClan
Posts: 247
Joined: Sat Feb 28, 2009 2:38 pm
Contact:

Re: Help: CSQC VWEP Options?

Post by OneManClan »

frag.machine wrote:
OneManClan wrote:I tried opening Blender, putting the players right hand at '0 0 0', and then positioning the VWEP, but back in Quake (after attaching the grip to the hand in qc) it was *still* not connecting at the right angle.
origin != angles...
Yea, that was poorly phrased..... what I meant is that even after positioning the vwep in the players hand in Blender, ie so that it looked perfect, this did not 'translate' into the right angle in qc. Talking of angles, I had another look at:
toneddu2000 wrote:Checked pivot with IQE Browser
(Noesis has an endless grid which makes impossible to understand where pivot is, with this software, instead, grid is limited, so you can easily understand where pivot is)
Image[/list]
Maybe it *is* a pivot issue, and there's some pivot-related setting that needs to be .. er.. 'set' in Blender, so that the VWEP exports 'properly', ie appears at the correct angle when spawned into the players handbone.

I'm still hoping someone with more experience will be able to describe how to do this 'like a pro'. :)
Spike
Posts: 2914
Joined: Fri Nov 05, 2004 3:12 am
Location: UK
Contact:

Re: Help: CSQC VWEP Options?

Post by Spike »

using bones as tags requires that you pay attention to the orientation of the parent's bone inside blender. if the point you attach it to is oriented downwards, then the entire weapon shall also be pointed downwards. failing that, negate the forwards vector, then swap v_forward+_up around. but its much more sane to correct your model instead, especially if you're ever going to use alternative player models (where they'd each need different adjustments).
toneddu2000
Posts: 1395
Joined: Tue Feb 24, 2009 4:39 pm
Location: Italy

Re: Help: CSQC VWEP Options?

Post by toneddu2000 »

I tried this approach on my own and I found it very tricky to accomplish.
I first declared my weapon (created in Blender without bones)as entity

Code: Select all

void CSQC_Init(float apilevel, string enginename, float engineversion)
{
	//precaches
	precache_model(PLAYER_MODEL);
	precache_model(WEAPON_MODEL);
	rifle = spawn();
	rifle.predraw = Predraw_Rifle;
	setmodel(rifle,WEAPON_MODEL);
}
Than, in Player_predraw, I attached weapon to weapon player bone right (weapon_r)

Code: Select all

setorigin(rifle,gettaginfo(self, weapon_r));
In CSQC_UpdateView added

Code: Select all

addentity(rifle);
or the weapon won't be rendered

The weapon is correctly attached to weapon right bone but, weapon's orientation follows mouse input.
It only stays fixed if I add, in Player_Predraw

Code: Select all

self.angles_y = 0;
The weapon stays now fixed in its orientation to weapon bone, but, of course, when I rotate mouse on Y axis, the whole player body doesn't rotate anymore(logical! :D )!

I also tried to orient rifle entity to bone orientation (tried skel_get_boneabs and skel_get_bonerel ... same no result)

Code: Select all

vector weaponorientation = skel_get_boneabs(self.skeletonindex,weapon_r);
	if(rifle.angles_x != weaponorientation_x || rifle.angles_y != weaponorientation_y || rifle.angles_z != weaponorientation_z){
		rifle.angles_x = weaponorientation_x;
		rifle.angles_y = weaponorientation_z;
		rifle.angles_y = weaponorientation_z;
	}
But weapon still follows mouse input
:shock:

There's a way to "block" orientation of an entity?
Thanks!
Meadow Fun!! - my first commercial game, made with FTEQW game engine
toneddu2000
Posts: 1395
Joined: Tue Feb 24, 2009 4:39 pm
Location: Italy

Re: Help: CSQC VWEP Options?

Post by toneddu2000 »

I found a workaround. In my project I created a third person view and when I attached weapon to hand bone and then moving mouse, the weapon rotated in opposite direction of player(didn't try if this happens with first person view too).
First I created a function that should have oriented the weapon. It took 2 parameters:

Code: Select all

void WeaponOrient(vector org,vector ang)
{
	rifle.origin_x = org;
	rifle.angles_x = ang;
}
then in player predraw

Code: Select all

float weapon_r = skel_find_bone(self.skeletonindex,"weapon_r");
vector hand_r_angles = skel_get_boneabs(self.skeletonindex,weapon_r);
vector hand_r_org = gettaginfo(self,hand_r);
vector hand_r_org2 = skel_get_bonerel(self.skeletonindex,weapon_r);//not used - if used with setorigin, weapon remains on the ground- left here just for let you know that it doesn't do anything
WeaponOrient(hand_r_org,hand_r_angles );
The weapon followed player weapon bone, it was correctly aligned (SUPER correctly I must say) with bone relative orientation (thanks to skel_get_boneabs that, unfortunately, doesn't store position) but, when rotating mouse left/right, it rotated in the opposite way of player, "thanks" to gettaginfo that, I don't know why, if you use it as 2# parameter for setorigin, somehow it sets angles too.


So I changed my function with:

Code: Select all

void WeaponOrient(vector org)
{
	rifle.origin = org;
	rifle.angles_x = -view_angles_x; //it corrects counter rotation on mouse input
	rifle.angles_y = view_angles_y; 
	rifle.angles_z = view_angles_z;
}
and in player predraw

Code: Select all

float weapon_r = skel_find_bone(self.skeletonindex,"weapon_r");
vector hand_r_org = gettaginfo(self,hand_r);
WeaponOrient(hand_r_org);
Now, I must say it's a NON-perfect but decent result. The weapon doesn't follow bone orientation anymore but it's now aligned perpendicular with player, which maybe it's better, because, even if your wrist is a little misaligned on its local X axis, when you handle a weapon you try to put it as much as perpendicular to your body(I guess, at least! :)) so I think it's viable solution. Weapon model is just mesh. No skeleton.

EDIT: I forgot, I also tried to use setattachment (which it seems that Xonotic uses it too), but with no results. ftextensions says that it could be used even for csqc but weapon doesn't move of a 1/2 centimeter from the ground.
On ssqc it works only if I remove all the SendEntity to csqc and, no csqc -> no skeleton so I cannot attach it to bone but only to md3 tag I think. Anyway this wasn't a solution imo
Meadow Fun!! - my first commercial game, made with FTEQW game engine
Spike
Posts: 2914
Joined: Fri Nov 05, 2004 3:12 am
Location: UK
Contact:

Re: Help: CSQC VWEP Options?

Post by Spike »

toneddu2000, I'm not sure what you're even trying to do, iiuc you're trying to position a viewmodel (as opposed to a vwep) directly on the player's model instead of simply positioning it in screenspace?

either way, you seem confused about what the various builtins return that you've decided to randomly call, so I'll try to describe them again:

skel_get_boneabs:
directly returns the modelspace position of the bone, also obtains the orientation via storing to the v_forward/v_right/v_up vectors (like makevectors does).
I'll say that again, returns a POSITION, not an ANGLE.
the result matrix is in model space. that is it does not consider the origin of the entity because there IS no specific entity to which it should be oriented.
because this is modelspace, positions won't be much larger than the entity's bbox.

gettaginfo:
exactly like skel_get_boneabs, but the result is in world space. uses the specified entity's skeleltal object, or the current frame if none is specified.

skel_get_bonerel:
exactly like skel_get_boneabs, except the result is relative to its parent bone, and thus will be quite small.
toneddu2000
Posts: 1395
Joined: Tue Feb 24, 2009 4:39 pm
Location: Italy

Re: Help: CSQC VWEP Options?

Post by toneddu2000 »

Spike wrote:toneddu2000, I'm not sure what you're even trying to do, iiuc you're trying to position a viewmodel (as opposed to a vwep) directly on the player's model instead of simply positioning it in screenspace?
No Spike, I tried to do what onemanclan tried: position a vwep to a model in csqc. The most obvious way to test vwep model position every time was to create a third person view from above (the other way was to start a server, connect 2 clients and see other player weapon but this method is faster imo)and see eventual errors.
either way, you seem confused about what the various builtins return that you've decided to randomly call
:) probably. Anyway problem remains: if you want that a model is ORIENTED (not positioned) relatively to a bone, how di you do.
Image

Image

The only way I found to align a model relatively to a bone is using skel_get_boneabs. Gettaginfo is useful for POSITION (so, if you attach with setorigin vwep model to a bone with gettaginfo it remains attached BUT NOT ALIGNED)
The problem is that, if you try to use setorigin with skel_get_boneabs, model will not be attached to bone.

Have I been detailed in what I understood?
Meadow Fun!! - my first commercial game, made with FTEQW game engine
Post Reply