This is an archived snapshot of W3C's public bugzilla bug tracker, decommissioned in April 2019. Please see the home page for more details.

Bug 30098 - What is the w (perspective) value for?
Summary: What is the w (perspective) value for?
Status: RESOLVED MOVED
Alias: None
Product: FXTF
Classification: Unclassified
Component: Geometry (show other bugs)
Version: unspecified
Hardware: PC All
: P2 normal
Target Milestone: ---
Assignee: Simon Pieters
QA Contact: sideshowbarker+geometry
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2017-04-23 19:49 UTC by Joe Pea
Modified: 2018-04-15 18:10 UTC (History)
3 users (show)

See Also:


Attachments

Description Joe Pea 2017-04-23 19:49:57 UTC
https://drafts.fxtf.org/geometry/#DOMPoint

[[
The following algorithms assume that DOMPointReadOnly objects have the internal member variables x coordinate, y coordinate, z coordinate and w perspective.
]]

What is the w (perspective) value used for? I would've assumed a point was only an x,y,z triplet. Why is the w needed? And what is a good value to default to?

If I may guess (let me know how close I am), the perspective value is useful if you are going to call `matrixTransform(matrix)` and will pass a `matrix` that is based on some perspective?

So, for example, if I have a CSS 3D nested DOM hierarchy, where each element in the hierarchy has CSS transform, and the root node has CSS perspective:1000px, and the root node has only a 2d transform (for example the root node is the body with only width and height applied, it is drawn in screen CSS pixels, and has perspective applied to it) then if I want to transform a point from the screen coordinates (body client coordinates) to some point in a nested element inside the 3D space, then would I first multiply the matrices from the nested element up to the root, then set `w` on my DOMPoint to `1000`, and finally call `point.matrixTransform(matrix)` where `matrix` is the nested element's world matrix that I just calculated?

It would be nice if the geometry-interfaces could link to appropriate articles on how to use the interfaces (not just describe how they are implemented). Is that something that would be fine to add to the specs?
Comment 1 Joe Pea 2017-04-23 20:27:50 UTC
Maybe I just don't have enough theory background, but I think it would be great to link to relevant articles from the specs.

So far I have a function that I wrote which traverses from a (grandchild)child node somewhere in the DOM "scene graph" up to the root, 

```
function multiply(target) {
    let result = new DOMMatrix;

    while (target && !(target instanceof Scene)) {
        const m = target._calculateMatrix()
        result.preMultiplySelf(m)
        target = target.parent
    }

    return result
}
```

The `Scene` instance is just a non-transformed HTMLElement that has `perspective:800px` applied to it, and all nodes inside the Scene (including Scene) have `transform-style: preserve-3d`.

What I am trying to do is map a click event on the screen to a point on the an element that was clicked (clientX and clientY don't work, those are screen pixel coordinates, not coordinates relative to the clicked element which may be transformed to anywhere in 3D space).

So I thought I could do something like the following where `node` is a reference to an HTMLElement somewhere inside the "scene graph":

```
// traverse from nested node to root node and multiply on the way
const matrix = multiply(node)

DOMPoint(clickX, clickY, 0, 800)
```

Is this how to do it?

I'm implementing DOMPoint.matrixTranform at the moment so that I can try this idea out (https://github.com/trusktr/geometry-interfaces/blob/master/src/DOMPoint.js). If you have any feedback on that, I would be glad to hear it.
Comment 2 Simon Pieters 2017-05-04 22:40:41 UTC
Dirk, Rik, can you help with this?

I wouldn't mind the spec having an introductory section or relevant links, or both.
Comment 3 Dirk Schulze 2018-04-15 18:10:46 UTC
https://github.com/w3c/fxtf-drafts/issues/276