| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 872 人关注过本帖
标题:求助。。讲解C++代码,关于opengl的3D魔方
只看楼主 加入收藏
miaoxiaoyao
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2013-5-7
结帖率:0
收藏
已结贴  问题点数:20 回复次数:2 
求助。。讲解C++代码,关于opengl的3D魔方
小女在做毕业设计,遇到了难题,现在有代码了,可是完全看不懂,求哪位大神帮帮忙来讲解一下,QQ1786121067,小女子在此不胜感激。离答辩日子越来越近了,心里着实忐忑。这里贴出一小部分代码,哪位大神哥哥有时间的有兴趣的就来Q我一下吧,全天在线等。
#include"Vector.h"
#include<iostream>
using namespace std;
CVector::CVector()
{
    x=0.0;
    y=0.0;
    z=0.0;
}
CVector::CVector(GLfloat x,GLfloat y,GLfloat z)
{
    this->x=x;
    this->y=y;
    this->z=z;
}
CVector::~CVector()
{
}
CVector& CVector::operator=(const CVector& vector)
{
    this->x=vector.x;
    this->y=vector.y;
    this->z=vector.z;
    return *this;
}
CVector CVector::operator+(const CVector& vector)
{
    return CVector(this->x+vector.x,this->y+vector.y,this->z+vector.z);
}
CVector CVector::operator-(const CVector& vector)
{
    return CVector(this->x-vector.x,this->y-vector.y,this->z-vector.z);
}
CVector CVector::operator*(const CVector& vector)
{
    GLfloat x,y,z;
    x=this->y*vector.z-this->z*vector.y;
    y=this->z*vector.x-this->x*vector.z;
    z=this->x*vector.y-this->y*vector.x;
    return CVector(x,y,z);
}
CVector CVector::operator*(GLfloat radius)
{
    return CVector(this->x*radius,this->y*radius,this->z*radius);
}
CVector& CVector::operator*=(GLfloat radius)
{
    this->x*=radius;
    this->y*=radius;
    this->z*=radius;
    return *this;
}
CVector& CVector::operator-=(const CVector& vector)
{
    this->x-=vector.x;
    this->y-=vector.y;
    this->z-=vector.z;
    return *this;
}
CVector& CVector::operator+=(const CVector& vector)
{
    this->x+=vector.x;
    this->y+=vector.y;
    this->z+=vector.z;

    return *this;
}
std::ostream& operator<<(std::ostream& os,const CVector& vector)
{
    return os<<"<"<<vector.x<<","<<vector.y<<","<<vector.z<<">";
}
搜索更多相关主题的帖子: namespace 不胜感激 include 小女子 
2013-05-07 07:23
yuccn
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
来 自:何方
等 级:版主
威 望:167
帖 子:6815
专家分:42393
注 册:2010-12-16
收藏
得分:10 
一些基本运算符的重载而已

我行我乐
公众号:逻辑客栈
我的博客:
https://blog.yuccn. net
2013-05-07 13:06
邓士林
Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19
来 自:淮河河畔
等 级:贵宾
威 望:61
帖 子:2392
专家分:13384
注 册:2013-3-3
收藏
得分:10 
#include"Vector.h"
#include<iostream>
using namespace std;
CVector::CVector()           //构造函数初始化
{
    x=0.0;
    y=0.0;
    z=0.0;
}
CVector::CVector(GLfloat x,GLfloat y,GLfloat z)            //带参数的构造函数
{
    this->x=x;
    this->y=y;
    this->z=z;
}
CVector::~CVector()                  //析构函数
{
}
CVector& CVector::operator=(const CVector& vector)                //=重载
{
    this->x=vector.x;
    this->y=vector.y;
    this->z=vector.z;
    return *this;
}
CVector CVector::operator+(const CVector& vector)
{
    return CVector(this->x+vector.x,this->y+vector.y,this->z+vector.z);
}
CVector CVector::operator-(const CVector& vector)
{
    return CVector(this->x-vector.x,this->y-vector.y,this->z-vector.z);
}
CVector CVector::operator*(const CVector& vector)
{
    GLfloat x,y,z;
    x=this->y*vector.z-this->z*vector.y;
    y=this->z*vector.x-this->x*vector.z;
    z=this->x*vector.y-this->y*vector.x;
    return CVector(x,y,z);
}
CVector CVector::operator*(GLfloat radius)
{
    return CVector(this->x*radius,this->y*radius,this->z*radius);
}
CVector& CVector::operator*=(GLfloat radius)
{
    this->x*=radius;
    this->y*=radius;
    this->z*=radius;
    return *this;
}
CVector& CVector::operator-=(const CVector& vector)
{
    this->x-=vector.x;
    this->y-=vector.y;
    this->z-=vector.z;
    return *this;
}
CVector& CVector::operator+=(const CVector& vector)
{
    this->x+=vector.x;
    this->y+=vector.y;
    this->z+=vector.z;

    return *this;
}
std::ostream& operator<<(std::ostream& os,const CVector& vector)
{
    return os<<"<"<<vector.x<<","<<vector.y<<","<<vector.z<<">";
}
都是一些基础的重载,你可以看下c++课本,学姐!你都不懂,答辩可紧张啊

Maybe
2013-05-07 20:51
快速回复:求助。。讲解C++代码,关于opengl的3D魔方
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.015321 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved