Innula Zenovka Posted July 27, 2023 Share Posted July 27, 2023 I'm afraid I've never really understood how to use llGroundNormal or the RC_GET_NORMAL flag in llCastRay. 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? Link to comment Share on other sites More sharing options...
Fenix Eldritch Posted July 27, 2023 Share Posted July 27, 2023 (edited) 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 July 27, 2023 by Fenix Eldritch 1 1 Link to comment Share on other sites More sharing options...
Quistess Alpha Posted July 27, 2023 Share Posted July 27, 2023 (edited) 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: The normal of the surface being rezzed on The normal/axis of the object to be rezzed (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 July 27, 2023 by Quistess Alpha 1 1 Link to comment Share on other sites More sharing options...
Quistess Alpha Posted July 27, 2023 Share Posted July 27, 2023 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); 1 Link to comment Share on other sites More sharing options...
Recommended Posts
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