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

📄 3dshapes.cpp

📁 一个三维打斗游戏
💻 CPP
字号:
// (C) Copyright 1996 by Anthony J. Carin.  All Rights Reserved.
#include <stdafx.h>
#include "3dshapes.h"
#include "launch.h"
#include "bmpsurf.h"

void coordinate::stepto(coordinate& to, float step, char stop)
{
    coordinate o = to;
#ifdef EDITOR
    stop = FALSE;
#endif
    if (stop)
    {
        bmpsurf *bsurf;
        bsurf = Game->Bmpsurfs()->First();
        while (bsurf)
        {
            if (bsurf->intersects(*this, o))
                return;
            bsurf = Game->Bmpsurfs()->Next();
        }
    }
    if (m_x < o.x())
    {
        m_x += step;
        if (m_x > o.x())
            m_x = o.x();
    }
    else if (m_x > o.x())
    {
        m_x -= step;
        if (m_x < o.x())
            m_x = o.x();
    }
    if (m_y < o.y())
    {
        m_y += step;
        if (m_y > o.y())
            m_y = o.y();
    }
    else if (m_y > o.y())
    {
        m_y -= step;
        if (m_y < o.y())
            m_y = o.y();
    }
    if (m_z < o.z())
    {
        m_z += step;
        if (m_z > o.z())
            m_z = o.z();
    }
    else if (m_z > o.z())
    {
        m_z -= step;
        if (m_z < o.z())
            m_z = o.z();
    }
}

coordinate& operator+(coordinate& a, coordinate& b)
{
   static coordinate r;
   r.m_x = a.m_x + b.m_x;
   r.m_y = a.m_y + b.m_y;
   r.m_z = a.m_z + b.m_z;
   return r;
}

coordinate& operator-(coordinate& a, coordinate& b)
{
   static coordinate r;
   r.m_x = a.m_x - b.m_x;
   r.m_y = a.m_y - b.m_y;
   r.m_z = a.m_z - b.m_z;
   return r;
}

void point::xrotate(direction& d)
{
    register float tmp;
    tmp = tccos(d, m_y) - tcsin(d, m_z);
    m_z = tcsin(d, m_y) + tccos(d, m_z);
    m_y = tmp;
}

void point::yrotate(direction& d)
{
    register float tmp;
    tmp = tccos(d, m_z) - tcsin(d, m_x);
    m_x = tcsin(d, m_z) + tccos(d, m_x);
    m_z = tmp;
}

void point::zrotate(direction& d)
{
    register float tmp;
    tmp = tccos(d, m_x) - tcsin(d, m_y);
    m_y = tccos(d, m_y) + tcsin(d, m_x);
    m_x = tmp;
}

void coordinate::operator +=(coordinate& c)
{
    m_x += c.m_x;
    m_y += c.m_y;
    m_z += c.m_z;
}

void coordinate::operator -=(coordinate& c)
{
    m_x -= c.m_x;
    m_y -= c.m_y;
    m_z -= c.m_z;
}

char operator==(coordinate& a, coordinate& b)
{
    if (a.m_x != b.m_x)
        return FALSE;
    if (a.m_y != b.m_y)
        return FALSE;
    if (a.m_z != b.m_z)
        return FALSE;
    return TRUE;
}


const long FOCAL3  = 3000;
const long WIDE    = 10;
const long FLAT    = 8;
const long TALL    = 9;

polygon::polygon(polygon& p)
{
   m_linenum = p.m_linenum;
   m_a = p.m_a;
   m_b = p.m_b;
   m_c = p.m_c;
   m_d = p.m_d;
   m_color = p.m_color;
}

coordinate& polygon::getcenter()
{
    static coordinate v;
    float acm = 0.0f, bdm = 0.0f;
    float acb = 0.0f, bdb = 0.0f;
    float x;
    char  acv = FALSE,
          bdv = FALSE;

    x = (m_c.x()-m_a.x());
    if (x == 0)
        acv = TRUE;
    else
        acm = (m_c.z()-m_a.z()) / x;            // get slope
    x = (m_d.x()-m_b.x());
    if (x == 0)
        bdv = TRUE;
    else
        bdm = (m_d.z()-m_b.z()) / x;            // get slope
    if (acv == FALSE)
        acb = m_a.z() - acm * m_a.x();        // get z intersect
    if (bdv == FALSE)
        bdb = m_b.z() - bdm * m_b.x();        // get z intersect
    if (acv || bdv)
    {
        if (acv)
        {
            v.setx(m_a.x());
            v.setz(bdm*m_a.x()+bdb);
        }
        else {
            v.setx(m_b.x());
            v.setz(acm*m_b.x()+acb);
        }
        return v;
    }
    x = (bdm-acm);
    if (x == 0.0f)
    {
        v.setx((m_a.x() + m_c.x()) / 2);
        v.setz((m_a.z() + m_c.z()) / 2);
    }
    else
    {
        x = (acb-bdb)/x;
        v.setx(x);
        v.setz(acm*x+acb);
    }
    v.sety((m_a.y() + m_c.y()) / 2);
    return v;
}

void polygon::setto(coordinate& a, coordinate& b, coordinate& c)
{
   m_a.setto(a);
   m_b.setto(b);
   m_c.setto(c);
   m_d.setto(c);
   m_linenum = 3;
}

void polygon::setto(coordinate& a, coordinate& b, coordinate& c, coordinate& d)
{
   m_a.setto(a);
   m_b.setto(b);
   m_c.setto(c);
   m_d.setto(d);
   m_linenum = 4;
}

view::view(view& c) : coordinate(c)
{
    m_xdirection = c.m_xdirection;
    m_ydirection = c.m_ydirection;
    m_zdirection = c.m_zdirection;
}

⌨️ 快捷键说明

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