📄 hopcreatesolidsphere.cpp
字号:
//
// Copyright (c) 2000 by Tech Soft 3D, LLC.
// The information contained herein is confidential and proprietary to
// Tech Soft 3D, LLC., and considered a trade secret as defined under
// civil and criminal statutes. Tech Soft 3D shall pursue its civil
// and criminal remedies in the event of unauthorized use or misappropriation
// of its trade secrets. Use of this information by anyone other than
// authorized employees of Tech Soft 3D, LLC. is granted only under a
// written non-disclosure agreement, expressly prescribing the scope and
// manner of such use.
//
// $Header: /files/homes/master/cvs/hoops_master/hoops_appwizard/VCWizards/HOOPSAppWiz_NET2003/Templates/1033/3daf/HOpCreateSolidSphere.cpp,v 1.3 2006-08-07 20:38:55 stage Exp $
//
#include "stdafx.h"
#include "hc.h"
#include "Htest6Model.h"
#include "Htest6View.h"
#include "HBaseOperator.h"
#include "HEventInfo.h"
#include "HTools.h"
#include "HOpCreateSolidSphere.h"
#include <stdio.h>
#include <math.h>
#include <assert.h>
#include "ha_bridge.h"
#include "cstrapi.hxx"
/////////////////////////////////////////////////////////////////////////////
// HOpCreateSolidSphere
//
// Operator for inserting a Solid Modeler Sphere into a newly created Scene/Part segment.
// Mouse down - fix first position
// Mouse motion while down - rubberband sphere with radius defined by first point and
// current position in world space in the scene/construction segment
// Mouse up inserts the sphere
HOpCreateSolidSphere::HOpCreateSolidSphere(HBaseView* view, int DoRepeat, int DoCapture) : HOpCreateSphere(view, DoRepeat, DoCapture)
{
}
HBaseOperator * HOpCreateSolidSphere::Clone()
{
return (HBaseOperator *)new HOpCreateSolidSphere(m_pView);
}
const char * HOpCreateSolidSphere::GetName() { return "HOpCreateSolidSphere"; }
/////////////////////////////////////////////////////////////////////////////
// CreateSphere message handlers
int HOpCreateSolidSphere::OnLButtonUp(HEventInfo &event)
{
// Mouse has come up
if(!m_bOpStarted)
return HBaseOperator::OnLButtonUp(event);
m_bOpStarted = false;
m_ptNew = event.GetMouseWorldPos();
HC_Open_Segment_By_Key(((Htest6View *)m_pView)->GetConstructionKey());
HC_Flush_Contents (".", "geometry");
HC_Close_Segment();
HC_Open_Segment_By_Key(m_pView->GetSceneKey());
HC_Compute_Coordinates(".", "viewpoint", &m_ptFirst, "world", &m_ptFirst);
HC_Close_Segment();
HVector radius_vector;
radius_vector.Set (m_ptNew.x - m_ptFirst.x,
m_ptNew.y - m_ptFirst.y,
m_ptNew.z - m_ptFirst.z);
float radius_length = (float) HC_Compute_Vector_Length (&radius_vector);
if(fabs(radius_length) < 0.000001){
m_bOpStarted = false;
return(HOP_CANCEL);
}
HC_Open_Segment_By_Key(GetView()->GetModel()->GetModelKey());
// put each entity in a separate segment so that we can easily apply
// transformations to separately created entities
HC_Open_Segment("");
BODY* sphere_ptr;
sphere_ptr = CreateSolidSphere(m_ptFirst, radius_length);
HC_Close_Segment();
HC_Close_Segment();
m_pView->Update(); // update the display
return(HOP_READY);
}
// create an acis sphere and return the sphere's body id
BODY* HOpCreateSolidSphere::CreateSolidSphere(HPoint & center, float radius)
{
BODY* sphere_body;
SPAvector translate_vector;
SPAtransf delta_transf;
outcome o;
translate_vector.set_x(center.x);
translate_vector.set_y(center.y);
translate_vector.set_z(center.z);
delta_transf = translate_transf(translate_vector);
o = api_make_sphere(radius, sphere_body);
o = api_transform_entity(sphere_body, delta_transf);
assert(o.ok());
// now put it in the HOOPS database
HA_Render_Entity((ENTITY*)sphere_body);
return sphere_body;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -