Jump to content

Advice, please, on normals


Innula Zenovka
 Share

You are about to reply to a thread that has been inactive for 275 days.

Please take a moment to consider if this thread is worth bumping.

Recommended Posts

The normal is basically the directional vector perpendicular to the surface. So you can use that along with something like llAxes2Rot to orient an object relative to the surface. I used this snippet in my ray tracer renderer.

list pRay = llCastRay (startPos,endPos,[RC_DATA_FLAGS,RC_GET_NORMAL]);
vector pHit = llList2Vector(pRay,1);
vector pNormal = llList2Vector(pRay,2);
// DEBUG: show visualization of surface normal (rezzes prim with its +z axis perpendicular to normal)
llRezObject("marker", pHit, ZERO_VECTOR, llAxes2Rot(pNormal%<1,0,0>%pNormal, pNormal%<1,0,0>, pNormal), 0);

In this case, since I wanted the top of the prim to be parallel with the surface normal, I used that as the "up" directional vector for llAxestoRot and used it with some cross product formulas to calculate the forward and left directions as well.

Edited by Fenix Eldritch
  • Like 1
  • Thanks 1
Link to comment
Share on other sites

30 minutes ago, Innula Zenovka said:

If I want to rez something flush to a sloping surface or to lay flat on some sloping ground, how do I do it, please?

High level stuff you already know: To rez an object tangent to another object, you need 3 pieces of (rotational) information:

  1. The normal of the surface being rezzed on
  2. The normal/axis of the object to be rezzed
  3. (semi-optional) the 'roll' the object will have when rezzed (I.E. if your thing is a piece of paper, where do the corners go?)

for sake of illustration, or if you ~really don't care about the roll (Ex. because your object is a cone/radially symetric) llRotBetween((2),(1)); should give you a semi-reasonable orientation:

vector a; vector b; // application dependant.
list ray = llCastRay(a,b,[RC_DATA_FLAGS,3]);

key k = llList2Key(ray,0);
vector pos = llList2Vector(ray,1);
vector normal = llList2Vector(ray,2);
// do some sanity checking on those, I've not tested in-world.
// if sanity passes:

vector up = <0,0,1>; // which vector points 'up' for the object?
float half_height = 1.0; // distance from ground to object center

llRezAtRoot("rez-me",pos+half_height*normal, <0,0,0>, llRotBetween(up,normal), 0);

ETA: I was going to explain the cross-product trick as an improvement, but Fenix already wrote out an example of it.

Edited by Quistess Alpha
  • Like 1
  • Thanks 1
Link to comment
Share on other sites

After mulling it over a bit in my sleep, I think in the specific case of rezzing something on the ground, in many/most situations, the most aesthetically pleasing 'roll' would take llGroundSlope/Contour into account to fix the y-axis. I haven't checked in-world but I think that would work something like:

// define variables as in previous examples, thrn
vector slope = llGroundSlope((pHit-llGetPos())/llGetRot());
llRezObject("marker", pHit+halfHeight*llVecNorm(pNormal), ZERO_VECTOR, llAxes2Rot(pNormal%slope, pNormal%slope%pNormal, pNormal), 0);

 

  • Thanks 1
Link to comment
Share on other sites

You are about to reply to a thread that has been inactive for 275 days.

Please take a moment to consider if this thread is worth bumping.

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
 Share

×
×
  • Create New...