Index: trunk/MagicSoft/Cosy/catalog/SlaPlanets.cc
===================================================================
--- trunk/MagicSoft/Cosy/catalog/SlaPlanets.cc	(revision 9435)
+++ trunk/MagicSoft/Cosy/catalog/SlaPlanets.cc	(revision 9439)
@@ -40,5 +40,5 @@
     double ra, dec, diam;
 
-    // One can use TT instead of TDB for all plenets
+    // One can use TT instead of TDB for all planets
     // (except the moon)
     // TDB, planet, elong, phi, *ra, *dec, *diam
Index: trunk/MagicSoft/Cosy/catalog/SlaStars.cc
===================================================================
--- trunk/MagicSoft/Cosy/catalog/SlaStars.cc	(revision 9435)
+++ trunk/MagicSoft/Cosy/catalog/SlaStars.cc	(revision 9439)
@@ -49,5 +49,5 @@
              0, 0,                         // polar motion x, y-coordinate (radians)
              // 273.155, 1013.25, 0.5,     // temp, pressure, humidity
-             273.155+20, 1013.25, 0.5,     // temp, pressure, humidity
+             273.155+10, 780.0, 0.25,     // temp, pressure, humidity
              // 0.2, 0.0065,               // wavelength, tropo lapse rate
              0.55, 0.0065,                 // wavelength, tropo lapse rate
Index: trunk/MagicSoft/Cosy/catalog/Slalib.cc
===================================================================
--- trunk/MagicSoft/Cosy/catalog/Slalib.cc	(revision 9435)
+++ trunk/MagicSoft/Cosy/catalog/Slalib.cc	(revision 9439)
@@ -18,12 +18,6 @@
 Double_t Slalib::Trunc(Double_t val)
 {
-    /* dint(A) - truncate to nearest whole number towards zero (double) */
+    // dint(A) - truncate to nearest whole number towards zero (double)
     return val<0 ? TMath::Ceil(val) : TMath::Floor(val);
-}
-
-Double_t Slalib::Round(Double_t val)
-{
-    /* dnint(A) - round to nearest whole number (double) */
-    return val<0 ? TMath::Ceil(val-0.5) : TMath::Floor(val+0.5);
 }
 
@@ -40,5 +34,4 @@
     SetMjd(fTime.GetMjd()+offset/(24*60*60));
 }
-
 
 ZdAz Slalib::XYZ2ZdAz(double coord[3]) const
Index: trunk/MagicSoft/Cosy/catalog/Slalib.h
===================================================================
--- trunk/MagicSoft/Cosy/catalog/Slalib.h	(revision 9435)
+++ trunk/MagicSoft/Cosy/catalog/Slalib.h	(revision 9439)
@@ -19,5 +19,4 @@
     double fAlpha;
 
-    static Double_t Round(Double_t val);
     static Double_t Trunc(Double_t val);
 
Index: trunk/MagicSoft/Cosy/catalog/StarCatalog.cc
===================================================================
--- trunk/MagicSoft/Cosy/catalog/StarCatalog.cc	(revision 9435)
+++ trunk/MagicSoft/Cosy/catalog/StarCatalog.cc	(revision 9439)
@@ -17,5 +17,5 @@
 using namespace std;
 
