Quick alternative to projection() using multmatrix()

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Quick alternative to projection() using multmatrix()

gingerbeardman
This post was updated on .
I want to render a "footprint" shadow of a car, which is enough of a
convincing shadow for me to use in a video game I am making.

I tried using projection() as follows:

module shadow() {
  color([0,0,0, 1])
  projection()
  car();
}

...but it was slow.

So I had the idea to squash the model down on the z-axis into a "flat"
surface, which is close enough to what i need and very quick:

module shadow() {
  flattenZ = [[ 1  , 0  , 0  , 0  ],
        [ 0  , 1  , 0 , 0  ],
        [ 0  , 0  , 0.01  , 0  ],
        [ 0  , 0  , 0  , 1  ] ];

  color([0,0,0, 1])
  multmatrix(flattenZ)
  car();
}

As you can see it's not quite flat, but 0.01 flat, which avoids
z-fighting and is not noticeable to the eye.

Thought this was worth sharing.

--
Sent from: http://forum.openscad.org/
_______________________________________________
OpenSCAD mailing list
To unsubscribe send an email to discuss-leave@lists.openscad.org
Reply | Threaded
Open this post in threaded view
|

Re: Quick alternative to projection() using

Whosawhatsis
I've used scale() for this in the past. It obviously doesn't let you render or do booleans as if it was 2D, but when you just need the projection for visual purposes, it works fine.
On May 3, 2021, 13:30 -0700, gingerbeardman <[hidden email]>, wrote:
I want to render a "footprint" shadow of a car, which is enough of a convincing shadow for me to use in a video game I am making.

I tried using projection() as follows:

module shadow() {
  color([0,0,0, 1])
  projection()
  car();
}
...but it was slow.

So I had the idea to squash the model down on the z-axis into a "flat" surface, which is close enough to what i need and very quick:

module shadow() {
  flattenZ = [[ 1  , 0  , 0  , 0  ],  
       [ 0  , 1  , 0  , 0  ],  
       [ 0  , 0  , 0.01  , 0  ],  
       [ 0  , 0  , 0  , 1  ] ];  

    color([0,0,0, 1])
    multmatrix(flattenZ)
    car();
}
As you can see it's not quite flat, but 0.01 flat, which avoids z-fighting and is not noticeable to the eye.

Thought this was worth sharing.


Sent from the OpenSCAD mailing list archive at Nabble.com.
_______________________________________________
OpenSCAD mailing list
To unsubscribe send an email to [hidden email]


_______________________________________________
OpenSCAD mailing list
To unsubscribe send an email to [hidden email]
Reply | Threaded
Open this post in threaded view
|

Re: Quick alternative to projection() using

nophead
Yes I think the matrix is the same as scale([1,1,0.01])

On Mon, 3 May 2021 at 21:35, Whosawhatsis <[hidden email]> wrote:
I've used scale() for this in the past. It obviously doesn't let you render or do booleans as if it was 2D, but when you just need the projection for visual purposes, it works fine.
On May 3, 2021, 13:30 -0700, gingerbeardman <[hidden email]>, wrote:
I want to render a "footprint" shadow of a car, which is enough of a convincing shadow for me to use in a video game I am making.

I tried using projection() as follows:

module shadow() {
  color([0,0,0, 1])
  projection()
  car();
}
...but it was slow.

So I had the idea to squash the model down on the z-axis into a "flat" surface, which is close enough to what i need and very quick:

module shadow() {
  flattenZ = [[ 1  , 0  , 0  , 0  ],  
       [ 0  , 1  , 0  , 0  ],  
       [ 0  , 0  , 0.01  , 0  ],  
       [ 0  , 0  , 0  , 1  ] ];  

    color([0,0,0, 1])
    multmatrix(flattenZ)
    car();
}
As you can see it's not quite flat, but 0.01 flat, which avoids z-fighting and is not noticeable to the eye.

Thought this was worth sharing.


Sent from the OpenSCAD mailing list archive at Nabble.com.
_______________________________________________
OpenSCAD mailing list
To unsubscribe send an email to [hidden email]

_______________________________________________
OpenSCAD mailing list
To unsubscribe send an email to [hidden email]

_______________________________________________
OpenSCAD mailing list
To unsubscribe send an email to [hidden email]
Reply | Threaded
Open this post in threaded view
|

Re: Quick alternative to projection() using

gingerbeardman
Oh, yes!

Would they be equivalent in terms of performance?

Sent from the OpenSCAD mailing list archive at Nabble.com.

_______________________________________________
OpenSCAD mailing list
To unsubscribe send an email to [hidden email]
Reply | Threaded
Open this post in threaded view
|

Re: Quick alternative to projection() using

nophead
Yes, scale() just fills in a matrix that looks exactly the same as the one you created, so it will be slightly faster done in C++ rather than OpenSCAD.

On Mon, 10 May 2021 at 21:26, gingerbeardman <[hidden email]> wrote:
Oh, yes!

Would they be equivalent in terms of performance?

Sent from the OpenSCAD mailing list archive at Nabble.com.
_______________________________________________
OpenSCAD mailing list
To unsubscribe send an email to [hidden email]

_______________________________________________
OpenSCAD mailing list
To unsubscribe send an email to [hidden email]