⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 plot2d.c

📁 The OpenGPSRec receiver software runs on the real time operating system RTAI-Linux. It compiles with
💻 C
字号:
/* ************************************************************************    *                                                                      *   *                            OpenGPS Receiver                          *   *                                                                      *   * -------------------------------------------------------------------- *   *                                                                      *   *    Module:   plot2d.c                                                *   *                                                                      *   *   Version:   0.1                                                     *   *                                                                      *   *      Date:   09.12.03                                                *   *                                                                      *   *    Author:   S. Esterhuizen, G. Beyerle                              *   *                                                                      *   * -------------------------------------------------------------------- *   *                                                                      *   * Copyright (C) 2003  S. Esterhuizen, G. Beyerle                       *   *                                                                      *   * This program is free software; you can redistribute it and/or modify *   * it under the terms of the GNU General Public License as published by *   * the Free Software Foundation; either version 2 of the License, or    *   * (at your option) any later version.                                  *   *                                                                      *   * This program is distributed in the hope that it will be useful,      *   * but WITHOUT ANY WARRANTY; without even the implied warranty of       *   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        *   * GNU General Public License for more details.                         *   *                                                                      *   * You should have received a copy of the GNU General Public License    *   * along with this program; if not, write to the Free Software          *   * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.            *   *                                                                      *   * -------------------------------------------------------------------- *   *                                                                      *   *                         xy-plotting routine                          *   *                                                                      *   ************************************************************************ *//* ******************************* changes ********************************   09.12.03 - adapted to OpenGPSRec   ************************************************************************ *//* ----------------------------- includes --------------------------------- */#include <stdio.h>#include <stdlib.h>#include <math.h>#include <string.h>#include <GL/gl.h>      // Header File For The OpenGL32 Library#include <GL/glu.h>     // Header File For The GLu32 Library#include <GL/glut.h>    // Header File For The GLUT Library #include "../include/port.h"#include "../include/ogr_defines.h"#include "../include/ogr_structs.h"#include "defines.h"#include "globals.h"#include "opengl_functions.h"#include "plot2d.h"/* ------------------------------ defines --------------------------------- */#define MAX_2D_BUF 10000#define  Y_MAX_WIND  3.5#define  Y_MIN_WIND -3.5#define  X_MAX_WIND  3.5#define  X_MIN_WIND -3.5/* ------------------------------ globals --------------------------------- */static float maxYVal = 0.0,             minYVal = 0.0,             maxXVal = 0.0,             minXVal = 0.0,             xShift = 0.0,             xScale = 0.0,             yShift = 0.0,             yScale = 0.0;static int   NumPoints = 0,             Head2d = -1;static PLOT2D Buf2d[MAX_2D_BUF];//------------------------------------------------------------------------------//  Plot2dAdd() //  // Adds a PLOT2D struct to the Buf2d buffer//void Plot2dAdd( PLOT2D point) {  if ( NumPoints == 0)  {    maxXVal   = point.x;    minXVal   = point.x;    maxYVal   = point.y;    minYVal   = point.y;  }  NumPoints++;  Head2d = (Head2d + 1) % MAX_2D_BUF; // boundary check  /* Sanity checks */  if ((Head2d < 0) || (Head2d >= MAX_2D_BUF))   {    printf( "gpsplot: error ADD, Head2d [%d] out of bounds\n",Head2d);    return;  }  if ( point.y > maxYVal)      maxYVal   = point.y;  if ( point.y < minYVal)      minYVal   = point.y;  if ( point.x > maxXVal)      maxXVal   = point.x;  if ( point.x < minXVal)      minXVal   = point.x;  Buf2d[Head2d] = point; // copy data into ring buf  return;}//------------------------------------------------------------------------------//  Plot2dGet() //  // Gets the POLAR struct at index of polarBuf buffer//PLOT2D* Plot2dGet(int index) {  // do a few sanity checks  if ((Head2d < 0) || (Head2d >= MAX_2D_BUF))   {    printf( "gpsplot: error GET, Head2d [%d] out of bounds\n", Head2d);    exit( 0);  }  if ((index < 0) || (index >= MAX_2D_BUF))   {    printf( "gpsplot: error GET, Head2d index [%d] out of bounds\n", index);    exit( 0);  }/*  * Calculate correct index (ring buffer * wraps at 0 and RING_BUF_SIZE */  if (( Head2d-index) < 0)     index = MAX_2D_BUF + (Head2d-index);  else     index = Head2d-index;  return &Buf2d[index];}/*  * determine transformation parameters  * from data to to window coordinate system */static void CalcScaleAndShift( int unitaspect){  xShift = (maxXVal + minXVal) / 2.0;  xScale = (maxXVal - minXVal) / (X_MAX_WIND - X_MIN_WIND);    if ( xScale <= 0.0)    xScale = 1.0;  yShift = (maxYVal + minYVal) / 2.0;  yScale = (maxYVal - minYVal) / (Y_MAX_WIND - Y_MIN_WIND);    if ( yScale <= 0.0)    yScale = 1.0;  if ( unitaspect)  {    yScale = max( yScale, xScale);    xScale = yScale;  }  return;}/* * transformation from data to to window coordinate system */static inline float True2WindowCoordX( float x){  return (x - xShift) / xScale;}static inline float True2WindowCoordY( float y){  return (y - yShift) / yScale;}//------------------------------------------------------------------------------//  Plot2dDraw() //  // Draws the polar plot on the OpenGL screen//void Plot2dDraw( PLOTOPT PlotOpt) {  PLOT2D *p;  int i;  char text[64];  CalcScaleAndShift( PlotOpt.unitaspect);/* Draw Axis only if data range includes zero */  glBegin( GL_LINE_STRIP);  if ( minXVal < 0 && maxXVal > 0)  {    glColor3f( 1.0f, 1.0f, 1.0f);    glVertex3f( True2WindowCoordX( 0.0f), True2WindowCoordY( minYVal), 0.0f); // y-axis    glVertex3f( True2WindowCoordX( 0.0f), True2WindowCoordY( maxYVal), 0.0f); // y-axis  }    glEnd();  glBegin( GL_LINE_STRIP);  if ( minYVal < 0 && maxYVal > 0)  {    glColor3f( 1.0f, 1.0f, 1.0f);    glVertex3f( True2WindowCoordX( minXVal), True2WindowCoordY( 0.0f), 0.0f); // x-axis    glVertex3f( True2WindowCoordX( maxXVal), True2WindowCoordY( 0.0f), 0.0f); // x-axis  }  glEnd();  sprintf( text, "Channel %d, plot [%s]", ch, plotDataListRaw);  DrawText12( W/2-5*(strlen(text)/2), H-15, text, 1.0f, 1.0f, 1.0f);//  sprintf( text, "Buf pos [%d]",-yNewHead);//  DrawText12( 5*(strlen(text)/2), H-15, text, 0.0f, 0.0f, 1.0f);  /* y-axis min/max labels */  sprintf( text, "%0.1f", minYVal);  DrawTextScale( 0.0, True2WindowCoordY( minYVal), text, 1.0f, 1.0f, 1.0f);  sprintf( text, "%0.1f", maxYVal);  DrawTextScale( 0.0, True2WindowCoordY( maxYVal), text, 1.0f, 1.0f, 1.0f);  /* x-axis min/max labels */  sprintf( text, "%0.1f", minXVal);  DrawTextScale( True2WindowCoordX( minXVal), 0.0f, text, 1.0f, 1.0f, 1.0f);  sprintf( text, "%0.1f", maxXVal);  DrawTextScale( True2WindowCoordX( maxXVal), 0.0f, text, 1.0f, 1.0f, 1.0f);/* Draw points */  if ( PlotOpt.plotline)  {    glBegin(GL_LINE_STRIP);    for (i=0; i < NumPoints; i++)     {      /* get a point */      p = Plot2dGet(i);      /* Set the colour */      glColor3f( p->r, p->g, p->b);      /* Draw a line */      glVertex3f( True2WindowCoordX( p->x), True2WindowCoordY( p->y), 0.0f);    }    glEnd();  }  else  {    glBegin( GL_POINTS);    for (i=0; i < NumPoints; i++)     {      /* get a point */      p = Plot2dGet( i);      /* Set the colour */      glColor3f( p->r, p->g, p->b);      /* Draw a line */      glVertex3f( True2WindowCoordX( p->x), True2WindowCoordY( p->y), 0.0f);    }    glEnd();  }    /* If we are not in stop mode */  if ( !stop)     NumPoints = 0;  return;}/* -----------------------------End of File ------------------------------- */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -