Пример #1
0
        public void initGridPositions(List <MoleCell> cells, int holeRows, int holeColumns, int spacing)
        {
            // Store pointer to holes array (for drawing later)
            taskCells = cells;

            // Store hole parameters for drawing later
            this.holeRows    = holeRows;
            this.holeColumns = holeColumns;
            this.spacing     = spacing;

            // Calculate maximum possible size of holes
            holeOffsetX = 0; holeOffsetY = 0;
            if (getContentWidth() / holeColumns > getContentHeight() / holeRows)
            {
                holeSize = (int)Math.Floor((double)((getContentHeight() - (spacing * (holeRows + 1))) / holeRows));
            }
            else
            {
                holeSize = (int)Math.Floor((double)((getContentWidth() - (spacing * (holeColumns + 1))) / holeColumns));
            }

            // set the x and y offset
            holeOffsetX = (getContentWidth() - holeColumns * holeSize - spacing * (holeColumns + 1)) / 2;
            //holeOffsetY =  (getContentHeight() - holeRows * holeSize - spacing * (holeRows+1)) / 2;
            holeOffsetY = (int)Math.Ceiling(getContentHeight() / 4.0);

            // Loop through the holes
            for (int i = 0; i < cells.Count; i++)
            {
                // calculate the row and column index (0 based)
                int row    = (int)Math.Floor((double)(i / holeColumns));
                int column = i - (row * holeColumns);

                // retrieve the reference to the hole
                MoleCell cell = cells[i];

                // Set position and size
                cell.x = holeOffsetX + spacing + column * (holeSize + spacing);
                cell.y = holeOffsetY + spacing + row * (holeSize + spacing);

                cell.height = holeSize;
                cell.width  = holeSize;
            }

            // calculate the position of the escape cue
            escapeOffsetX = (getContentWidth() - holeSize) / 2;                             // horizontal center
            escapeOffsetY = (((getContentHeight() - holeOffsetY) / 2) - holeSize) / 2;      // vertical center between top of viewport and top of grid
        }
