Limit rain to an area
by Chris Labombard · 06/26/2005 (10:39 am) · 12 comments
This is farily simple to do...
First off, back up you Torque project, as I take no responsibility for you messing anything up.
Ok... Open up your ide. navigate to engine/game/fx/precipitation.cc
comment out the following lines:
671
672
676 - 681
and add the following lines below line 681:
It should now look like this:
save it. compile it. Run it.
ok... Now place a precipitation object...
F11 -> F4 ... mission -> environment -> precipitation ... name it rain so it's easy to find.
ok. Now find the rain object and move it where you want it. If you can't see any rain it is probably too low.
apply any changes. Save. Hit F11 again.
Now run around. you should be able to run in and out of the raining area...
First off, back up you Torque project, as I take no responsibility for you messing anything up.
Ok... Open up your ide. navigate to engine/game/fx/precipitation.cc
comment out the following lines:
671
672
676 - 681
and add the following lines below line 681:
Box3F box(getPosition().x - mBoxWidth / 2, getPosition().y - mBoxWidth / 2, getPosition().z - mBoxHeight / 2,
getPosition().x + mBoxWidth / 2, getPosition().y + mBoxWidth / 2, getPosition().z + mBoxHeight / 2);It should now look like this:
camDir.normalize();
F32 fovDot = camObj->getCameraFov() / 180;
Raindrop* curr = mDropHead;
//make a box
// Box3F box(camPos.x - mBoxWidth / 2, camPos.y - mBoxWidth / 2, camPos.z - mBoxHeight / 2,
// camPos.x + mBoxWidth / 2, camPos.y + mBoxWidth / 2, camPos.z + mBoxHeight / 2);
//offset the renderbox in the direction of the camera direction
//in order to have more of the drops actually rendered
// box.min.x += camDir.x * mBoxWidth / 4;
// box.max.x += camDir.x * mBoxWidth / 4;
// box.min.y += camDir.y * mBoxWidth / 4;
// box.max.y += camDir.y * mBoxWidth / 4;
// box.min.z += camDir.z * mBoxHeight / 4;
// box.max.z += camDir.z * mBoxHeight / 4;
Box3F box(getPosition().x - mBoxWidth / 2, getPosition().y - mBoxWidth / 2, getPosition().z - mBoxHeight / 2,
getPosition().x + mBoxWidth / 2, getPosition().y + mBoxWidth / 2, getPosition().z + mBoxHeight / 2);
VectorF windVel = getWindVelocity();
while (curr)save it. compile it. Run it.
ok... Now place a precipitation object...
F11 -> F4 ... mission -> environment -> precipitation ... name it rain so it's easy to find.
ok. Now find the rain object and move it where you want it. If you can't see any rain it is probably too low.
apply any changes. Save. Hit F11 again.
Now run around. you should be able to run in and out of the raining area...
About the author
I have been a professional game programmer for over 5 years now. I've worked on virtually every platform, dozens of games and released a few of my own games, including 2 iPhone titles and a title waiting release on Big Fish Games.
#2
B--
06/29/2005 (10:53 pm)
It might even be more efficient to setup area effect trigger nodes that "turn on" the precipitation around the player when they enter the area, and off when they leave it.B--
#3
It's weird becauseI tested it and it worked... Don't know why it stopped.
06/30/2005 (3:46 am)
Yes, it would. I have also noticed another issue. When you restart the mission, the precipitation blocks don't show up until you move the positoin. I haven't gotten around to fixing it but I will this weekend. It's weird becauseI tested it and it worked... Don't know why it stopped.
#4
08/04/2005 (2:21 am)
#5
If youd like to go that route this is what I did.
Created a bunch of triggers and put the following in them:
$precip.delete();
$precip = new Precipitation(){...};
That causes any precipitation you already created to stop and the new one to take its place.
I will try and find time tonight to fix the issue.
08/04/2005 (3:36 am)
JM - Sorry man, I forgot about this entirely. I stopped using hte localized precip blocks. instead I decided to go for using triggers to start and stop precipitation...If youd like to go that route this is what I did.
Created a bunch of triggers and put the following in them:
$precip.delete();
$precip = new Precipitation(){...};
That causes any precipitation you already created to stop and the new one to take its place.
I will try and find time tonight to fix the issue.
#6
08/04/2005 (4:10 am)
#7
I think the precipitation object is better to limit the rain to an area. I hope you fix it. I'll try too, but I'm a designer, not a programmer... My skills to help you with this are so limited...
Thanks for the resource.
05/19/2006 (5:58 am)
Triggers works fine, but it's weird to see the particles disappear/appear at the moment you enter in a trigger.I think the precipitation object is better to limit the rain to an area. I hope you fix it. I'll try too, but I'm a designer, not a programmer... My skills to help you with this are so limited...
Thanks for the resource.
#8
08/20/2006 (11:55 pm)
Is it possible that this script works on water surface too?
#9
I have implemented this and cannot get it to work properly. I have my game setup so that people warp to a certain location where I would like to have the precipitation working only in that area. It works to the point where it creates the precipitation object but it will not work until I go into the editor mode and slightly move it, then it works. So with that theory I tried creating it and then changing it's position after, that didnt' work. I then attempted something like this. %this.setScale(%this.getScale) that didn't work either. Nothing seems to get the precipitation object started without going into editor mode.
Does anyone know a fix to this? BTW, this is a multiplayer game so I can't just turn precipitation on/off via triggers, this affects all clients.
Or better yet, I would rather know how to only render precipitation to a specific client and not all clients.
Any answers would be hugely appreciated.
Thx.
DALO
09/07/2007 (2:30 pm)
Hello,I have implemented this and cannot get it to work properly. I have my game setup so that people warp to a certain location where I would like to have the precipitation working only in that area. It works to the point where it creates the precipitation object but it will not work until I go into the editor mode and slightly move it, then it works. So with that theory I tried creating it and then changing it's position after, that didnt' work. I then attempted something like this. %this.setScale(%this.getScale) that didn't work either. Nothing seems to get the precipitation object started without going into editor mode.
Does anyone know a fix to this? BTW, this is a multiplayer game so I can't just turn precipitation on/off via triggers, this affects all clients.
Or better yet, I would rather know how to only render precipitation to a specific client and not all clients.
Any answers would be hugely appreciated.
Thx.
DALO
#10
12/17/2007 (1:34 pm)
I experience exactly the same problem, and would also greatly appreciate any answers.
#11
Moving the precipitation box in the world editor (with the mouse, not by typing in coordinates) makes getPosition() return the correct values. What I still don't get is why this happens.
04/03/2008 (9:29 am)
Ok, so apparently all those getPosition() calls return 0, which means the precipitation is rendered in a box at 0,0,0 instead of at the position value of the precipitation object. I tried some things, like using setPosition just before the creation of the box. That changed the position successfully but it was reset with each new tick...Moving the precipitation box in the world editor (with the mouse, not by typing in coordinates) makes getPosition() return the correct values. What I still don't get is why this happens.
#12
Precipitation::inspectPostApply() should be updated to look something like this:
Then add a setTransform function to allow updating the rain block position from the console or in some engine function:
Of course, this needs a declaration in precipitation.h:
In Precipitation::onAdd(), replace
with
Add a line to Precipitation::packUpdate() to send along the transform when DataMask is set:
And in Precipitation::unpackUpdate(), we retrieve it and set the transform:
Together with the code in the original post, this should give you proper rain areas in TGE that start the rain at the transform of the Precipitaiton object when is created, and allow you to move it around outside the world editor. :)
04/21/2008 (1:02 pm)
Ok, figured it out. Here's the fix:Precipitation::inspectPostApply() should be updated to look something like this:
void Precipitation::inspectPostApply()
{
if (isClientObject())
fillDropList();
mObjBox.min = -Point3F(mBoxWidth/2, mBoxWidth/2, mBoxHeight/2);
mObjBox.max = Point3F(mBoxWidth/2, mBoxWidth/2, mBoxHeight/2);
resetWorldBox();
setMaskBits(DataMask);
}Then add a setTransform function to allow updating the rain block position from the console or in some engine function:
void Precipitation::setTransform(const MatrixF & mat)
{
Parent::setTransform(mat);
setMaskBits(DataMask);
}Of course, this needs a declaration in precipitation.h:
void setTransform(const MatrixF &mat);
In Precipitation::onAdd(), replace
mObjBox.min.set(-1e6, -1e6, -1e6); mObjBox.max.set( 1e6, 1e6, 1e6);
with
mObjBox.min = -Point3F(mBoxWidth/2, mBoxWidth/2, mBoxHeight/2); mObjBox.max = Point3F(mBoxWidth/2, mBoxWidth/2, mBoxHeight/2);
Add a line to Precipitation::packUpdate() to send along the transform when DataMask is set:
if (stream->writeFlag(mask & DataMask))
{
stream->writeAffineTransform(mObjToWorld);
.
.
.And in Precipitation::unpackUpdate(), we retrieve it and set the transform:
if (stream->readFlag())
{
MatrixF mat;
stream->readAffineTransform(&mat);
Parent::setTransform(mat);
.
.
.Together with the code in the original post, this should give you proper rain areas in TGE that start the rain at the transform of the Precipitaiton object when is created, and allow you to move it around outside the world editor. :)
Torque Owner Chris Labombard
Premium Preferred