Mouse and vec_for_screen behavior question

Posted By: PHeMoX

Mouse and vec_for_screen behavior question - 06/19/07 05:36

I'm not using the quote code, however I am using exactly the same code for the vec_for_screen part, and that gives me the same deviation I'm currently dealing with.

If you click the object using this action you will be able to move it while it's under your mouse cursor, however, it's position will not stay exactly underneath the mouse cursor, instead, it has a deviation. The further you move the object away from the center, the bigger the deviation. (even if optical illusion, I don't want it to have this deviation...)

Code:
function pick_or_drop()
{
wait (1);
my.skill1 += 1;
if ((my.skill1 % 2) == 1) // clicked the object?
{
while (mouse_left == on) {wait (1);}
while (mouse_left == off) // move the object until the player presses the mouse button again
{
temp.x = pointer.x;
temp.y = pointer.y;
temp.z = 200; // move the object 200 quants below the camera, play with this value
vec_for_screen(temp.x, camera);
my.x = temp.x;
my.y = temp.y;
my.z = temp.z;
wait (1);
}
}
else // drop the object
{
vec_set (temp.x, my.x);
temp.z -= 3000;
trace_mode = ignore_me + ignore_sprites + ignore_models + use_box;
my.z -= trace (my.pos, temp); // place the object on the ground
}
}

action click_and_move
{
my.skill1 = 0;
my.enable_click = on;
my.event = pick_or_drop;
}



How can I fix this? I'm quite lost on how to solve this, especially because I don't quite get the problem. It should have the right coordinates because vec_for_screen took care of that, but apparently it doesn't quite.

The thing is, I'm trying to attach a particle effect to my mouse cursor using an object in 3D with a particle function attached. Thing is, the particle effect doesn't follow the cursor accurately, instead it has a huge deviation. I'm a total loss here, I've already tried adding certain values, but that only made it worse, probably because I do not quite understand the nature of this problem.

(by the way, "doing it the other way around" doesn't give deviations at all; meaning from 2D to 3D position like this;

Code:

bmap my_pcx = <my.pcx>;
panel my_pan
{
bmap = my_pcx;
layer = 15;
flags = overlay, refresh, visible;
}
function highlight_me()
{
var temporary;
while (1)
{
vec_set (temporary, my.x);
vec_to_screen (temporary, camera);
my_pan.pos_x = temporary.x;
my_pan.pos_y = temporary.y;
wait (1);
}
}
action my_entity
{
highlight_me(); // attach the panel to the entity
// put the rest of the code for your entity here
}


)



Edit: In the meantime I've got it working using a work-around, but any thoughts on this problem are still very welcome ..

Cheers
Posted By: George

Re: Mouse and vec_for_screen behavior question - 06/20/07 06:46

Attaching particles to the mouse pointer sounds fun. I'll post a snippet in the following magazine (should be out in a week or so).
Posted By: PHeMoX

Re: Mouse and vec_for_screen behavior question - 06/20/07 12:04

Thanks George, much appreciated.

Cheers
Posted By: MMike

Re: Mouse and vec_for_screen behavior question - 02/11/08 23:51

Quote:

Attaching particles to the mouse pointer sounds fun. I'll post a snippet in the following magazine (should be out in a week or so).



yeah how you did it! i also want to know..
Posted By: DavidLancaster

Re: Mouse and vec_for_screen behavior question - 02/13/08 13:27

If you're using lite-c then there might be a lag when you try and do that, all tactics to attach anything in the 3D world to a 2D position on the screen gives me a lag in lite-c. I could be wrong, it's what I ran into using lite-c and gave up and stuck with c-script I posted asking for an answer and got no response (I think).
© 2024 lite-C Forums