Author Topic: Main Coloring Based On Distance  (Read 356 times)

Denes

  • Traveller
  • *
  • Posts: 32
    • View Profile
Main Coloring Based On Distance
« on: March 04, 2013, 07:20:09 am »
Well… I understand this isn’t a new idea and neither considered a useful one. But. I for one find difficult to read “between the lines” (on rare occasions when more than one interaction takes place close by) and thought of giving it a shot:
Code: [Select]
--- D:/development/ps_prist_20130208/src/client/gui/chatwindow.h Fri Feb 08 08:32:33 2013
+++ C:/development/PlaneShift/src/client/gui/chatwindow.h Mon Mar 04 12:30:22 2013
@@ -207,6 +207,10 @@
     /// mixes two colours and returns their mixed colour
     int mixColours(int colour1, int colour2);
 
+    /// mixes two colours and returns their mixed colour dased on distance [0..160]
+ int mixColoursWithDistance(int colour1, int colour2, float distFromMe);
+ static const int distantColour=4210752; //graphics2D->FindRGB(64,64,64); //grey TODO: Hardcoded. Needs config attribute
+
     /// Leaves the channel and removes the hotkey association
     bool LeaveChannel(int hotkeyChannel);
 
--- D:/development/ps_prist_20130208/src/client/gui/chatwindow.cpp Fri Feb 08 08:32:33 2013
+++ C:/development/PlaneShift/src/client/gui/chatwindow.cpp Mon Mar 04 12:32:51 2013
@@ -41,6 +41,8 @@
 #include <iutil/stringarray.h>
 #include <iutil/plugin.h>
 
+#include <csgeom/math3d.h>
+
 //=============================================================================
 // Project Includes
 //=============================================================================
@@ -1651,7 +1653,17 @@
         case CHAT_SAY:
         {
             FormatMessage(msg.sText,msg.sPerson, "says", buff, hasCharName);
-            colour = settings.chatColor;
+
+ csVector3 myPos = psengine->GetCelClient()->GetMainPlayer()->GetPosition();
+ GEMClientActor* actor = dynamic_cast<GEMClientActor*> (psengine->GetCelClient()->GetActorByName(msg.sPerson));
+ float distFromMe=0;
+ if (actor)
+ {
+ csVector3 pos = actor->GetPosition();
+ distFromMe = csSquaredDist::PointPoint(myPos, pos);
+ }
+ colour= mixColoursWithDistance(settings.chatColor,distantColour,distFromMe);
+            //colour = settings.chatColor;
             break;
         }
 
@@ -2626,6 +2638,19 @@
     graphics2D->GetRGB(colour1,r,g,b); //gets the rgb values of the first colour
     graphics2D->GetRGB(colour2,r2,g2,b2); //gets the rgb values of the second colour
     return graphics2D->FindRGB((r+r2)/2,(g+g2)/2,(b+b2)/2); //does the average of the two colours and returns it back
+}
+
+int pawsChatWindow::mixColoursWithDistance(int colour1, int colour2, float distFromMe)
+{
+    int r,g,b;
+    int r2,g2,b2;
+ int n=int(distFromMe);
+ if (n<0) {n=0;}
+ if (n>160) {n=160;} //0..160 is the distance we work with. TODO: either divide by 16 or 32 to save CPU, or make resolution configurable
+ int o=160-n;
+    graphics2D->GetRGB(colour1,r,g,b); //gets the rgb values of the first colour
+    graphics2D->GetRGB(colour2,r2,g2,b2); //gets the rgb values of the second colour
+    return graphics2D->FindRGB((o*r+n*r2)/160,(o*g+n*g2)/160,(o*b+n*b2)/160); //does the average of the two colours and returns it back
 }
 
 //------------------------------------------------------------------------------

This one is rather crude. I’d be happy to enhance it, if I learnt someone else using it too.
Screenshot from an irrelevant event, but you get the idea  :) :
« Last Edit: March 04, 2013, 07:26:26 am by Denes »

LigH

  • Forum Legend
  • *
  • Posts: 7096
    • View Profile
Re: Main Coloring Based On Distance
« Reply #1 on: March 04, 2013, 07:43:52 am »
Loudness represented by brightness? ... :D Crazy idea ... but someone might like it.

Gag Harmond
Knight and Ambassador
The Royal House of Purrty

Bonifarzia

  • Hydlaa Notable
  • *
  • Posts: 718
    • View Profile
Re: Main Coloring Based On Distance
« Reply #2 on: March 04, 2013, 07:45:14 am »

The way you implemented this does not look useless at all.

I think this related topic, in particular this post may be interesting for you.

MishkaL1138

  • Veteran
  • *
  • Posts: 1175
  • Meh.
    • View Profile
Re: Main Coloring Based On Distance
« Reply #3 on: March 04, 2013, 10:24:20 am »
I like it and wonder why hasn't this been implemented into the actual game already.