Пример #2
0
        protected override void render()
        {
            // check if fixation should be shown
            if (showFixation)
            {
                // set the fixation to white
                glColor3(1f, 1f, 1f);

                // set the text count
                int fixationTextWidth = fixationFont.getTextWidth("+");
                fixationFont.printLine((int)((getContentWidth() - fixationTextWidth) / 2), (int)((getContentHeight() - fixationFont.height) / 2), "+");
            }

            if (showCountDown >= 0)
            {
                // set the countdown to white
                glColor3(1f, 1f, 1f);

                // set the text count
                int countTextWidth = countdownFont.getTextWidth(showCountDown.ToString());
                countdownFont.printLine((int)((getContentWidth() - countTextWidth) / 2), (int)((getContentHeight() - countdownFont.height) / 2), showCountDown.ToString());
            }

            if (showEscape)
            {
                // set white color for drawing
                glColor3(1f, 1f, 1f);

                // set escape texture
                glBindTexture2D(escapeTexture);

                // draw texture
                glBeginTriangles();

                // vertex 0
                glTexCoord2(1.0f, 1.0f);
                glVertex3(escapeOffsetX + holeSize, escapeOffsetY + holeSize, 0.0f);

                glTexCoord2(1.0f, 0.0f);
                glVertex3(escapeOffsetX + holeSize, escapeOffsetY, 0.0f);

                glTexCoord2(0.0f, 0.0f);
                glVertex3(escapeOffsetX, escapeOffsetY, 0.0f);

                //vertex 1
                glTexCoord2(0.0f, 1.0f);
                glVertex3(escapeOffsetX, escapeOffsetY + holeSize, 0.0f);

                glTexCoord2(1.0f, 1.0f);
                glVertex3(escapeOffsetX + holeSize, escapeOffsetY + holeSize, 0.0f);

                glTexCoord2(0.0f, 0.0f);
                glVertex3(escapeOffsetX, escapeOffsetY, 0.0f);

                glEnd();
            }

            // Check if we should draw grid
            if (showGrid)
            {
                // loop through the holes
                for (int i = 0; i < taskCells.Count; i++)
                {
                    // retrieve hole reference
                    MoleCell cell = taskCells[i];

                    if (cell.type == MoleCell.CellType.Hole || cell.type == MoleCell.CellType.Mole || cell.type == MoleCell.CellType.Exit)
                    {
                        // set white color for drawing
                        glColor3(1f, 1f, 1f);

                        // set texture
                        if (cell.type == MoleCell.CellType.Hole)
                        {
                            glBindTexture2D(holeTexture);
                        }
                        else if (cell.type == MoleCell.CellType.Exit)
                        {
                            glBindTexture2D(exitTexture);
                        }
                        else
                        {
                            glBindTexture2D(moleTexture);
                        }

                        // draw hole
                        glBeginTriangles();

                        // vertex 0
                        glTexCoord2(1.0f, 1.0f);
                        glVertex3(cell.x + cell.width, cell.y + cell.height, 0.0f);

                        glTexCoord2(1.0f, 0.0f);
                        glVertex3(cell.x + cell.width, cell.y, 0.0f);

                        glTexCoord2(0.0f, 0.0f);
                        glVertex3(cell.x, cell.y, 0.0f);

                        //vertex 1
                        glTexCoord2(0.0f, 1.0f);
                        glVertex3(cell.x, cell.y + cell.height, 0.0f);

                        glTexCoord2(1.0f, 1.0f);
                        glVertex3(cell.x + cell.width, cell.y + cell.height, 0.0f);

                        glTexCoord2(0.0f, 0.0f);
                        glVertex3(cell.x, cell.y, 0.0f);

                        glEnd();
                    }
                }

                // check if the selection should be drawn
                if (selectionWidth != 0 && selectionHeight != 0)
                {
                    // set the color
                    float colorR = 1, colorG = 1, colorB = 0;
                    if (selected)
                    {
                        colorG = 0;
                    }

                    // draw selection
                    drawRectangle(selectionX,
                                  selectionY,
                                  (selectionX + selectionWidth),
                                  (selectionY + selectionHeight),
                                  5,
                                  colorR, colorG, colorB);
                }
            }

            if (showScore)
            {
                // print score (accuracy) and escpae score if required
                glColor3(1f, 1f, 1f);
                scoreFont.printLine(getContentWidth() - scoreFont.height * 10, 5, ("Score: " + score + "%"));
                if (seperateEscapes)
                {
                    scoreFont.printLine(scoreFont.height * 2, 5, ("EscapeScore: " + scoreEscape + "%"));
                }

                // get offsets
                int x = scoreGridOffsetX;
                int y = scoreGridOffsetY;

                // create new list from posAndNegs list (to prevent referencing the same object), remove true negatives (we don't want to plot these), and use this list for plotting
                List <CMoleTask.scoreTypes> scoreList = new List <CMoleTask.scoreTypes>(posAndNegs);
                scoreList.RemoveAll(item => item == CMoleTask.scoreTypes.TrueNegative);

                // determine at which index to begin plotting the scores (it is possible that there are more scores than can fit on screen (scoreRows * scoreCellsPerRow fit on screen), so when screen is full, only new scores are plotted
                int index = (int)Math.Floor(scoreList.Count / (double)totalScoresOnScreen) * totalScoresOnScreen;

                // loop through the scores and plot
                for (int i = index; i < scoreList.Count; i++)
                {
                    // plot anything but true negatives
                    if (scoreList[i] != CMoleTask.scoreTypes.TrueNegative)
                    {
                        // to determine if was false or true
                        bool correct = false;

                        // set white color for drawing
                        glColor3(1f, 1f, 1f);

                        // set texture
                        if (scoreList[i] == CMoleTask.scoreTypes.FalseNegative)
                        {
                            glBindTexture2D(moleLaughTexture);
                        }
                        else if (scoreList[i] == CMoleTask.scoreTypes.FalsePositive)
                        {
                            glBindTexture2D(holeTexture);
                        }
                        else if (scoreList[i] == CMoleTask.scoreTypes.TruePositive)
                        {
                            glBindTexture2D(moleWhackedTexture); correct = true;
                        }
                        else if (scoreList[i] == CMoleTask.scoreTypes.TruePositiveEscape)
                        {
                            glBindTexture2D(escapeTexture); correct = true;
                        }
                        else if (scoreList[i] == CMoleTask.scoreTypes.FalseNegativeEscape)
                        {
                            glBindTexture2D(escapeTexture);
                        }
                        else
                        {
                            return;
                        }

                        // draw hole
                        glBeginTriangles();

                        // vertex 0
                        glTexCoord2(1.0f, 1.0f);
                        glVertex3(x + scoreCellWidth, y + scoreCellHeight, 0.0f);

                        glTexCoord2(1.0f, 0.0f);
                        glVertex3(x + scoreCellWidth, y, 0.0f);

                        glTexCoord2(0.0f, 0.0f);
                        glVertex3(x, y, 0.0f);

                        //vertex 1
                        glTexCoord2(0.0f, 1.0f);
                        glVertex3(x, y + scoreCellHeight, 0.0f);

                        glTexCoord2(1.0f, 1.0f);
                        glVertex3(x + scoreCellWidth, y + scoreCellHeight, 0.0f);

                        glTexCoord2(0.0f, 0.0f);
                        glVertex3(x, y, 0.0f);

                        glEnd();

                        // set color for border, indicating false of true positive or negative
                        float colorR = 1, colorG = 0, colorB = 0;
                        if (correct)
                        {
                            colorR = 0; colorG = 1; colorB = 0;
                        }

                        // draw colored border
                        drawRectangle(x, y, (x + scoreCellWidth), (y + scoreCellHeight), 5, colorR, colorG, colorB);

                        // update x and y coordinates for plotting next scoreItem
                        x = x + scoreCellWidth + spacing;
                        if ((x + scoreCellWidth + spacing) > getContentWidth())
                        {
                            y = y + scoreCellHeight + spacing;
                            x = scoreGridOffsetX;
                        }
                    }
                }
            }

            // check if text should be shown
            if (showText.Length != 0)
            {
                // set the text to white
                glColor3(1f, 1f, 1f);

                // print the text
                textFont.printLine((getContentWidth() - showTextWidth) / 2, getContentHeight() / 2, showText);
            }

            // check if there is no signal
            if (showConnectionLost)
            {
                // set white color for drawing
                glColor3(1f, 1f, 1f);

                // print text
                int textWidth = textFont.getTextWidth("Lost connection with device");
                textFont.printLine((int)((getContentWidth() - textWidth) / 2), (int)((getContentHeight()) / 4), "Lost connection with device");

                // set texture
                glBindTexture2D(connectionLostTexture);

                // draw texture
                glBeginTriangles();

                // vertex 0
                glTexCoord2(0.0f, 0.0f);
                glVertex3((getContentWidth() - 200) / 2, (getContentHeight() - 200) / 2, 0.0f);

                glTexCoord2(1.0f, 0.0f);
                glVertex3((getContentWidth() - 200) / 2 + 200, (getContentHeight() - 200) / 2, 0.0f);

                glTexCoord2(1.0f, 1.0f);
                glVertex3((getContentWidth() - 200) / 2 + 200, (getContentHeight() - 200) / 2 + 200, 0.0f);

                //vertex 1
                glTexCoord2(0.0f, 0.0f);
                glVertex3((getContentWidth() - 200) / 2, (getContentHeight() - 200) / 2, 0.0f);

                glTexCoord2(1.0f, 1.0f);
                glVertex3((getContentWidth() - 200) / 2 + 200, (getContentHeight() - 200) / 2 + 200, 0.0f);

                glTexCoord2(0.0f, 1.0f);
                glVertex3((getContentWidth() - 200) / 2, (getContentHeight() - 200) / 2 + 200, 0.0f);

                glEnd();
            }
        }