Create a free account to remove all ad content.

Author Topic:  How would I go about doing this?  (Read 569 times)

0 Members and 1 Guest are viewing this topic.

Dryym

  • Supreme Member
  • *
  • Posts: 4336
  • What's yours is mine. ~TM's Resident Master Thief~
    • View Profile
  • Xbox: dryym
How would I go about doing this?
« on: August 17, 2016, 07:22:10 AM »
I am very close to getting velocity relative to view direction done.
I have a system which seems to be returning velocity on each axis dependant on my view direction. And I had it all translated into a single velocity number. (Which has a bug that I worked out the fix for in my head.)

But I have one thing that needs to be done to get this fully working.

I need to be able to get a vector that is perpendicular to the view vector so that I can test for velocity along the right|left axis.


How would I go about doing this? I really have no clue.

Creator of the term "Deathmine "
Jared [19|Oct 07:12 PM]: "It changes everything" Dryym

Craig

  • Developer
  • Extreme Member
  • *
  • Posts: 6655
  • Dig Deep
    • View Profile
    • Twitter
  • Steam: tota1miner
Re: How would I go about doing this?
« Reply #1 on: August 17, 2016, 08:12:06 AM »
right = normalize(cross(forward, up))

up x,y,z = 0,1,0
forward x,y,z = view:x,y,z

cross product:
right.x = up.y * forward.z - up.z * forward.y;
right.y = up.z * forward.x - up.x * forward.z;
right.z = up.x * forward.y - up.y * forward.x;

normalize:
magnitude = sqrt(right.x * right.x + right.y * right.y + right.z * right.z);
right.x /= magnitude;
right.y /= magnitude;
right.z /= magnitude;

right is now your vector


Script: CrossProduct
var [x1] [y1] [z1] [x2] [y2] [z2]
var [x] = [y2] * [z1]
var [x] = [x] - [z2] * [y1]
var [y] = [z2] * [x1]
var [y] = [y] - [x2] * [z1]
var [z] = [x2] * [y1]
var [z] = [z] - [y2] * [x1]

Script: Normalize
var [x] [y] [z]
//var [mag] = [x] * [x]
//var [mag] = [mag] + [y] * [y]
//var [mag] = [mag] + [z] * [z]
//var [mag] = [sqrt:mag] // 2.5 only
var [mag] = [distance:[0,0,0][x,y,z]]
var [x] = [x] / [mag]
var [y] = [y] / [mag]
var [z] = [z] / [mag]

Script: GetRightVector
var [x1] [y1] [z1] // forward vector
var [x2] = [0] // up vector
var [y2] = [1] // up vector
var [z2] = [0] // up vector
var [x] [y] [z] // right vector (result)
script [CrossProduct] [vars:x1,y1,z1,x2,y2,z2] [out:x,y,z]
script [Normalize] [out:x,y,z]

Script: Dryym
var [x1] = [view:x]  // forward
var [y1] = [view:y]  // forward
var [z1] = [view:z]  // forward
var [x] [y] [z]  // right
script [GetRightVector] [vars:x1,y1,z1] [out:x,y,z]
// x,y,z are now your right vector

I just typed it in, it isn't tested, so it probably has errors, I'll check it tmrw morning, it's too late now.
« Last Edit: August 17, 2016, 07:25:54 PM by Craig »

Dryym

  • Supreme Member
  • *
  • Posts: 4336
  • What's yours is mine. ~TM's Resident Master Thief~
    • View Profile
  • Xbox: dryym
Re: How would I go about doing this?
« Reply #2 on: August 17, 2016, 08:33:13 AM »
So this is completely (I mean, I guess not completely if I script an algorithm.) undoable in 2.44 with the lack of a sqrt function?

Creator of the term "Deathmine "
Jared [19|Oct 07:12 PM]: "It changes everything" Dryym

Craig

  • Developer
  • Extreme Member
  • *
  • Posts: 6655
  • Dig Deep
    • View Profile
    • Twitter
  • Steam: tota1miner
