Hi, a little rectification to my previous answer;
actually, storing the "reference frame" at Firing time (and then describing the motion of the bullet in such reference frame) will produce the same result as describing the bullet motion in Camera reference fram (instead of world reference frame).
The problem with your scenario is that Vuforia provides two reference frames, one is the World as defined by one of your targets, and the other is the Camera reference frame; these two frames are linked to each other by the trackable Pose transformation.
You would need in theory a "third" reference frame, a sort of "static" world reference that never changes, so that both the camera and the target reference frames can be represented with respect to such "static" frame.
So, the only way you can do this is to use 2 Image Targets (or FrameMarkers) instead of one:
- the first Image Target can be used to define the "static" reference frame
- the second Image target can be used to define the "moving target" reference frame (i.e. your moving target); the idea is that so you can move Image Target 2 (which is the target at which you want to shoot your bullet), while keeping the first Image target fixed at some position
In Unity + Vuforia, it is then quite easy to setup such scenario, as you just need to change the World Center Mode in the ARCamera game-object
(just click on the ARCamera object and check the World Center Mode property in the Inspector);
By default, this is set to Auto, which means that the World Reference frame will automatically be centered on the First Image Target detected
(so, if you have two image targets, the first one detected defines the World Ref; however, if you loose tracking of such Image Target, then the Worlkd Center will be recentered onto the other target)
So, you will need to set the World Center Mode to "USER"; when you do so, an exra field called "World Center" will appear, and there you can specify which Image target should always be used as World Center.
If you do so, the bullet will move in the world reference of the first target, while you will be able to move around with your hands the second target, achieving (hopefully) the desired effect.
I hope this helps.
Hi, your problem is about choosing a "world reference" system that fits your expectations:
As you know already, the trackable->getPose() method returns a matrix which represents the target reference frame as seen from the camera point of view.
The usual assumption would be to consider the marker reference frame (as reported via the pose) as the "World" reference frame;
with that assumption, your bullet will move in the world reference frame defined by the target.
To avoid this, you can take one of these two paths:
1. describe the bullet motion in the camera reference frame (this will attach the bullet trajectory to your camera...but maybe this is not what you wish in this case)
OR:
2. store the Pose of the marker at the time when the bullet is created/fired (i.e. save the pose into some global variable for instance), so that the frame marker reference frame AT THAT TIME (bullet creation) is "frozen"; then, this frozen frame will define your World reference frame during all the life-time of your bullet.
So, basically, you set the world reference frame at bulet creation, then the bullet motion occurs in that reference system, instead of following the continuously changing reference frame of the marker (which is changing at every frame).
In the OpenGL code, when you redner your bullet, you simply need to use the modelview matrix that was saved at the time of bullet creation;
for the marker rendering instead, you can keep using the actual Pose matrix which is updated every frame.
I hope this helps.