You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently when cs_script returns a vector/qangle it will return a simple object instance with x,y,z/pitch,yaw,roll. This drastically limits how we can use them.
If these objects instead had a prototype point to another parent vector/qangle specific object both us and valve could extend the functionality of vectors/angles without adding overhead to every vector/angles instance. (JS uses object prototype as inheritance rather than classic class inheritance, when resolving object members the JS engine will first check the object, then go through the entire prototype chain)
What we would need to have implemented on the C++ side written how it would be done in js:
classVector{constructor(publicx: number,publicy: number,publicz: number){}}// Equivalent to:/*function Vector(x, y, z) { this.x = x; this.y = y; this.z = z;}*/classEntity{GetAbsOrigin(): Vector;// return new Vector(0,0,0)}// point_script.d.tsdeclareclassVector{x: number;y: number;z: number;// any out of the box methods}
and have Vector be exported in cs_script/point_script, this both allows us to call new Vector(0,0,0) to construct a vector in a nicer way, and more importantly if cs_script will always create an object instance with a prototype pointing to Vector it allows us to do
// declaration merge the Vector3 interfaceinterfaceVector3{equals: (other: Vector3)=>boolean;}// new Vector3(0,0,0).__proto__ === Vector3.prototypeVector3.prototype.equals=function(other: Vector3){returnthis.x===other.x&&this.y===other.y&&this.z===other.z}pawn.GetAbsOrigin().equals(newVector3(0,0,0));
Valve can then also add function members to the original Vector object and have them be available in every single instance of Vector and implement basic math operations on these.
This is our current custom vector/qangle API if there's any interest in implementing any of these in the prototypes out of the box
exportdeclareclassVec3{x: number;y: number;z: number;staticZero: Vec3;constructor(x: number,y: number,z: number);constructor(vector: Vector);getlength(): number;getlengthSquared(): number;getlength2D(): number;getlength2DSquared(): number;/** * Normalizes the vector (Dividing the vector by its length to have the length be equal to 1 e.g. [0.0, 0.666, 0.333]) */getnormal(): Vec3;getinverse(): Vec3;/** * Floor (Round down) each vector component */getfloored(): Vec3;/** * Calculates the angles from a forward vector */geteulerAngles(): Euler;toString(): string;equals(vector: Vector): boolean;add(vector: Vector): Vec3;subtract(vector: Vector): Vec3;divide(vector: Vector): Vec3;scale(vector: Vector): Vec3;scale(scale: number): Vec3;/** * Alias for Vec3.scale */multiply(vector: Vector): Vec3;multiply(scale: number): Vec3;dot(vector: Vector): number;cross(vector: Vector): Vec3;distance(vector: Vector): number;distanceSquared(vector: Vector): number;/** * Linearly interpolates the vector to a point based on a 0.0-1.0 fraction * Clamp limits the fraction to [0,1] */lerpTo(vector: Vector,fraction: number,clamp?: boolean): Vec3;/** * Gets the normalized direction vector pointing towards specified point (subtracting two vectors) */directionTowards(vector: Vector): Vec3;/** * Returns an angle pointing towards a point from the current vector */lookAt(vector: Vector): Euler;/** * Returns the same vector but with a supplied X component */withX(x: number): Vec3;/** * Returns the same vector but with a supplied Y component */withY(y: number): Vec3;/** * Returns the same vector but with a supplied Z component */withZ(z: number): Vec3;}
exportdeclareclassEuler{pitch: number;yaw: number;roll: number;staticZero: Euler;constructor(pitch: number,yaw: number,roll: number);constructor(angle: QAngle);/** * Returns angle with every componented clamped from -180 to 180 */getnormal(): Euler;/** * Returns a normalized forward direction vector */getforward(): Vec3;/** * Returns a normalized backward direction vector */getbackward(): Vec3;/** * Returns a normalized right direction vector */getright(): Vec3;/** * Returns a normalized left direction vector */getleft(): Vec3;/** * Returns a normalized up direction vector */getup(): Vec3;/** * Returns a normalized down direction vector */getdown(): Vec3;toString(): string;equals(angle: QAngle): boolean;/** * Linearly interpolates the angle to an angle based on a 0.0-1.0 fraction * Clamp limits the fraction to [0,1] * ! Euler angles are not suited for interpolation, prefer to use quarternions instead */lerp(angle: QAngle,fraction: number,clamp?: boolean): Euler;/** * Returns the same angle but with a supplied pitch component */withPitch(pitch: number): Euler;/** * Returns the same angle but with a supplied yaw component */withYaw(yaw: number): Euler;/** * Returns the same angle but with a supplied roll component */withRoll(roll: number): Euler;/** * Rotates an angle towards another angle by a specific step * ! Euler angles are not suited for interpolation, prefer to use quarternions instead */rotateTowards(angle: QAngle,maxStep: number): Euler;/** * Clamps each component (pitch, yaw, roll) between the corresponding min and max values */clamp(min: QAngle,max: QAngle): Euler;}
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Currently when cs_script returns a vector/qangle it will return a simple object instance with x,y,z/pitch,yaw,roll. This drastically limits how we can use them.
If these objects instead had a prototype point to another parent vector/qangle specific object both us and valve could extend the functionality of vectors/angles without adding overhead to every vector/angles instance. (JS uses object prototype as inheritance rather than classic class inheritance, when resolving object members the JS engine will first check the object, then go through the entire prototype chain)
What we would need to have implemented on the C++ side written how it would be done in js:
and have Vector be exported in
cs_script/point_script, this both allows us to callnew Vector(0,0,0)to construct a vector in a nicer way, and more importantly if cs_script will always create an object instance with a prototype pointing toVectorit allows us to doValve can then also add function members to the original Vector object and have them be available in every single instance of Vector and implement basic math operations on these.
This is our current custom vector/qangle API if there's any interest in implementing any of these in the prototypes out of the box
Beta Was this translation helpful? Give feedback.
All reactions