Re: How would I go about doing this?
« Reply #3 on: August 17, 2016, 08:51:07 AM »
You could still use the right vector without the normalization, it just wouldn't be normalized. The direction will still be true.

But there's a workaround to use [distance:] instead of [sqrt:] it's actually shorter.

My op edited.

I changed the var names, because they have to be the same in each script when passed to/from.
« Last Edit: August 17, 2016, 09:26:41 AM by Craig »

Dryym

  • Supreme Member
  • *
  • Posts: 4336
  • What's yours is mine. ~TM's Resident Master Thief~
    • View Profile
  • Xbox: dryym
Re: How would I go about doing this?
« Reply #4 on: August 17, 2016, 09:54:36 AM »
This is an interesting problem. I have the scripts set up exactly as you have them here.

The only exceptions being that my var names and such are different, And I added the [wait] param to all "Script" commands to try to fix the issue I was having.


I have this tied to a HUDText loop in the form of "Script [VecRight] //What I named the script labeled "Dryym" here. [wait] [out:rx,ry,rz]"


It is a default speed loop, And the right vector text normally does not get updated, But when I put a notify command at the end of the "VecRight" script, The HUDText does get updated. It is really really weird, And I don't understand why the status of one notify command determines whether or not it works.



Creator of the term "Deathmine "
Jared [19|Oct 07:12 PM]: "It changes everything" Dryym

Craig

  • Developer
  • Extreme Member
  • *
  • Posts: 6655
  • Dig Deep
    • View Profile
    • Twitter
  • Steam: tota1miner
Re: How would I go about doing this?
« Reply #5 on: August 17, 2016, 07:25:38 PM »
I don't know, I'd have to see the scripts. But the scripts are working correctly here, I just tested them. The HUDTest updates correctly without any workarounds. btw the [wait] param is automatic if you have an [out:] param on that line, so adding it won't change anything.

Dryym

  • Supreme Member
  • *
  • Posts: 4336
  • What's yours is mine. ~TM's Resident Master Thief~
    • View Profile
  • Xbox: dryym
Re: How would I go about doing this?
« Reply #6 on: August 17, 2016, 07:30:46 PM »
I don't know, I'd have to see the scripts. But the scripts are working correctly here, I just tested them. The HUDTest updates correctly without any workarounds. btw the [wait] param is automatic if you have an [out:] param on that line, so adding it won't change anything.

Oddly enough, Adding a wait command for 1 ms at the end of the VecRight script makes it work just fine.

If I notice any other problems, I'll post here.

Creator of the term "Deathmine "
Jared [19|Oct 07:12 PM]: "It changes everything" Dryym

Craig

  • Developer
  • Extreme Member
  • *
  • Posts: 6655
  • Dig Deep
    • View Profile
    • Twitter
  • Steam: tota1miner
Re: How would I go about doing this?
« Reply #7 on: August 17, 2016, 08:00:40 PM »
Oddly enough, Adding a wait command for 1 ms at the end of the VecRight script makes it work just fine.
That typically means the problem is elsewhere. I would like to be able to duplicate so I can fix, but I can't duplicate here. It works without these hacks.

Dryym

  • Supreme Member
  • *
  • Posts: 4336
  • What's yours is mine. ~TM's Resident Master Thief~
    • View Profile
  • Xbox: dryym
Re: How would I go about doing this?
« Reply #8 on: August 17, 2016, 08:09:23 PM »
Oddly enough, Adding a wait command for 1 ms at the end of the VecRight script makes it work just fine.
That typically means the problem is elsewhere. I would like to be able to duplicate so I can fix, but I can't duplicate here. It works without these hacks.

Next time I get on TM, I'll take pictures of every part of each script for you.

Creator of the term "Deathmine "
Jared [19|Oct 07:12 PM]: "It changes everything" Dryym

Phearcia

  • Member
  • *
  • Posts: 157
    • View Profile
  • Xbox: Phearcia
Re: How would I go about doing this?
« Reply #9 on: September 11, 2016, 07:18:35 PM »
Was this the solution?