Rezzing a cube flat against any sloped ground
|
Al Bravo
Retired
Join date: 29 Jun 2004
Posts: 373
|
10-04-2005 12:27
I'm trying to rez a flattened cube(3x3x0.01) flat against the ground no matter what the slope of the ground may be (standard +z up). I know that llGroundSlope or llGroundNormal are involved to get the rotation for llRezObject. But, I'm not quite sure how to produce the right rotation based on the ground information. I have no problem getting the correct ground height at the specific spot. It is just the rotation formula that escapes me. Any help?
|
Cid Jacobs
Theoretical Meteorologist
Join date: 18 Jul 2004
Posts: 4,304
|
10-04-2005 13:09
From: Al Bravo I'm trying to rez a flattened cube(3x3x0.01) flat against the ground no matter what the slope of the ground may be (standard +z up). I know that llGroundSlope or llGroundNormal are involved to get the rotation for llRezObject. But, I'm not quite sure how to produce the right rotation based on the ground information. I have no problem getting the correct ground height at the specific spot. It is just the rotation formula that escapes me. Any help? hum, I can't get in world right now. But I think what you may be after would go something like this: llSetRot( llGetRot() * llRotBetween( ( llRot2Up( llGetRot( ) ) ) * llGetRot( ), llGroundSlope( ZERO_VECTOR ) ) ); If that's wrong, I'm sure someone will follow shortly to correct me  .
|
Cletus Fardel
Registered User
Join date: 5 Oct 2005
Posts: 6
|
10-05-2005 08:42
It would be a great idea. I have no idea how to do it though. Please share with us if you figure it out 
|
Cid Jacobs
Theoretical Meteorologist
Join date: 18 Jul 2004
Posts: 4,304
|
10-05-2005 08:58
Well, I managed to go in world today and wrote up a small snippet of code. I was a bit off though. The rotation the above code was defining wasn't on the axis you wanted. It shouldve been llRot2Left. But anywho, here is a quick snippet that may help? vector current; vector old; default { state_entry() { llSetTimerEvent(10); }
timer() { current = llGetPos(); if(old != current) { llSetRot(ZERO_ROTATION); llSetRot( llGetRot() * llRotBetween( ( llRot2Left( llGetRot( ) ) ) * llGetRot( ), llGroundSlope( ZERO_VECTOR ) ) ); old = current; } } }
|
Ralan Gall
Registered User
Join date: 13 Sep 2005
Posts: 3
|
10-05-2005 09:18
So you want it to go to the ground when you rez it? In that case all the code above would do is rotate it to the the correct angle. This would probably move it to the ground: /////////////////////////////////////////////////////////////////////////////////////////////////////// // Our vector where we are moving it to. vector vMoveToGround; // Set where to move to our current position. vMoveToground = llGetPos(); // Set where to move to's Z a.k.a. up and down to the grounds current height. vMoveToground.z -= llGround(<0,0,0>  ; // This is optional so feel free to comment this out; this is just to make sure it //jabs into the ground. llSet postion can never make an object go through //the ground. vMoveToground.z -= 1; //Set the objects position to the ground. llSetPos(vMoveToground); /////////////////////////////////////////////////////////////////////////////////////////////////////// That combined with the code above should work but i'm at school right now so i can't really test it.
|
Cid Jacobs
Theoretical Meteorologist
Join date: 18 Jul 2004
Posts: 4,304
|
10-05-2005 09:40
From: Ralan Gall That combined with the code above should work but i'm at school right now so i can't really test it.
I think all he was looking for was the rotation part, but you know.... I have the feeling we will soon see sims filled with plywood floors curving along every hill! The horror. The horror!! 
|
Al Bravo
Retired
Join date: 29 Jun 2004
Posts: 373
|
10-05-2005 10:22
Thanks all - actually this is for a single game piece. I am rezzing it at ground height. So all I really needed was the rotation bit. This has put me in the right direction. Thanks again.
|
RyeDin Meiji
Reluctant Entrepeneur
Join date: 15 Mar 2005
Posts: 124
|
10-05-2005 12:57
You guys are going to laugh at how simple this can be (I think...)... When you need to set the cube's rotation as you described, have the script set physical to true. If you set it up properly so it's not falling from too far, the cube should end up how you want it. You may need to place a non-physical prim just below that spot on the hill to prevent your cube from sliding down. Anyway, once you've figured out how long you need to keep the cube physical for it to settle into place (some sort of timer or a touch event to tell it to freeze), have the script set physical to false again. So maybe you can do all the above in the on_rez event for your example...
_____________________
if (!you) { who(); }
|
Cid Jacobs
Theoretical Meteorologist
Join date: 18 Jul 2004
Posts: 4,304
|
10-05-2005 13:02
From: RyeDin Meiji You guys are going to laugh at how simple this can be (I think...)... When you need to set the cube's rotation as you described, have the script set physical to true. If you set it up properly so it's not falling from too far, the cube should end up how you want it. You may need to place a non-physical prim just below that spot on the hill to prevent your cube from sliding down. Anyway, once you've figured out how long you need to keep the cube physical for it to settle into place (some sort of timer or a touch event to tell it to freeze), have the script set physical to false again. So maybe you can do all the above in the on_rez event for your example... Thats a bit hacky, plus the physics engine doesnt really calculate the exact slope, it's more of a "best guess". While you could kind of fake it with physics, I still believe llSetRot is the best answer here........ plus it's faster 
|
RyeDin Meiji
Reluctant Entrepeneur
Join date: 15 Mar 2005
Posts: 124
|
10-05-2005 13:05
I love hacky black magic kung fu type solutions. 
_____________________
if (!you) { who(); }
|