-StarCatalog::StarCatalog(MObservatory::LocationName_t key) : SlaStars(key), fW(768), fH(576), fAstro(0), /*fSao(NULL), fSrt(NULL), fEntries(0),*/ fSinAngle(0), fCosAngle(1), fBox(768)
+StarCatalog::StarCatalog(MObservatory::LocationName_t key) : SlaStars(key), fW(768), fH(576), fAstro(0), /*fSao(NULL), fSrt(NULL), fEntries(0),*/ fSinAngle(0), fCosAngle(1), fBoxX(768), fBoxY(576)
 {
     fAstro = new MAstroCatalog;
@@ -32,11 +32,12 @@
 {
     // pixsize [arcsec/pixel]
-    fPixSize = D2PI/360.0*pixsize/3600; // [rad / (deg*pixel)]
+    fPixSize = TMath::DegToRad()*pixsize/3600; // [rad / (deg*pixel)]
     fAstro->SetRadiusFOV(pixsize, 768, 576);
+    // fov = hypot(768, 576)/2*pixsize/3600;
 }
 
 double StarCatalog::GetPixSize() const
 {
-    return fPixSize*3600*360.0/D2PI;
+    return fPixSize*3600*TMath::RadToDeg();
 }
 
@@ -55,5 +56,5 @@
 void StarCatalog::SetAltAz(const AltAz &altaz)
 {
-    fAltAz = altaz * D2PI/360.0;
+    fAltAz = altaz * TMath::DegToRad();
     fRaDec = CalcRaDec(fAltAz);
 
@@ -72,5 +73,5 @@
 void StarCatalog::SetRaDec(const RaDec &radec)
 {
-    const RaDec rd = fRaDec*360.0/D2PI;;
+    const RaDec rd = fRaDec*TMath::RadToDeg();
 
     const Bool_t same =
@@ -78,5 +79,5 @@
         rd.Dec()>radec.Dec()-1e-5 && rd.Dec()<radec.Dec()+1e-5;
 
-    fRaDec = radec * D2PI/360.0;
+    fRaDec = radec * TMath::DegToRad();
     fAltAz = CalcAltAz(fRaDec);
 
@@ -153,26 +154,30 @@
 
 void StarCatalog::CalcStars(MStarList &list, int xc, int yc, 
-			    int xo, int yo) const
-{
-    // For an apropriate unit conversion to pixels [pix/rad]
-    const Double_t scale = TMath::RadToDeg()*TMath::Sqrt(768*768 + 576*576)/(fAstro->GetRadiusFOV()*2);
-
-    // Offsets to shift [-n/2;n/2] to [0;n] and to
-    // move the stars in the counterdirection of the LEDs
-    const Int_t offx = 768/2 + xo;
-    const Int_t offy = 576/2 + yo;
+			    float offx, float offy) const
+{
+//    const Int_t offx = 768/2 + xo;
+//    const Int_t offy = 576/2 + yo;
 
     // Allow catalog stars to be a bit outside [0.2deg] of the
     // monitored window. To get the std behaviour set offset=0
-    const Int_t offset = TMath::Nint(0.2*TMath::DegToRad()*scale);
-    const Int_t box    = fBox+offset;
+    const Int_t offset = TMath::Nint(0.2*TMath::DegToRad()/fPixSize);
+    const Int_t boxx   = fBoxX+offset;
+    const Int_t boxy   = fBoxY+offset;
 
     // CalcStars flips the picture in X defaultwise now
     // This defined the box in which stars are really returned
+    const int x0 = TMath::Max((768-xc)-boxx,   -offset);
+    const int y0 = TMath::Max(yc-boxy,         -offset);
+    const int x1 = TMath::Min((768-xc)+boxx, fW+offset);
+    const int y1 = TMath::Min(yc+boxy,       fH+offset);
+/*
     const int x0 = TMath::Max((768-xc)-box,   -offset);
-    const int y0 = TMath::Max(yc-box,         -offset);
     const int x1 = TMath::Min((768-xc)+box, fW+offset);
-    const int y1 = TMath::Min(yc+box,       fH+offset);
-
+
+    const int y0 = TMath::Max(yc-box-100,         -offset);
+    const int y1 = TMath::Min(yc+box+100,       fH+offset);
+ */
+
+/*
     // Align stars into telescope system
     // (Move the telescope to pointing position)
@@ -181,4 +186,8 @@
     align.RotateY(-(TMath::Pi()/2-fAltAz.Alt()));
     align.RotateZ(TMath::Pi()/2);
+ */
+
+    TRotation rot;
+    rot.RotateY(-(TMath::Pi()/2-fAltAz.Alt()));
 
     // Get List of stars from catalog
@@ -200,4 +209,24 @@
         const ZdAz  za(CalcZdAz(rd));
 
+        TVector3 v;
+        //v.SetMagThetaPhi(1., TMath::Pi()/2-za.Alt(), za.Az()-fAltAz.Az());
+        v.SetMagThetaPhi(1., za.Zd(), za.Az()-fAltAz.Az());
+        v *= rot;
+
+        if (v(2)<0)
+            continue;
+
+        // Stretch such, that the Z-component is alwas the same. Now
+        // X and Y contains the intersection point between the star-light
+        // and the plain of a virtual plain screen (ccd...)
+        v *= 1./v(2);
+
+        // Do unit conversion to pixels
+        v *= 1./fPixSize;
+
+        const Double_t x = -v.Y();
+        const Double_t y =  v.X();
+
+/*
         // Virtually move telescope to pointing position
         TVector3 loc;
@@ -215,13 +244,17 @@
 
         // Do an apropriate unit conversion to pixels
-        loc *= scale;
-
+        loc *= 1./fPixSize;
+
+        const Double_t x = loc.X();
+        const Double_t y = loc.Y();
+*/
         // if (loc.Mod2()>fRadiusFOV*fRadiusFOV)
         //     continue;
 
+
         // Rotate by the rotation angle of the video camera
         // and add the offsets on both axis
-        Float_t xx = loc.X()*fCosAngle - loc.Y()*fSinAngle  +  offx;
-        Float_t yy = loc.X()*fSinAngle + loc.Y()*fCosAngle  +  offy;
+        const Double_t xx = x*fCosAngle - y*fSinAngle + 768 - offx;
+        const Double_t yy = x*fSinAngle + y*fCosAngle + offy;
 
         // Check if the resulting star is in the
@@ -235,4 +268,5 @@
 }
 
+/*
 AltAz StarCatalog::CalcAltAzFromPix(Double_t pixx, Double_t pixy) const
 {
@@ -251,2 +285,38 @@
     return AltAz(-dec, ha+fAltAz.Az());
 }
+*/
+
+ZdAz StarCatalog::CalcDeltaZdAzFromPix(Double_t dpixx, Double_t dpixy) const
+{
+    double dx =  dpixx*fCosAngle + dpixy*fSinAngle;
+    double dy = -dpixx*fSinAngle + dpixy*fCosAngle;
+
+    TVector3 loc(dy, -dx, 1./fPixSize);
+
+    loc.RotateY(TMath::Pi()/2-fAltAz.Alt());
+
+    return ZdAz(loc.Theta()-TMath::Pi()/2+fAltAz.Alt(), -loc.Phi());
+
+    /*
+    // Align stars into telescope system
+    // (Move the telescope to pointing position)
+    TRotation align;
+    align.RotateZ(-fAltAz.Az());
+    align.RotateY(-(TMath::Pi()/2-fAltAz.Alt()));
+    align.RotateZ(TMath::Pi()/2);
+
+
+    TVector3 loc(dx, dy, 1./fPixSize);
+
+    loc *= align.Inverse();
+
+    cout << (TMath::Pi()/2-loc.Theta()-alt)*TMath::RadToDeg() << " " << (loc.Phi()-az)*TMath::RadToDeg() << endl;
+
+
+
+    TVector3 loc(dx, -dy, 1./fPixSize);
+
+    loc *= align.Inverse();
+
+    return ZdAz(loc.Theta(), loc.Phi());*/
+}
Index: trunk/MagicSoft/Cosy/catalog/StarCatalog.h
===================================================================
--- trunk/MagicSoft/Cosy/catalog/StarCatalog.h	(revision 9435)
+++ trunk/MagicSoft/Cosy/catalog/StarCatalog.h	(revision 9439)
@@ -41,11 +41,13 @@
 
     void   SetRaDec(const RaDec &radec);
-    void   SetAltAz(const AltAz &altaz);
 
-    int    fBox;
+    int    fBoxX;
+    int    fBoxY;
 
 public:
     StarCatalog(MObservatory::LocationName_t key);
     virtual ~StarCatalog();
+
+    void   SetAltAz(const AltAz &altaz);
 
     void GetImg(byte *img, byte *cimg, MStarList &list) const;
@@ -65,5 +67,6 @@
     double GetPixSize() const;
 
-    AltAz CalcAltAzFromPix(Double_t pixx, Double_t pixy) const;
+    //AltAz CalcAltAzFromPix(Double_t pixx, Double_t pixy) const;
+    ZdAz  CalcDeltaZdAzFromPix(Double_t pixx, Double_t pixy) const;
 
     virtual void SetMjd(double mjd);
@@ -75,8 +78,9 @@
 
     //void   CalcStars(MStarList &list);
-    void   CalcStars(MStarList &list, int xc, int yc, int xo, int yo) const;
+    void   CalcStars(MStarList &list, int xc, int yc, float xo, float yo) const;
     static void DrawStars(MStarList &list, byte *img);
 
-    void SetBox(int box)   { fBox = box; }
+    void SetBox(int box)   { fBoxX = fBoxY = box; }
+    void SetBox(int boxx, int boxy)   { fBoxX = boxx; fBoxY=boxy; }
 
     ClassDef(StarCatalog, 0)