EDIT: How am I supposed to install it if I ever go back to the game?
« Last Edit: March 04, 2013, 02:34:32 pm by MishkaL1138 »

"It's all fun and games until someone stabs someone else in the eye."

BoevenF

  • Hydlaa Notable
  • *
  • Posts: 543
  • Amdeneir citizen, mostly travelling
    • View Profile
    • The Doømed Ones SVG
Re: Main Coloring Based On Distance
« Reply #4 on: March 04, 2013, 03:35:39 pm »
Genius. I want it.

mistnmc

  • Traveller
  • *
  • Posts: 16
    • View Profile
Re: Main Coloring Based On Distance
« Reply #5 on: March 05, 2013, 04:39:47 pm »
Me too, love the idea. It would also enhance RP experience, in my opinion.

Denes

  • Traveller
  • *
  • Posts: 32
    • View Profile
Re: Main Coloring Based On Distance
« Reply #6 on: March 08, 2013, 07:31:23 am »
Since this has got a fair amount of positive feedbacks, I decided to try and help the best I know how to get it to a wider public. (Your only way to have this is to compile it or get it to official release as far as I know) But I’m going to need your help with that.
   So I assume, to give it the best chances from the start we need: well thought-out concept (down to details), specifics and community support. From a workflow point: 1) gathering inputs here and IG; 2) Implement as good as I can; 3) Link this thread with a flyspray feature request + sit back and wait patiently for the devs to revise/rework/scrap/implement it. (Or I might just delegate this to someone who wants it ASAP and would keep nagging the devs about it.  )
   There are three pillars I can think of that could get main closer to RL hearing.
-   Damping with squared distance
(The first post. This is in line with physics.)
-   Amplify voices based on facing
Code: [Select]
actor->GetLastPosition(pos,yrot,sector);
me->GetLastPosition(myPos,myYrot,mySector);
csVector3 diff=pos-myPos;
float r=(atan2(-diff.x,-diff.z))-myYrot; //-x -z for opposite (facing)
r=(r>PI) ? TWO_PI-r : r;
r=(r<-PI) ? TWO_PI+r : r;
r=abs(r);
This results in a coefficient ranging from 0 (you are facing the source) to PI (source is behind you). It is 2d deliberately since I assume players use third person view the most, but this can be argued with. It is also possible to use this the other way around too (someone talking with their backs facing you) so to try to simulate something more complex than a point source of waves.
-   Clear line of sight
Code: [Select]
csVector3 isect,start,end,norm;
csRef<iCollideSystem> cdsys =  csQueryRegistry<iCollideSystem> (psengine->GetObjectRegistry ());
start= myPos+ csVector3(0, 1.8f, 0);//1,8.. I'm sorry dwarven friends... Is there a way to tell character height?
end = pos+ csVector3(0, 1.8f, 0);
norm=end-start;norm.Normalize();
csIntersectingTriangle closest_tri;
iMeshWrapper* sel;
float dist,maxRad=0;
do
{
sel = 0;
dist = csColliderHelper::TraceBeam (cdsys, sector,start, end, false, closest_tri, isect, &sel);
if (sel && dist>0)
{
csSphere cssph=sel->GetRadius();
if (cssph.GetRadius()>=maxRad)
{
maxRad=cssph.GetRadius();
}
float lastStep=(isect-start).Norm();
if (lastStep<0,1) //Sometimes TraceBeam gets stuck in objects (almost endless loop) so needs a kick
{
start+=norm;
}
else
{
start=csVector3(isect);
}
}
} while (dist>0);
if (maxRad>4.25f)
{
//different floor – other side
}
In this maxRad(ius) returns with the size of the biggest object blocking. Some sizes from next to KadaEl’s:  chimney 0,18; jug 0,18; chair 0,6; large barrel; table 0,83; bar 3,08; bench 3,62, forge 4,25, a piece of wall 4,5, a piece of ceiling 4,53-5,42, floor 8; roof 10,82; guard tower 12,51
Might not be fully accurate at all times, but tests shows it is doable. There also is the possibility to redo calculations from a slightly different point of view too (something like start+=csVector3(0.3, 0, 0.3)). My aim here would be to being able to tell if the source is on another floor in KadaEl’s or it is originating from behind a whole smithy.

What I want you to do is: form an opinion and share it with me here or IG. Could be about anything like: which can be useful at all, how many colors should we use, what their default values should be, how and in what order to use the numbers from the functions above. And any insights are welcome too like: why not just leave it alone? PS is slow enough already, your code has errors here and here, that can be solved easily like this, uses cases where it should be tested first, hints on how RL biology/physics work, etc.

PS: I did the mods in cmdusers.cpp to test with additional includes as follows:
Code: [Select]
#include <csgeom/math3d.h>
#include "meshattach.h"
#include "csgeom/sphere.h"