Advertisement

Projecting a Quad from light source and Normal Vector

Started by March 04, 2014 07:51 PM
0 comments, last by Tom Sloper 10 years, 11 months ago

Hi All,

I'm having a decal mesh( a quad) which has a shadow texture. and I have a bike, which has its forward direction, I have the normal to the ground, and normal touching point to ground. I have also the direction of light.

My quad on the floor has 4 vertices, so I assumed as the figure Points C,D is set to be parallel with the front wheel and the back wheel.

I would like to get the maths and get the points A, B with respect to the light direction.

My current code is : I would like to determine both vxPosSide2, and VxPosSide3


Quaternion rot = Quaternion.AngleAxis(Source.rotation.eulerAngles.y, normal) * Quaternion.FromToRotation(new Vector3(0, 1, 0), normal);
Vector3 pos = point + new Vector3(0, 0.1f, 0);
Color32 colorSideTexture = mRenderer.sharedMaterial.GetColor("_Color");

Vector3 vxPos1Side = pos + rot * (new Vector3(-1.4f, 0, -0.7f) * scale);
Vector3 vxPos2Side = pos + rot * (new Vector3(0, 0, -0.7f) * scale);
Vector3 vxPos3Side = pos + rot * (new Vector3(0, 0, 0.7f) * scale);
Vector3 vxPos4Side = pos + rot * (new Vector3(-1.4f, 0, 0.7f) * scale);
 
mDecalSide.SetVertex(0, vxPos1Side, colorSideTexture);
mDecalSide.SetVertex(1, vxPos2Side, colorSideTexture);
mDecalSide.SetVertex(2, vxPos3Side, colorSideTexture);
mDecalSide.SetVertex(3, vxPos4Side, colorSideTexture);

This is cross-posted in For Beginners. There's a reply in that thread, so I'm closing this one.

-- Tom Sloper -- sloperama.com

This topic is closed to new replies.

Advertisement